Skip to content

Instantly share code, notes, and snippets.

@MrLeebo
Last active December 24, 2015 00:59
Show Gist options
  • Save MrLeebo/6720737 to your computer and use it in GitHub Desktop.
Save MrLeebo/6720737 to your computer and use it in GitHub Desktop.
Repro of an issue with Syncfusion XlsIO upgrade.
using (var excel = new ExcelEngine())
{
var workbook = excel.Excel.Workbooks.Open(fileName);
var sheet = workbook.Worksheets[sheetName];
var exportWorkbook = excel.Excel.Workbooks.Add(ExcelVersion.Excel2013); // Increases the maximum number of allowed rows.
var exportSheet = exportWorkbook.Worksheets.Create();
exportSheet.IsStringsPreserved = true; // Prevents leading zeroes from being dropped.
sheet.UsedRange.CopyTo(exportSheet.Range["A1"]);
}
// Replacing the CopyTo call with the following block:
foreach (IRange cell in sheet.UsedRange)
exportSheet.Range[cell.AddressLocal].Value = cell.Value;
// Has 3 issues:
// - Not as quick
// - Drops leading zeroes, for instance zipcode 02360 becomes 2360
// - In .xlsx files, throws an ArgumentOutOfRangeException on the 65537th row. (UInt16.MaxValue + 2??)
using (var excel = new ExcelEngine())
{
// Open the Excel document and retrieve the appropriate work sheet.
var workbook = excel.Excel.Workbooks.Open(@"C:\Path\To\Some\File.xlsx");
var sheet = workbook.Worksheets["Sheet1"];
// Create a new work sheet to export.
var exportWorkbook = excel.Excel.Workbooks.Add();
var exportSheet = exportWorkbook.Worksheets.Create();
// Copy the data to the export work sheet.
// "A1" is the first cell in the work sheet,
// the copy will expand into more cells to
// fit the size of the data source.
sheet.UsedRange.CopyTo(exportSheet.Range["A1"]);
// The line above throws an ArgumentOutOfRangeException in v11.3035.0.30, worked in v8.403.0.10.
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment