Repaired Records : Cell information from worksheet created from scratch Repaired Records : Cell information from worksheet created from scratch xml xml

Repaired Records : Cell information from worksheet created from scratch


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:

<x:row>  <x:c>    <x:v>12345</x:v>  </x:c></x:row>

when you use an inline string it looks like:

<x:row>  <x:c t="inlineStr">    <x:is>      <x:t>Foo</x:t>    </x:is>  </x:c></x:row>

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.


My issue was that I had been setting the name of the worksheet with a name that had a forward slash / in it.


Another late one - but check how you're adding cells to a row. Have you cut and paste add cell code in which there's a 'simple' compare with the existing cell reference (A1 etc) in the row? In which case if you have a cell beyond column Z - AA1 onwards - then you might end up trying to insert cell (eg) AB1) before cell B1. You'll then get this error on opening the written sheet in excel. Instead, if simply adding cell after cell along each row, just go straight to insert before with the reference cell set to null - ie. add new cell to end.

Hope that makes sense.