2017-05-24 147 views
0

私はdynamicly​​3210ライブラリでメモリ内の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(); 
     } 

答えて

0

あなたはセルの値を右cell.DataTypeを提供する必要があります。テキストを挿入する場合は、SharesStringTableを更新して参照する必要があります。 私の答えを見てhere私は希望のセルに値を更新/書き込みするメソッドを提供しています。このメソッドの名前は「更新」ですが、基本的にExcelのセルに値を書き込んだり上書きしたりします。

関連する問題