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

Free Support Forum - aspose.com

Saving individual worksheets in the Workbook as HTML using C#.NET and Java


From the samples, we found that we can save the entire workbook as html but is it possible to save individual worksheets as html too? Basically, what we want is to generate a html of a specific sheet on demand without converting the entire workbook. (Each worksheet usually has around 10,00 rows).

I saw an option to convert the active sheet to html but I am unable to figure out how to change the active sheet using aspose.

My questions are:-

(1) Does converting the active sheet convert the entire workbook internally? This is important to us for performance concerns.
(2) I believe the active sheet could be set using Aspose. Can you give me a sample on how to do this?
(3) If you convert sheet by sheet, can Aspose handle references from other sheets (e.g. chart data values)



Please use HtmlSaveOptions.ExportActiveWorksheetOnly property for your needs.

Please try the following sample code. It will help you in answering most of your questions. Please note, the code will not work in Evaluation Mode. Because, in Evaluation Mode, active worksheet does not change and always remain Evaluation Worksheet.

I have attached the Sample Excel File used in this code and Output HTML Files generated by it. Each worksheet has its own HTML file.

Download Links:
Sample-Excel-File.zip (7.1 KB)
Output-Html-Files.zip (7.4 KB)


String dirPath = @"F:\Download\";

Workbook wb = new Workbook("Sample.xlsx");

//Convert all worksheets to html one by one
int count = wb.Worksheets.Count;

for(int i=0; i<count; i++)
    HtmlSaveOptions opts = new HtmlSaveOptions();
    opts.ExportActiveWorksheetOnly = true;

    wb.Worksheets.ActiveSheetIndex = i;

    wb.Save(dirPath + "Sheet" + (i+1) + ".html", opts);

Hi Shakeel,

Thanks for the pointer. I am using Apose.java.

        Workbook wb = new Workbook(input);
        HtmlSaveOptions sv = new HtmlSaveOptions(SaveFormat.HTML);
        wb.save(output, sv);

The above seems to be working but I cannot figure out the java equivalent of the following .NET code you provided.

wb.Worksheets.ActiveSheetIndex = i;

Can you help me out?

Thanks in advance.


The Java equivalent of your mentioned line is


Here is the complete sample code in Java


String dirPath = "F:/Download/";

Workbook wb = new Workbook(dirPath + "Sample.xlsx");

// Convert all worksheets to html one by one
int count = wb.getWorksheets().getCount();

for (int i = 0; i < count; i++) {
	HtmlSaveOptions opts = new HtmlSaveOptions();


	wb.save(dirPath + "Sheet" + (i + 1) + ".html", opts);
} // end-for