Hi,
Writing an large excel file using SpreadsheetDocument takes around 2 mins.
surprisingly when i comment the cell.Datatype line the excel file generates in 10 secs. But in this case opening in excel it gives error as datatype must be specified for string data.
1. Can Datatype be specified for entire column?
2. Can we avoid specifying Datatype somehow?
Please let me know if the performance of the code can be improved some how.
In the sample code I am using same text value for each cell but in my project their will be different values for each cell . Thus I cant use sharedtables.
My code is as follows.
static void Main(string[] args){
String str_IntermidiateXMLPath = "c:\\Ouput.xlsx";
File.Copy("c:\\book.xlsx", str_IntermidiateXMLPath, true);
using (SpreadsheetDocument SpreadsheetDocumentObj = SpreadsheetDocument.Open(
str_IntermidiateXMLPath, true))
{
WorkbookPart workbookpart = null;
WorksheetPart worksheetpart = null;
Worksheet worksheet = null;
SheetData sheetdata = null;
OpenXmlWriter writer = null;
Cell cell = null;
Row row = null;
SpreadsheetDocumentObj.CompressionOption = CompressionOption.SuperFast;
workbookpart = SpreadsheetDocumentObj.WorkbookPart;
worksheetpart = workbookpart.WorksheetParts.First();
writer = OpenXmlWriter.Create(worksheetpart);
writer.WriteStartElement(new Worksheet());
writer.WriteStartElement(new SheetData());
for (int i = 0; i < 35000; i++)
{
row = new Row();
for (int j = 0; j < 100; j++)
{
cell = new Cell();
row.Append(cell);
cell.DataType = CellValues.InlineString;
cell.InlineString = new InlineString { Text = new Text { Text = "Hi" } };
}
writer.WriteElement(row);
}
writer.WriteEndElement();
writer.WriteEndElement();
writer.Close();
workbookpart.Workbook.Save();
SpreadsheetDocumentObj.Close();
}
}