0
votes

I have Apache POI API for Excel file manipulation. Excel file is generated from Jasper Report. Generated Excel from Jasper Report is fine. What I want is some additional things which Jasper Report do not support. Like adding print page setup - Header and Footer thing. I have ignored border margins on each Excel pages. But when I add header and footer, they are printed with some margin. Then observed that there is a checkbox on Page Setup page on MS Excel.

enter image description here

Here Align with page margins checkbox controls margin on Header and Footer. If this checkbox is checked then it will have same margin as excel page.

Question: How can I control this checkbox field from Apache POI?

1

1 Answers

1
votes

This feature has not been surfaced. But, in the XSSF file format, you can get at it using the CT Classes. I would start here:

Sheet sh = wb.createSheet();
HeaderFooter header = sh.getHeader();
XSSFHeaderFooter xhd = (XSSFHeaderFooter) header;
CTHeaderFooter ctHd = xhd.getHeaderFooter();
ctHd.setAlignWithMargins(true);

This only works with XLSX files, I don't know how to do it with XLS files. Note I started with the generic Workbook, Sheet, and Header. But then cast it over to an XSSF Header to get at the underlying CT classes. You could write the entire application with XSSF classes, and you wouldn't have to XSSFHeaderFooter xhd = (XSSFHeaderFooter) header;.