Tutorial :c# export excel maintain fraction value


I'm exporting (by that I mean using the contentType) an aspx page to excel. It works fine, except for when the value is like 1/6.

Instead of excel displaying 1/6. It's displaying 6-Jan. Is there something in c# that I can put around the value being exported that says, keep this value a fraction when it is a fraction?



From what I understand Excel stores all values as numbers internally and is the difference between the differnt value types in Excel purely based on formatting.

I think you'd have to explicitly set the format on the Cell in Excel where you will be storing the value.

I don't know if you are completely creating the Excel file from scratch in the export or if you are filling a template with the values, but that's what I'd look into first. Try and set the cell's number format programmatically in the first case and simply update your template in the latter.

Hope that helps.


You can make "a trick". Start your string by char space in format HTML. https://www.utexas.edu/learn/html/spchar.html


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »