excel export convert number to string while exporting
excel export convert number to string while exporting
nikki111
Posts: 8Questions: 3Answers: 0
i am having this problem when i export the data into excel , excel treat's a column as numeric and performs some rounding on it but i want to keep it as text.
This discussion has been closed.
Answers
Looks like Excel recognizes your column as numeric. You can override this using built in styles: https://datatables.net/reference/button/excelHtml5 See "Customization" and "Built in Styles"
Here are some examples: https://datatables.net/extensions/buttons/examples/html5/index.html
See the Excel examples on how to apply built-in styles.
I already checked those links, applying styles are not working for me
... then you have a different problem ... but without your code is is pretty much impossible to give you further advice.
hi,
I want to prevent "1.65461E+11" in my cell.
I want just normal text without E+11.
just put a blank in front of it when formatting for export. Then Excel shouldn't recognize it as numeric any longer.
Take a look at this post for questions on how to format these things:
https://datatables.net/forums/discussion/45846/datatable-excel-export-how-can-we-apply-multiple-styles-to-same-cell#latest
It is a plain number if you look at the raw XML. It is Excel which is detecting the number and formatting it as such. If you typed such a number into Excel, then it would do the same thing.
Allan
True, Excel does these things unfortunately. Inserting a leading space stops Excel from recognizing it as a number. Had the same problem with PHPSpreadsheet. Then checked for numeric in PHP and inserted the space whenever I came across a numeric value for that field. Inserting a leading “ ' “ unfortunately didn't work. You can do the same in JavaScript using the export options.
Prepending "\0" to the column I wanted Excel to treat as string worked for me. Note that you will not see any extra zero in your data, and Excel will not treat your data as numeric anymore.
Here is a code snippet:
Note: it is the 3rd column in my table that I wanted as string, hence "column ===2"
I just wish the syntax was a bit easier.
@lyassa Best answer
Add '\u200C' before large number, it will convert as string
Prashant_O
Tried with '\u200C' it works but its keeping some hidden value in excel. how to avoid the hidden value(?)
@Prabhosha We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin