J'ai essayé de générer un fichier Excel en mémoire dynamicly avec bibliothèque Open XML, mais quand j'ouvre le fichier que je toujours face avec erreur ci-dessous:Excel terminé la validation et la réparation au niveau du fichier. Certaines parties de ce manuel peuvent avoir été réparés ou mis au rebut
Excel completed file level validation and repair. Some parts of this workbook may have been repaired or discarded. Repaired Records: Cell information from /xl/worksheets/sheet1.xml part.
Voici mon code c#
exemple:
var coordination = new string[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L" };
var ba = System.IO.File.ReadAllBytes(tempAddress); // tempAddress is an empty template path
using (var document = new MemoryStream())
{
document.Write(ba, 0, (int)ba.Length);
using (SpreadsheetDocument excel = SpreadsheetDocument.Open(document, true))
{
uint index = 1;
Sheet sheet = excel.WorkbookPart.Workbook.Descendants<Sheet>().SingleOrDefault();
WorksheetPart worksheetPart = (WorksheetPart)excel.WorkbookPart.GetPartById(sheet.Id);
var worksheet = worksheetPart.Worksheet;
Cell cell = ExcelProvider.GetCellOrCreate(worksheet, coordination[0], index);
cell.CellValue = new CellValue(StuffExcelDefinition.Title);
Cell cell1 = ExcelProvider.GetCellOrCreate(worksheet, coordination[1], index);
cell1.CellValue = new CellValue(StuffExcelDefinition.Name);
Cell cell2 = ExcelProvider.GetCellOrCreate(worksheet, coordination[2], index);
cell2.CellValue = new CellValue(StuffExcelDefinition.Category);
foreach (var stuff in stuffs)
{
index++;
cell = ExcelProvider.GetCellOrCreate(worksheet, coordination[0], index);
cell.CellValue = new CellValue(stuff.Title);
cell1 = ExcelProvider.GetCellOrCreate(worksheet, coordination[1], index);
cell1.CellValue = new CellValue(stuff.Name);
cell2 = ExcelProvider.GetCellOrCreate(worksheet, coordination[2], index);
cell2.CellValue = new CellValue(stuff.Category.Title);
}
worksheetPart.Worksheet.Save();
}
return document.GetBuffer();
}