Apache POI - setting input field left / right in Excel

Is it possible - with apache POI - to set the left or right print edge for an Excel worksheet?

The default fields are quite large. I see neither setLeftMargin nor setRightMargin in XSSFPrintSetup, but only the header and footer:

XSSFPrintSetup printSetup = (XSSFPrintSetup) sheet.getPrintSetup(); printSetup.setHeaderMargin(0.5D); printSetup.setFooterMargin(0.5D); 

Is there any good friend who could help me a little?

+6
source share
2 answers

Sheet fields are not contained in the XSSFPrintSetup object, but in the XSSFSheet itself. Use the Sheet methods getMargin and setMargin , passing the corresponding Sheet constant for the header / left / foot / right / header / footer. Set and get a margin in inches.

 double leftMarginInches = sheet.getMargin(Sheet.LeftMargin); sheet.setMargin(Sheet.RightMargin, 0.5 /* inches */ ); 
+17
source

Now the listing is MarginType.LeftMargin, -RightMargin

 double leftMargin = sheet.GetMargin(MarginType.LeftMargin); double rightMargin = sheet.GetMargin(MarginType.RightMargin); 

Update:

Code preceding this code:

  var workbook = new XSSFWorkbook(); var sheet = workbook.CreateSheet(sheetname); double leftMargin = sheet.GetMargin(MarginType.LeftMargin); double rightMargin = sheet.GetMargin(MarginType.RightMargin); 

This is truly an NPOI.

-2
source

All Articles