I have to create a big XLSX file. I use OpenXmlWriter to do the task as fast as possible. The file is properly create, but i can't change the data type of the field. It's always standard type, and i would like to use number format for some of them.
I have tried many way but no one worked (Cell DataType, with the attribute,...).
Here is an example :
SpreadsheetDocument fichier_excel = SpreadsheetDocument.Create(chemin + NomFichier, SpreadsheetDocumentType.Workbook);
fichier_excel.AddWorkbookPart();
WorksheetPart wsp = fichier_excel.WorkbookPart.AddNewPart<WorksheetPart>();
OpenXmlWriter writer = OpenXmlWriter.Create(wsp);
writer.WriteStartElement(new Worksheet());
writer.WriteStartElement(new SheetData());
oxa = new List<OpenXmlAttribute>();
oxa.Add(new OpenXmlAttribute("r", null, "1"));
writer.WriteStartElement(new Row(), oxa);
oxa = new List<OpenXmlAttribute>();
oxa.Add(new OpenXmlAttribute("t", null, "str"));
writer.WriteStartElement(new Cell(), oxa);
writer.WriteElement(new CellValue("10001"));
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
writer.Close();
writer = OpenXmlWriter.Create(fichier_excel.WorkbookPart);
writer.WriteStartElement(new Workbook());
writer.WriteStartElement(new Sheets());
writer.WriteElement(new Sheet()
{
Name = "Inventaire",
SheetId = 1,
Id = fichier_excel.WorkbookPart.GetIdOfPart(wsp)
});
writer.WriteEndElement();
writer.WriteEndElement();
writer.Close();
writer.Dispose();
fichier_excel.Close();
fichier_excel.Dispose();