0

I have a C# application that is using the NPOI library version 2.3.0.0. I want to print an excel document with the default print dialog settings pager size set to Legal Paper.

I've done the following in code xlsx is an IWorkbook and sheet is ISheet.

var sheet = xlsx.CreateSheet("Statement");

sheet.PrintSetup.PaperSize = (short)PaperSize.US_Legal; 

I expect when I go to Print that the Settings show as Legal and not as Custom Paper Size. But this isn't the case. Can someone fill me in on why I'm not getting the Legal Paper size to be set?

tim
  • 879
  • 1
  • 8
  • 26

2 Answers2

2

Figured out my problem

sheet.PrintSetup.PaperSize = (short)PaperSize.US_Legal;

should be ...

sheet.PrintSetup.PaperSize = (short)PaperSize.US_Legal+1;

After adding +1, I was able to set excel print page default to legal paper.

1

I encountered the same problem as well.

When I execute the following statement, the paper size is set as A3 instead of A4.

sheet.PrintSetup.PaperSize = (short)PaperSize.A4;

The statement needs to be changed as the following in order to set the paper size as desired.

sheet.PrintSetup.PaperSize = (short)PaperSize.A4 + 1;
Jeremy Caney
  • 7,102
  • 69
  • 48
  • 77