We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Convert Excel to HTML or image

I'm new to Aspose.cell. I have a simple question. Can I use aspose.cell to convert Excel (.xls) to either HTML or an image (i.e. gif, jpg or png). I need to support preview of Excel spreadsheet in a web page. I was hoping I could find a browser plug-in. But no luck. So I'm thinking of generating either a HTML version of the spreadsheet or an image in order to preview it.

Thanks,

-Bin

Hi bzhang3,

I think, I have seen something called sheettoimage somewhere in this forum. Basically, Amjad had posted a new version of Aspose.Cell.dll which had this functionality. So, search for SheettoImage in this forum and it might help you.

-pload

Hi Bin,

Thanks for considering Aspose.

Thanks pload for helping him out a bit.

I'm new to Aspose.cell. I have a simple question. Can I use aspose.cell to convert Excel (.xls) to either HTML or an image (i.e. gif, jpg or png). I need to support preview of Excel spreadsheet in a web page. I was hoping I could find a browser plug-in. But no luck. So I'm thinking of generating either a HTML version of the spreadsheet or an image in order to preview it.

Yes, you may do it both ways. Saving .xls file to .html and Sheet2Image are our latest features.
Please check the sample code:
Workbook wb = new Workbook();
wb.Open(@"d:\test\Book1.xls");
//Get the image of first sheet.
Bitmap bitmap = wb.Worksheets[0].SheetToImage();
bitmap.Save(@"d:\test\sheetimage.png",System.Drawing.Imaging.ImageFormat.Png);
book.Save("d:\\test\\websheet.html",FileFormatType.Html);
Thank you.

Hi,

Forgot to attach the latest version / fix for you, here it is, please try it

Thank you.

Amjad and Pload,

Thanks both of you for the helpful info.

Amjad,

Regarding to saving .xls to html or image, I have some more questions:

1. Which version of Aspose.cell supports that? I don't see FileFormatType.Html or SheetToImage() in the online documentation. BTW, is it SheetToImage() or Sheet2Image()?

2. When saved as HTML, does it save all the workbooks, or just the first one? If multiple workbooks are saved, does it provides any way to navigate through them?

3. When saved as either HTML or Image, does it include Charts? Is there a document to explain what excel features get included and what get excluded when saving to HTML or image?

Thanks,

-Bin

Amjad,

I tried SheetToImage(). But I ran into some issues with it.

1. It looks like Grid lines and chart objects are not included in the output image. Can this be fixed?

2. It threw exceptions for some worksheets. For example, I tried a demo xls file (Aspose.Cells\Demos\Designer\FinancialPlan.xls). It threw a nullreference exception for the first worksheet. It worked ok with the 2nd worksheet.

3. It seems this method is overloaded. What do you do with the bool parameter in SheetToImage(bool)?

Thanks,

-Bin

Hi Bin,

Thanks for considering Aspose.

First I will respond to your previous queries:

1. Which version of Aspose.cell supports that? I don't see FileFormatType.Html or SheetToImage() in the online documentation. BTW, is it SheetToImage() or Sheet2Image()?

Well Sheet2Image and saving an .xls file as .html are our latest features and we want users to give a try as we have released them for testing purpose currently. The version (4.4.3.15) which I sent you in my previous post as an attchement does include both the features. And we will update our online documentation soon.

2. When saved as HTML, does it save all the workbooks, or just the first one? If multiple workbooks are saved, does it provides any way to navigate through them?

You mean to say all the worksheets in a workbook, well, yes, all the sheets in a workbook are saved. Navigation is the same as .xls file in ms excel as the sheet names are tabbed at the bottom.

3. When saved as either HTML or Image, does it include Charts? Is there a document to explain what excel features get included and what get excluded when saving to HTML or image?

Well, saving as .html would include charts but sheet2image will currently exclude them currently. Well, you may utilize Chart.ToImage() method to get the image of the chart. This feature is already there : Convert an Excel chart to image

Now let us come towards you recent questions:

1. It looks like Grid lines and chart objects are not included in the output image. Can this be fixed?

Well, if you check in MS Excel manually, gridlines are not seen when taking the print preview of a sheet. If you want to implement tabular format, you may either apply borders in MS Excel or use Aspose.Cells APIs to set borders for your data cells range: Adding border to cells

Using Named Ranges

2. It threw exceptions for some worksheets. For example, I tried a demo xls file (Aspose.Cells\Demos\Designer\FinancialPlan.xls). It threw a nullreference exception for the first worksheet. It worked ok with the 2nd worksheet.

Yes, we found the issue and will fix it soon.

3. It seems this method is overloaded. What do you do with the bool parameter in SheetToImage(bool)?

Please check the following notes to get the complete reference about the all the overloaded versions of the Worksheet.SheetToImage() method:

Notes:

The following list shows the versions of Worksheet.SheetToImage() overloaded method:

///

/// Creates the sheet image and returns it as a Bitmap object.

///

///

public Bitmap SheetToImage()

///

/// Creates the sheet image and saves it to a file.

///

/// The image file name with full path.

/// Indicates whether workshert can be paginated

///

///

The following formats are supported:

/// .bmp, .gif, .jpg, .jpeg, .tiff, .emf.

///

public void SheetToImage(string imageFile, bool isPaginate)

///

/// Creates the sheet image and saves it to a file.

///

/// The image file name with full path.

///

The following formats are supported:

/// .bmp, .gif, .jpg, .jpeg, .tiff, .emf.

///

public void SheetToImage(string imageFile)

///

/// Creates the sheet image and saves it to a file in the specified format.

///

/// The image file name with full path.

/// The format in which to save the image.

/// Indicates whether workshert can be paginated

