Export worksheet To Html

Hi,

First of all, I’m using Aspose.Cells for .NET dll in a web application. In my app I need to export a given worksheet to Html and display the result into an Asp page.

I found in your documentation a way to export a whole workbook with

_wb.Save(_savePath + "ConvertingToHTMLFiles_out.html", SaveFormat.Html)

But is there a way to export only one worksheet ?

Also, if it’s possible how may I display the result into an asp Panel ?

Could you please tell me if there is a way to do it?

Thanks for your answer,

@lswe,

Thanks for your query.

Well, you may hide/remove your unwanted worksheets from the workbook and then save to HTML file format via Aspose.Cells APIs, see the document (although it renders to PDF file format but you may refer to it) for your reference:

Moreover, Aspose.Cells does render Excel spreadsheet to HTML similar to what MS Excel does (when you save to “Web page” in MS Excel manually). The output HTML file is rather MS Excel oriented and not a common HTML file. Anyways, you may use it. You may try embedding the HTML source in asp panel by yourself if the contents displays fine.

Thanks for your answer,

I followed your suggestion and it works as well as expected. First, I load the workbook, then I make hidden all the worksheet except one. I save the workbook into a MemoryStream using ExportImagesAsBase64 to true and ExportHiddenWorksheet to false. I convert the memory stream to a string to get the html code then I insert the code into a asp:Literal to display the result. The result is fine.

However, I looked the generated html and something seems problematic. All the size are defined in “pt” which is a fixed size. This means that if my container Panel width is 600px I’m going to get an horizontal scrollbar if the generated table width is bigger.

So is there a way to change this fixed size into a a scalable unit like “em” or “percent” to get a better result presentation ?

Thanks,

@lswe,

Aspose.Cells follows MS Excel standards and specifications when rendering to HTML file format. I am not sure if there is such an option available in MS Excel either which could scale the output differently. By the way, could you try using PresentationPreference option to make it more elegant, see the sample lines of code for your reference:
e.g
Sample code:

..........
  //Create HtmlSaveOptions object
            HtmlSaveOptions options = new HtmlSaveOptions();
            //Set the Presenation preference option
            options.PresentationPreference = true;

            //Save the Excel file to HTML with specified option
            workbook.Save("e:\\test2\\out1.html", options); 

Hope, this helps a bit.

Hi,

Thanks for your suggestion,

However if I set PresentationPreference to true, the generated html is quite the same. The only thing which changed is col width unit. Without PresentationPreference, width are in “pt” and with PresentationPreference, width are in “px”. But both of them are fixed size unit. So it does not solve my problem.

You will find here here the generated html with and without setting PresentationPreference to true.

Thanks

@lswe,

Thanks for the sample HTML files.

Could you provide us template Excel file and generated HTML file (by Aspose.Cells APIs). Also provide your desired HTML (you may create/edit it manually) which should show what should be your expected results. Also provide some screenshots to highlight the comparisons of the sources for current output Vs expected results. We will log an investigation ticket into our database if we could figure it out.

You will find here the files you asked for. Some screenshot will be quite useless to highlight desired behaviour. Please just open desiredOutput.html file in your favorite browser. Try to decrease browser window width and you will notice the page element automatically resize. If you do that with your generated file (asposeOutput.html) you will notice that some scrollbar are displayed. It’s because of the fixed size col width. In the desiredOutput.html file, I changed all the width using percent unit.

Thanks for your help,

@lswe,

Thanks for the template file, output files.

We understand your needs. I have logged a ticket for your requested feature as following:
CELLSNET-46194 - Export Excel to HTML - change columns’ fixed size width (i.e., pt/px) into scalable unit like “em” or “percent”.

We will look into it if we could support your needs. Once we have an update on it, we will let you know here.

@lswe,

This is to inform you that we have fixed your issue now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

@lswe,

Please try our latest version/fix: Aspose.Cells for .NET (Latest Version)

Your issue should be fixed in it.

Please note:

  1. We added HtmlSaveOptions.WidthScalable property which indicates whether using scalable unit to describe the column width when exporting file to HTML.

The default value is false.

  1. The sample code is as follows:
    e.g
    Sample code:

     Workbook wb = new Workbook(filePath + "template.xlsm");
    
     HtmlSaveOptions options = new HtmlSaveOptions();
    
     options.WidthScalable = true;
    
     options.ExportImagesAsBase64 = true;
    
     wb.Save(filePath + "out.html", options);
    

Let us know your feedback.

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


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