Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
2035
Excel creates corrupt file for large datasets
posted

I have a small app that collects data from a device and then writes that data to an Excel spreadsheet.  I have found that when the Excel file is too large, a corrupt Excel file is created.

The following example code fails in a Xamarin.Forms app for Android.  I tried both Infragistics 17.2 and 18.1. The xslx file is generated, but it fails to open in Excel.  Note that if I change the number of rows to 70,000 then the app works.

var wb = new Workbook(WorkbookFormat.Excel2007);
var ws = wb.Worksheets.Add("Sheet 1");
ws.Rows[0].Cells[0].Value = "Key";
ws.Rows[0].Cells[1].Value = "Value";
for (int ii = 1; ii < 120000; ++ii)
{
  ws.Rows[ii].Cells[0].Value = "Key" + ii.ToString();
  ws.Rows[ii].Cells[1].Value = ii;
}


var path = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/Alpha/";
string filename = Path.Combine(path, "test.xlsx");
var fs = File.Create(filename);
wb.Save(fs);