///

The following formats are supported:

/// .bmp, .gif, .jpg, .jpeg, .tiff, .emf.

///

public void SheetToImage(string imageFile, ImageFormat imageFormat, bool isPaginate)

///

/// Creates the sheet image and saves it to a file in the specified format.

///

/// The image file name with full path.

/// The format in which to save the image.

///

The following formats are supported:

/// .bmp, .gif, .jpg, .jpeg, .tiff, .emf.

///

public void SheetToImage(string imageFile, ImageFormat imageFormat)

And we also support print worksheet now.

///

/// Prints the work sheet

///

/// The printer name

public void SheetToPrinter(String PrinterName)

Thank you.

I need this functionality as well so I thought I would jump in. I have version 4.4.3.1 of Aspose.Cells which I recently downloaded after purchasing Aspose.Totals. Nowhere in the documentation does it mention HTML as a member of FileFormatType. Also, if you use intellisense to drop down all of the members of this enumeration in code, HTML is not listed.

Thanks,

Todd Herman

Hi,

We introduced this functionality recently, we will embed it in our future versions and update the documentation with the release.

Kindly try the attached version (4.4.3.15), the FileFormatType.Html is included in it.

Thank you.

I noticed that the bin directory for Aspose.Cells has a Net1.0 and Net2.0 folder. Is the attached Aspose.Cells dll for version 1.1 or 2.0 of the .NET Framework?

Thanks,

Todd

Hi Todd,

The version / fix I attached is compiled on framework 1.x and it will work fine on .NET 2.0 or so.

Thank you.

Amjad,

Does the latest build (4.4.3.15) you attached require an updated license file?

I purchased Aspose.Total license and used the following code to set the license for Aspose.Cells.

string licenseFile = Path.Combine(Page.MapPath(@"..\bin"), "Aspose.Total.lic");
if (System.IO.File.Exists(licenseFile))
{
Aspose.Cells.License licenseCells = new Aspose.Cells.License();
licenseCells.SetLicense(licenseFile);
}

But I still get an evaluation worksheet in the generated HTML files.

Thanks,

-Bin

Hi Bin,

Could you check the expiry date of your Aspose.Total license. The license will never stop worksing. But, it is to be noted here, when you purchase the license, you are authorized to use this license file with any new (upcoming) versions / hot fixes of the components (Cells,Words, Pdf etc.) for the next whole year. Obviously, if you want to utilize any version / fix of any component which is released after your subscription expiry date, then you do need to upgrade your subscription only.

If your license is not expired, kindly be assured that you / somebody should not edit the license file manually.

Thank you.

Amjad,

I purchased the Aspose.Total license yesterday. I used it for Aspose.Words and it worked ok (no water marker saying it's an evaluation version). But for some reason, I keep getting the evaluation worksheet in the HTML pages generated by Aspose.Cells.

Also, I noticed some generated files (such as sheet001.htm, sheet002.htm) are not closed after I called workbook.Save(). As a result, I got 'file is used by another process' error when I tried to delete/overwrite them (either in the same ASP.net page or using Windows Explorer). I'm not entirely sure if it's Aspose.Cells problem or the problem with ASP.net. Could you please also take a look?

Thanks,

-Bin

Hi Bin,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Aspose.Cells do close all the generated html files in workbook.Save().Please test the following code:

Workbook book = new Workbook();

string outFn = @"E:\test\Aspose_Cells\Html\testFileClose.htm";

book.Save(outFn, FileFormatType.Html);

string delFn = @"E:\test\Aspose_Cells\Html\testFileClose_files\sheet001.htm";

File.Delete(delFn); // it will not throws out any exception

If you still find the problem, please give us more details and do create a sample project, zip the project and post us here to show and reproduce the problem. We will check and fix it soon if found the problem.

Thank you.

The problem with files not being closed is sort of random. I used process explorer to check which process holding the file handles. I don't know if it's a problem with aspnet worker process. Have you heard anything like that before?

Apart from that, could you help me resolve the license issue? Why I keep getting the evaluation worksheet even after I set the license to the license file I just purchased (see my previous post for details).

Thanks,

-Bin

Hi Bin,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

1. For the issue that files not being closed, we found the problem and fixed it. Please try the attached version.

2. For the license issue, Aspose.Cells will not export evaluation worksheet if the license file is set correctly. Please test the following code:

License lic = new License();

lic.SetLicense(@"E:\temp\Aspose.Cells.lic");

Workbook book = new Workbook();

book.Worksheets.Add();

string outFn = @"E:\temp\testFileClose.htm";

book.Save(outFn, FileFormatType.Html);

If you still getting the evaluation worksheet, please post your license file to nanjing@aspose.com , we will check it soon.

Thank you.

Hi Bin,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

If you are using Aspose.Words and Aspose.Cells in one problem, you have to set license for each of them separately. Please test the following code and check if the evaluation worksheet still appearance:

Aspose.Cells.License lic = new Aspose.Cells.License(); lic.SetLicense(@"E:\temp\Aspose.Cells.lic");

Workbook book = new Workbook();

book.Worksheets.Add();

string outFn = @"E:\temp\testFileClose.htm";

book.Save(outFn, FileFormatType.Html);

Thank you.

Karen,

The license issue was resolved. It was my mistake. I set the license in a method that I never called it. I'll check out the fix for files not being closed.

Thanks,

-Bin

Hi,

I run into another problem with saving Excel to HTML. I have a spreadsheet which uses an external data source (pointing to a SQL server database). I converted it to HTML but I noticed the chart which is generated based on the data in SQL server database is not rendered in HTML. Does 'save to HTML' support external source?

Thanks,

-Bin