私はdynamicly3210ライブラリでメモリ内のExcelファイルを生成しようとしてきたが、私は、ファイルを開いたとき、私はいつも、以下のエラーで直面:Excelでファイルレベルの検証と修復が完了しました。このワークブックのいくつかの部分は、修理または破棄された可能性があり
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.
ここに私のc#
サンプルコードは次のとおりです。
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();
}