pojomx
pojomx

Reputation: 790

How to keep format within HTML converted to Excel

I'm working with an HTML table, that contains numbers (formated) and when I export this to xls file (just change extension... hehe) I loss some of the formated data.

Example:

in html I have " 1,000.00 | 500.00 | 20.00 " and in excel it shows like: "1,000.00 | 500 | 20"

I want it to know if it is possible to show the very same format as in html.

THankyou :P

Upvotes: 5

Views: 4845

Answers (3)

arun.m
arun.m

Reputation: 131

you can achive that by using class. for example:

first add class

writer.WriteLine("<style> .number{mso-number-format:\"\\#\\#0\\.00\";} </style>");

and then, in your iteration :

writer.Write("<td class=\"number\" >");
writer.Write(data);
writer.WriteLine("</td>");

as shown in : Export to Excel in ASP.NET, issue with decimal formatting for numbers greater than 1000

Upvotes: 1

ashurexm
ashurexm

Reputation: 6335

You can open Excel and import it as data where it will ask you for your delimiter, and the data type of each column. You can also just manually choose the columns and add formatting.

Upvotes: 0

jhorback
jhorback

Reputation: 833

I've done this. The best way to tell is to create an .xls file (not .xlsx) and then save it as an html file.

Then look at the source of the html file. You'll see some css classes at the top and then if you look at the data below you'll see them being applied to the sheet.

So just a bit of reverse engineering...

FYI - if you try to open this up in 2007 or later, you'll get an initial warning but then all works OK.

Upvotes: 1

Related Questions