Oscar Moncayo
Oscar Moncayo

Reputation: 188

Gembox Spreadsheet - Remove blank pages

I dont know how achieve this, I have to create an informative report with images. For this, I use an excell template (It helps me with the format and with the position of the text where to place the respective information). The images are generated perfectly. I convert this XLS to PDF with the property

DocumentToMemoryStream (excelTemplate, XlsxSaveOptions.XlsxDefault);

This report generate blank pages in the PDF. How can I remove these blank pages, before the excel is generated?

I have to remove this

Upvotes: 0

Views: 968

Answers (2)

Oscar Moncayo
Oscar Moncayo

Reputation: 188

I had a counter of the rows of the document I was writing on, thanks to the help of @Mario Z, I use this function, before the save and solve my problem of blank pages

wsimgs.NamedRanges.SetPrintArea(wsimgs.Cells.GetSubrange("A1",CellRange.RowColumnToPosition (countRow, 10)));

Upvotes: 0

Mario Z
Mario Z

Reputation: 4381

Without checking your spreadsheet it's impossible to tell from where do those empty pages come from, so can you upload your XLS?

Anyway, do you perhaps have some explicitly defined horizontal or vertical page breaks?
If yes, can you remove the ones you don't need?

Or, do you perhaps have empty columns at the end which have some kind of styling or formatting?
If yes, then you could try using something like this to remove those empty columns from exporting to PDF:

var workbook = ExcelFile.Load("input.xls");
var worksheet = workbook.Worksheets.ActiveWorksheet;

worksheet.NamedRanges.SetPrintArea(
    worksheet.GetUsedCellRange(true));

var options = new PdfSaveOptions();
options.SelectionType = SelectionType.ActiveSheet;
workbook.Save("output.pdf", options);

Upvotes: 2

Related Questions