Increase the range of rows included when converting from an excel worksheet to HTML

Viewed 145

I would like to convert a xlsx worksheet to HTML format. The worksheet has fewer Worksheet.MaxRows than the specified PageSetup.PrintArea. Therefore when converting to HTML I would like to include empty rows beyond the MaxRows in the HTML output. When changing PageSetup.PrintArea range to be lower than MaxRows (e.g. only print rows 3-15, when the final row in the excel file is 20). But when I try to increase the range (print rows 3-25, when the final row is 20), it only prints up to row 20, instead of including the extra 5 empty rows.

I am using HtmlSaveOptions.ExportPrintAreaOnly to specify the range to print.

Here's a snippet of my code:

FilePath htmlFilePath = output.GetDirPath() + output.GetFileNameWithoutExtension() + ".html";

var htmlSaveOptions = new HtmlSaveOptions
            {
                ExportHiddenWorksheet = false,
                ExportActiveWorksheetOnly = true,
                ExportPrintAreaOnly = true
            };
                
sheet.Workbook.Save(htmlFilePath, htmlSaveOptions);

Another option I could go for is simply inserting the rows manually and removing their styling (though I seem to be having an issue applying styling but that is for another question post), but I was wondering if there is a neater, in-built way this could be done using HtmlSaveOptions.

1 Answers

Since you have set ExportPrintAreaOnly attribute to "true". so Aspose.Cells would print up to maximum row (data) only and do not include empty or null rows (even you have specified increased printable area). For your specific case, please either remove or comment out the following line of code, it will work ok.

ExportPrintAreaOnly = true

Moreover, if you still persist with using the above attribute for your needs, a workaround can be: you may add an empty string into your last row cell (e.g. sheet.Cells["A25"].PutValue(" ");)

PS. I am working as Support developer/ Evangelist at Aspose.

Related