How to save Worksheets in HTML- one below one

I want to save all the worksheets in an excel file in a single HTML file. By default, HTML file shows these worksheets as separate tabs in HTML. Instead, I want to save those one below one. Can you please suggest how can I achieve it?

Hi,


Thank you for using Aspose. Cells.

I am afraid there is not direct method for this purpose. But you can combine the data of all the worksheets in one worksheet and then save it as html for your requirements. Please visit this link for how to combine all the worksheets in one worksheet.

Hi,


You can refer to the following code for your requirements. It is the same as I have mentioned in the earlier post, except that at the end, the destination worksheet is saved as HTML. I have attached the Source Excel file as well for your reference.

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”> string filePath = @“K:\sourcesheets.xls”;

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”>

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”> Workbook workbook = new
Workbook(filePath);

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”>

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”> Workbook destWorkbook = new
Workbook();

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”>

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”> Worksheet destSheet = destWorkbook.Worksheets[0];

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”>

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”> int TotalRowCount = 0;

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”>

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”> for (int i = 0; i
< workbook.Worksheets.Count; i++)

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”> {

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”> Worksheet sourceSheet = workbook.Worksheets[i];

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”>

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”> Range sourceRange =
sourceSheet.Cells.MaxDisplayRange;

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”>

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”> Range destRange =
destSheet.Cells.CreateRange(sourceRange.FirstRow + TotalRowCount,
sourceRange.FirstColumn,sourceRange.RowCount, sourceRange.ColumnCount);

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”>

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”>
destRange.Copy(sourceRange);

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”>

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”>
TotalRowCount = sourceRange.RowCount + TotalRowCount;

<span style=“font-size:10.0pt;font-family:“Courier New”;
mso-no-proof:yes”> }

<span style=“font-size:10.0pt;
line-height:115%;font-family:“Courier New”;mso-no-proof:yes”> destWorkbook.Save(@“K:\output.html”, SaveFormat.Html);

Thanks a lot Kashif. It works for me :slight_smile:

Hi,


You are welcome. Please feel free to contact us if you have any additional query. We will try our best to assist you as soon as possible.

Also, we recommend you to download and use this latest version of Aspose.Cells: Aspose.Cells for .NET v7.2.2.7 in your applications.