Is it possible to convert Worbook into HTML Table and then write them into String writer

I found a solution for converting workbook into HTML by the following code. But we don’t want to save them as HTML, instead we want to convert workbook to HTML Table and then pass them through String writer. Is there a way for that?


HtmlSaveOptions sv = new HtmlSaveOptions(SaveFormat.M_HTML);
// Instantiate a workbook and open the template XLSX file
Workbook wb = new Workbook(filePath);
// Save the HTML file
wb.save(dataDir + “CToHTMLFiles_out.html”, sv);

Thanks,
Toney

Hi,


Thanks for your query.

Although I am not entirely certain about your requirements but, for your information, Aspose.Cells does render Excel to HTML file as you manually do (e.g Save an Excel spreadsheet to Web page) in MS Excel. Aspose.Cells follows MS Excel standards and specifications for Excel to HTML rendering, the output HTML file is MS Excel oriented (HTML) file. Aspose.Cells does not do anything different than MS Excel. What do you mean by HTML table, do you mean need to retrieve/save HTML tags/strings against data and formatting in the cells in the worksheet? If this is the case, you may easily get the HTML string via Cell.HtmlString attribute that will give you HTML string for data and formatting in the cell. You may loop through each cell in the worksheet and get the HTML strings for your needs.

Thank you.

Thanks Amjad ! It worked when i iterated over the cells & took values. I have saved the html string values to html file. But the way the values displayed is different. Attached the 2 files for your reference.

Sheet Html - This is how it has to be dispalyed.

aspose Html - This is how aspose displays.

Could you please suggest me a way for this.



Regards,

Toney

Hi,


Thanks for the sample files.

I am not sure if there is any better way to cope with your scenario except you got to save the entire spreadsheet to HTML via Aspose.Cells APIs. Your devised HTML is table oriented where you manually embed data inside “” and “” based. As I said earlier, Aspose.Cells does render Excel to HTML file as you manually do (e.g Save an Excel spreadsheet to Web page) in MS Excel. Aspose.Cells follows MS Excel standards and specifications for Excel to HTML rendering, the output HTML file is MS Excel oriented (HTML) file. By the way you could try to save the Excel to HTML in MS Excel manually to check how it goes. The output HTML file should be same with output HTML by MS Excel.

Thank you.

Thanks Amjad for your response ! We would do the formatting separately as suggested.

Regards,
Toney