Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
182 views
in Technique[技术] by (71.8m points)

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

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.

question from:https://stackoverflow.com/questions/65888598/increase-the-range-of-rows-included-when-converting-from-an-excel-worksheet-to-h

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...