Empty cells with border are missing in PDF export

Here is a sample code to reproduce (adjust the filenames…):

var file = new ExcelFile();
var sheet = file.Worksheets.Add("1");

sheet.Cells["A1"].Value = "A1";
var range = sheet.Cells.GetSubrangeAbsolute(0, 0, 5, 5);
range.Style.Borders.SetBorders(MultipleBorders.Outside, SpreadsheetColor.FromName(ColorName.Black), LineStyle.Medium);
file.Save(@"d:\Temp\TestPdfExport.xlsx");

var pdfOptions = new PdfSaveOptions();
file.Save(@"d:\Temp\TestPdfExport.pdf", pdfOptions);

Result in XLSX is OK:

But in PDF, only cell A1 is displayed:

Do I need to set some more settings or is it just a bug in the library?

P.S. As a workaround, it helps if I set

sheet.Cells["F6"].Value = "";

Hi Otakar,

Can you try using this before ExcelFile.Save methods:

sheet.NamedRanges.SetPrintArea(range);

Does this solve your issue?

Regards,
Mario

It does. Thanks a lot.

But should not be done automatically? :wink:

The problem is that by default, the print area is basically this:

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

But what you need is this:

sheet.NamedRanges.SetPrintArea(sheet.GetUsedCellRange(false));

I see…

Maybe GetUsedRange(true) should also include cells with empty content, but with defined borders…

No, that is basically the point of that bool parameter.