How to save all worksheets to stream in html format

Hi everyone,


I am trying to use Aspose.Cell to convert an excel workbook to html format. I was wondering how I can save all worksheets to stream in html format rather than the active one alone since I set ExportActiveWorksheetOnly to be false but the result doesn’t contain the content of worksheets but there are only link to html pages and I can’t find those file. I hope the result could be like one page per sheet.

Also I was wondering if Aspose.Cell provides a more friendly Resource saving handler that let me set how to store image files inside workbook when saving excel files to html. Current function I am using is ExportObjectListener and it is not as easy as those similar functions in other aspose libraries.

Thanks!

Hi Rui,

Thanks for your posting and using Aspose.Cells.

When you save your workbook into html format in memory stream, then it will not pack everything because resources in html are linked not embedded.

For example, check the attached output html generated by converting the source.xlsx file using the following code.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\source.xlsx”;


Workbook workbook = new Workbook(filePath);

workbook.Save(filePath + “.out.html”, SaveFormat.Html);

If you check the output html, you will see it has created a folder source.xlsx.out_files which contains all the html resources. These include.

  • cellsDrawing_Sheet2_1.png
  • cellsDrawing_Sheet3_1.png
  • filelist.xml
  • image000.jpeg
  • image001.jpeg
  • image002.jpeg
  • sheet001.htm
  • sheet002.htm
  • sheet003.htm
  • stylesheet.css
  • tabstrip.htm

All these resources are linked objects not embedded objects.

If you want to get embedded objects, then please save your workbook in MHTML format. Please check the MHTML format generated with the following code which I have attached for your reference. It is a single file which contains all the above resources as embedded objects.

C#

string filePath = @"F:\Shak-Data-RW\Downloads\source.xlsx";

Workbook workbook = new Workbook(filePath);

MemoryStream ms = new MemoryStream();
workbook.Save(ms, SaveFormat.MHtml);

ms.Position = 0;
byte[] data = new byte[ms.Length];
ms.Read(data, 0, data.Length);

File.WriteAllBytes("test.mhtml", data);

Hi Shakeel,

Thank you for your explanation that how saving sheets to html works and how to embed those resource files in a webpage using mhtml format. I was wondering if there is an option that we can save sheet to html in a “one-sheet-per-page” behaviour, for example, the result webpage contains several

s, and there is one
for a sheet, Thank you!

Hi Rui,

Thanks for your posting and using Aspose.Cells.

You can use Aspose.Cells for GridWeb for this purpose. It will show your Excel file worksheets in separate tabs and fulfill your needs.

I have attached the sample GridWeb project for your reference. Also attached the screenshots illustrating how it displays source Excel workbook sheets in different tabs.

Himshakeel.faiz is not online. Last active: 08-05-2014, 11:52 AM
Shakeel,

Thank you for introduction about GridWeb and it looks great. However as we are using MVC and I was wondering it could be integrated with our project now. Thank you


Hi Rui,

Thanks for your posting and using Aspose.Cells.

We have looked into your requirement and we are afraid, you cannot use GridWeb control in MVC. Please see the following post for your reference.

( Microsoft Office Web Component (OWC) )