Repaired Records : Cell information from worksheet created from scratch

前端 未结 7 1482
醉话见心
醉话见心 2021-01-31 08:58

I\'m receiving an error when opening my OpenXML created spreadsheet. The error is as follows.

Repaired Records: Cell information from /xl/worksheets/sheet.xml p         


        
7条回答
  •  囚心锁ツ
    2021-01-31 09:29

    If you are adding a string to a cell rather than a number (or a string that can be converted to a number) then you should use an inline string or a shared string instead of the CellValue. You can only use CellValue if the value is numeric.

    The XML generated when using CellValue looks something like:

    
      
        12345
      
    
    

    when you use an inline string it looks like:

    
      
        
          Foo
        
      
    
    

    note the "is" node for inline string and that the cell type attribute is set to "inlineStr".

    Here is C# code to generate correct XML for a cell containing text:

    cell.DataType = CellValues.InlineString;
    cell.InlineString = new InlineString() { Text = new Text(textToInsert) };
    

    From what I have read using shared strings is preferable but using inline strings avoids the error and looks just fine when you open the file in Excel.

提交回复
热议问题