Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an existing Open XML app in VB that generates a spreadsheet from SQL data. My problem is numeric identifiyers like 5678.1 and 5678.10. Even though I set the cellValueType to String in the resultant spreadsheet it appears as General format.

So how do I make it Text format?

In my call to SetCellValue() I pass a Nothing as the styleIndex.

I use a predefined styles file as follows:-

<x:numFmts>
<x:numFmt numFmtId="164" formatCode="#,##0.00\ "€"" />
</x:numFmts>

etc...

Can I define a style, put it into my predefinedstyles.xml and call it from the SetcellValue() routine?

What I have tried:

I have no reference for defining the content of the predefined style xml file.

In the resulting spreadsheet the two identifyers do appear correct but if you play with the cells ther 5434.10 value changes to 5434.1. The only way I can see to hold the correct text is to change from General format to Text format.
Posted
Updated 23-Jan-18 8:58am

1 solution

May I ask, How you are generating the Spreadsheet,What I mean by that is, are you writing each cell in a loop? If so, then you can set the DataType of each cell as string.
C#
Cell cell = new Cell();
cell.DataType = CellValues.String;
cell.CellValue = new CellValue(table.Rows[rowIndex][colIndex].ToString());


than you can append the cell to other row cells.

Hope that helps !
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900