Converting xlsx to html

Hello, trying to convert some excel files to html (from stream) we obtain a completely blank html: what we can correct?

This is our code (as in your website examples):

Aspose.Cells.HtmlSaveOptions OptionsC = new Aspose.Cells.HtmlSaveOptions();
OptionsC.ExportImagesAsBase64 = true;
((Aspose.Cells.Workbook)m_oDocument).Save(_oOutputStream, OptionsC);

Hi,


Thanks for the code segment and details.

Please provide us your template Excel file and output HTML file to evaluate your issue, we will check it soon.

Thank you.

Here they are.
Example attached… but it happened with different excel files of ours

Hi,

Thanks for the template file.

I have tested your scenario/case a bit using the following sample code with your template file, it works fine and the output file (attached) is ok:
e.g
Sample code:

var wb = new Workbook(“e:\test2\GLOSSARI IQTRANSLATE.xlsx”);

var options = new HtmlSaveOptions(SaveFormat.Html)

{

ExportImagesAsBase64 = true,

};

wb.Save("e:\\test2\\out1GLOSSAR1.html", options);

I think since you are saving the Excel file to HTML memory stream which does not allow saving more than one sheet (in the workbook) at a time. I think you should either save your Excel workbook to MHTML file format or try saving different HTMLs for each sheet separately, you got to update/write your code accordingly.

Thank you.

  • we tried to save as MHTML but the result is not reliable (see attached file)
    - can you suggest a sample code to save one html (stream) per sheet?
    - in our scenario we must use stream as input and output, so how we can handle excel conversion to html format (with embedded images and all others stuff)?

    thanks a lot

Hi,

I have tested by converting your template file to MHtml file format and it works fine. See the following sample code and find attached the output .mhtml file for your reference:
e.g
Sample code:

var wb = new Workbook(“e:\test2\GLOSSARI IQTRANSLATE.xlsx”);

var options = new HtmlSaveOptions(SaveFormat.MHtml)

{

ExportImagesAsBase64 = true,

};

var stream = new MemoryStream();

wb.Save(stream, options);

string filename = "e:\\test2\\out1.mhtml";


FileStream fstream = new System.IO.FileStream(filename, FileMode.OpenOrCreate);

stream.Position = 0;

byte[] data = stream.ToArray();

fstream.Write(data, 0, data.Length);

And, I am afraid, as I told you in my previous reply that you cannot save to stream having a complete workbook (containing all the worksheets in it) to a single HTML file, you got to save only one worksheet to stream, so you may create separate HTML file for each worksheet in the workbook.

Thank you.

Hi,

BooleServer:

- can you suggest a sample code to save one html (stream) per sheet?

See the sample code for your reference:
e.g
Sample code:

Aspose.Cells.License license = new Aspose.Cells.License();

license.SetLicense("Aspose.Cells.lic");


var wb = new Workbook("e:\\test2\\GLOSSARI IQTRANSLATE.xlsx");


var options = new HtmlSaveOptions(SaveFormat.Html)

{

ExportImagesAsBase64 = true,

ExportActiveWorksheetOnly = true


};

for (int i = 0; i < wb.Worksheets.Count; i++)

{

var stream = new MemoryStream();

wb.Worksheets.ActiveSheetIndex = i;

wb.Save(stream, options);

string filename = "e:\\test2\\out1" + i + ".html";


FileStream fstream = new System.IO.FileStream(filename, FileMode.OpenOrCreate);

stream.Position = 0;

byte[] data = stream.ToArray();

fstream.Write(data, 0, data.Length);

fstream.Close();

stream.Close();

Hope, this helps a bit.

Thank you.