Multi worksheets convert to single static HTML file

Hello,


I have problem with convert Excel file to HTML. In Excel I have 5 worksheet and I would like to get single static HTML file with all worksheet (not only active) - without javascript tabs, etc.

It is possible to do that?

My Aspose.Cells version: 8.6.3

Thanks for answers.

Hi,


Please try our latest version/fix:
http://www.aspose.com/downloads/cells/net/new-releases/aspose.cells-for-.net-8.9.2/

Well, Aspose.Cells renders Excel to HTML file in the same way as MS Excel does. If you still find any issue, kindly provide your template Excel file and your output HTML file and an expected HTML file which you may create it manually in MS Excel with some screenshot(s) to highlight the problematic areas.


Thank you.

Ok. This is example:


When I use settings like that:

var settings = new HtmlSaveOptions();
settings.ExportActiveWorksheetOnly = true;

I get HTML file like I want - one file - only html with active worksheet.

But… I have five worksheets in my file and I would like to get again one file with five worksheets one by one. But, when I use this settings:

var settings = new HtmlSaveOptions();
settings.ExportActiveWorksheetOnly = false;

I get HTML file with folder. And this is not excepted by me. Because there is many files, javascript, etc. So - what can I do to get only static HTML with all worksheets in my xlsx file?

Thanks!

Hi,

Thanks for your posting and using Aspose.Cells.

We could partially understand your problem. Please note, if you have not set the license, then you cannot convert any of your worksheet into html because in evaluation mode, the active worksheet will always be an Evaluation Warning worksheet.

However, your problem seems to be different. Could you elaborate your problem by posting us one sample excel file and their expected output html files? It will help us look into your issue more closely and precisely and we will provide you a sample code to achieve the same output as your expected output.

Hello,


Thanks for answer. My company has a license for Aspose 8.6.3.

Ok, I made sample xlsx file and excepted html output.

3 worksheet with different columns width are in excel.
In html these worksheets are put together into one html file one by one.

Hi,

Thanks for your illustration of the issue and considering Aspose.Cells.

After looking into your output, we found that this can only be achieved by first combining all of your worksheets into a single worksheet and then converting your combined worksheet into html.

Please see the following documentation article that describes how you can combine multiple worksheets into a single worksheet.

( Combine Multiple Worksheets into a Single Worksheet|Documentation )

Ok, Thanks. I will try this solution. But - what will happen when I have different width of columns?

Hi,

Thanks for your posting and considering Aspose.Cells.

That might cause an issue. Because it just combines the contents and do not take care of column widths. So this solution will not work in that case.

Another thing, you can do is to save html of all of your worksheets into memory stream objects and then parse that stream yourself and combine the html contents into a single html document.

But if you like us to add a New Feature request for your issue, then we can log it for product team investigation. It will look into it and implement it if feasible.

Hi,

Thanks for your posting and using Aspose.Cells.

We have found another solution that might fit your needs. You can save your workbook into MHTML format. In this way, you will get a single file that will contain all of your worksheets and everything related to it.

Please see the following sample code that converts your excel file into MHTML format. I have also attached the generated MHTML output file for your reference. Please open it in Internet Explorer or any Web Browser that supports MHTML format.

C#
Workbook wb = new Workbook(dirPath + “workbook.xlsx”);
wb.Save(dirPath + “output.mht”, SaveFormat.MHtml);

Another workaround that you may use is to convert all of your worksheets into images and then add those images in your HTML document via the tag.

The following sample code converts worksheet into image.

C#
//Create a new Workbook object
//Open a template excel file
Workbook book = new Workbook(“C:\Testbook.xls”);

//Get the first worksheet.
Worksheet sheet = book.Worksheets[0];

//Get the second worksheet.
//Worksheet sheet = book.Worksheets[1];

//Define ImageOrPrintOptions
ImageOrPrintOptions imgOptions = new ImageOrPrintOptions();

//Specify the image format
imgOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;

//If you want entire sheet as a singe image
imgOptions.OnePagePerSheet = true;

//Render the sheet with respect to specified image/print options
SheetRender sr = new SheetRender(sheet, imgOptions);

//Render the image for the sheet
Bitmap bitmap = sr.ToImage(0);

//Save the image file
bitmap.Save(@“D:\SheetImage.jpg”);