Problem with Excel to Html Conversion

Hi,


We have to convert the Excel file to Html to display it on web page.
Now as far I noticed the excel to Html conversion embeds some css to save the cell level styling, and the name of CSS style are similar across converted Excel Files .

Lets say I have two Excel file. (PFA : Excel1 and Excel2)
Excel1 and Excel2, I converted those to Html using below code :
using (MemoryStream documentStream = new MemoryStream(excelfiles))
{
Aspose.Cells.LoadOptions load = new Aspose.Cells.LoadOptions(Aspose.Cells.LoadFormat.Xlsx);
Aspose.Cells.Workbook document = new Workbook(memoryStream, load);
document.Save(documentStream, Aspose.Cells.SaveFormat.Html);
documentStream.Position = 0;

using (StreamReader reader = new StreamReader(documentStream))
{
return reader.ReadToEnd();
}
}

Above code was separately executed for both content then I will get
Excel1.html and Excel2.html,

Now If I merge these two html into one file, I am facing css overlapping issue, because both have same css name but different definition. (PFA : htmlFromExcel.zip)
Note: both html has .x21 as css,
The combined result has overlapping in Css (PFA : combined.zip)

So Is there any way to generate this css number at random in Aspose.cells or we can customize it in our code ?


Hi,

Thanks for your posting and using Aspose.Cells.

As a workaround, you should first combine all the worksheets into a single worksheet and then save your workbook in html format.

Please see the following documentation article that illustrates how to combine multiple worksheets into a single worksheet.


Please also see the following sample code. I have attached the output Excel file and the output HTML for your reference.

C#

string[] files = {“Excel1.xlsx”, “Excel2.xlsx” };


Workbook destWorkbook = new Workbook();


Worksheet destSheet = destWorkbook.Worksheets[0];


int TotalRowCount = 0;


for (int i = 0; i < files.Length; i++)

{

Workbook workbook = new Workbook(files[i]);


Worksheet sourceSheet = workbook.Worksheets[0];


Range sourceRange = sourceSheet.Cells.MaxDisplayRange;


Range destRange = destSheet.Cells.CreateRange(sourceRange.FirstRow + TotalRowCount, sourceRange.FirstColumn,

sourceRange.RowCount, sourceRange.ColumnCount);


destRange.Copy(sourceRange);


TotalRowCount = sourceRange.RowCount + TotalRowCount;

}


destWorkbook.Save(“output.xlsx”);


HtmlSaveOptions opts = new HtmlSaveOptions();


destWorkbook.Save(@“F:\Shak-Data-RW\Downloads\output.html”, opts);


Hi,

Thanks for the response.

The above workaround will not work for our case as we deal with HTML directly.


Hi,

Thanks for your posting and using Aspose.Cells.

We have logged a New Feature (Improvement) in our database to support this feature. We will look into it and see if it can be implemented. If we need some more information from your part, we will ask. Once, this feature is implemented or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-43368 - Customizing the generation of CSS while saving Excel to HTML

Hi,

Thanks for your using Aspose.Cells.

Please download and try the latest fix: Aspose.Cells for .NET v8.3.2.7 and let us know your feedback.

There are some tips for you:

1. Adds HtmlSaveOptions.CellCssPrefix attribute. Indicates the cell style prefix, the default value is “”.

The sample codes as follows:

C#


Workbook wb = new Workbook(“a.xlsx”);

HtmlSaveOptions options = new HtmlSaveOptions();

options.CellCssPrefix= “e1”;

wb.Save(“out.html”, options);

The issues you have found earlier (filed as CELLSNET-43368) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.