BF [ 1974309 ] Exporting a report to XLS is not setting page format
This commit is contained in:
parent
6adcc98adb
commit
d4d6fea6fb
|
@ -68,6 +68,9 @@ public abstract class AbstractExcelExporter
|
||||||
private HSSFFont m_fontDefault = null;
|
private HSSFFont m_fontDefault = null;
|
||||||
private Language m_lang = null;
|
private Language m_lang = null;
|
||||||
private int m_sheetCount = 0;
|
private int m_sheetCount = 0;
|
||||||
|
//
|
||||||
|
private int m_colSplit = 1;
|
||||||
|
private int m_rowSplit = 1;
|
||||||
/** Styles cache */
|
/** Styles cache */
|
||||||
private HashMap<String, HSSFCellStyle> m_styles = new HashMap<String, HSSFCellStyle>();
|
private HashMap<String, HSSFCellStyle> m_styles = new HashMap<String, HSSFCellStyle>();
|
||||||
|
|
||||||
|
@ -80,6 +83,11 @@ public abstract class AbstractExcelExporter
|
||||||
return Env.getCtx();
|
return Env.getCtx();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void setFreezePane(int colSplit, int rowSplit) {
|
||||||
|
m_colSplit = colSplit;
|
||||||
|
m_rowSplit = rowSplit;
|
||||||
|
}
|
||||||
|
|
||||||
private String fixString(String str)
|
private String fixString(String str)
|
||||||
{
|
{
|
||||||
// ms excel doesn't support UTF8 charset
|
// ms excel doesn't support UTF8 charset
|
||||||
|
@ -216,7 +224,8 @@ public abstract class AbstractExcelExporter
|
||||||
return;
|
return;
|
||||||
//
|
//
|
||||||
fixColumnWidth(prevSheet, colCount);
|
fixColumnWidth(prevSheet, colCount);
|
||||||
prevSheet.createFreezePane(1, 1);
|
if (m_colSplit >= 0 || m_rowSplit >= 0)
|
||||||
|
prevSheet.createFreezePane(m_colSplit >= 0 ? m_colSplit : 0, m_rowSplit >= 0 ? m_rowSplit : 0);
|
||||||
if (!Util.isEmpty(prevSheetName, true) && m_sheetCount > 0) {
|
if (!Util.isEmpty(prevSheetName, true) && m_sheetCount > 0) {
|
||||||
int prevSheetIndex = m_sheetCount - 1;
|
int prevSheetIndex = m_sheetCount - 1;
|
||||||
try {
|
try {
|
||||||
|
@ -230,22 +239,8 @@ public abstract class AbstractExcelExporter
|
||||||
private HSSFSheet createTableSheet()
|
private HSSFSheet createTableSheet()
|
||||||
{
|
{
|
||||||
HSSFSheet sheet= m_workbook.createSheet();
|
HSSFSheet sheet= m_workbook.createSheet();
|
||||||
sheet.setFitToPage(true);
|
formatPage(sheet);
|
||||||
// Print Setup
|
createHeaderFooter(sheet);
|
||||||
HSSFPrintSetup ps = sheet.getPrintSetup();
|
|
||||||
sheet.setAutobreaks(true);
|
|
||||||
ps.setFitWidth((short)1);
|
|
||||||
ps.setNoColor(true);
|
|
||||||
// Sheet Header
|
|
||||||
HSSFHeader header = sheet.getHeader();
|
|
||||||
header.setRight(HSSFHeader.page()+ " / "+HSSFHeader.numPages());
|
|
||||||
// Sheet Footer
|
|
||||||
HSSFFooter footer = sheet.getFooter();
|
|
||||||
footer.setLeft(Adempiere.ADEMPIERE_R);
|
|
||||||
footer.setCenter(Env.getHeader(getCtx(), 0));
|
|
||||||
Timestamp now = new Timestamp(System.currentTimeMillis());
|
|
||||||
footer.setRight(DisplayType.getDateFormat(DisplayType.DateTime, getLanguage()).format(now));
|
|
||||||
// Table Header
|
|
||||||
createTableHeader(sheet);
|
createTableHeader(sheet);
|
||||||
m_sheetCount++;
|
m_sheetCount++;
|
||||||
//
|
//
|
||||||
|
@ -282,6 +277,30 @@ public abstract class AbstractExcelExporter
|
||||||
// m_workbook.setRepeatingRowsAndColumns(m_sheetCount, 0, 0, 0, 0);
|
// m_workbook.setRepeatingRowsAndColumns(m_sheetCount, 0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void createHeaderFooter(HSSFSheet sheet)
|
||||||
|
{
|
||||||
|
// Sheet Header
|
||||||
|
HSSFHeader header = sheet.getHeader();
|
||||||
|
header.setRight(HSSFHeader.page()+ " / "+HSSFHeader.numPages());
|
||||||
|
// Sheet Footer
|
||||||
|
HSSFFooter footer = sheet.getFooter();
|
||||||
|
footer.setLeft(Adempiere.ADEMPIERE_R);
|
||||||
|
footer.setCenter(Env.getHeader(getCtx(), 0));
|
||||||
|
Timestamp now = new Timestamp(System.currentTimeMillis());
|
||||||
|
footer.setRight(DisplayType.getDateFormat(DisplayType.DateTime, getLanguage()).format(now));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void formatPage(HSSFSheet sheet)
|
||||||
|
{
|
||||||
|
sheet.setFitToPage(true);
|
||||||
|
// Print Setup
|
||||||
|
HSSFPrintSetup ps = sheet.getPrintSetup();
|
||||||
|
ps.setFitWidth((short)1);
|
||||||
|
ps.setNoColor(true);
|
||||||
|
ps.setPaperSize(HSSFPrintSetup.A4_PAPERSIZE);
|
||||||
|
ps.setLandscape(false);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Export to given stream
|
* Export to given stream
|
||||||
* @param out
|
* @param out
|
||||||
|
|
|
@ -16,9 +16,14 @@ package org.adempiere.print.export;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
|
import javax.print.attribute.standard.MediaSizeName;
|
||||||
|
|
||||||
import org.adempiere.impexp.AbstractExcelExporter;
|
import org.adempiere.impexp.AbstractExcelExporter;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||||
import org.compiere.print.MPrintFormat;
|
import org.compiere.print.MPrintFormat;
|
||||||
import org.compiere.print.MPrintFormatItem;
|
import org.compiere.print.MPrintFormatItem;
|
||||||
|
import org.compiere.print.MPrintPaper;
|
||||||
import org.compiere.print.PrintData;
|
import org.compiere.print.PrintData;
|
||||||
import org.compiere.print.PrintDataElement;
|
import org.compiere.print.PrintDataElement;
|
||||||
|
|
||||||
|
@ -26,6 +31,7 @@ import org.compiere.print.PrintDataElement;
|
||||||
* Export PrintData to Excel (XLS) file
|
* Export PrintData to Excel (XLS) file
|
||||||
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
* @author Teo Sarca, SC ARHIPAC SERVICE SRL
|
||||||
* <li>BF [ 1939010 ] Excel Export ERROR - java.sql.Date - integrated Mario Grigioni's fix
|
* <li>BF [ 1939010 ] Excel Export ERROR - java.sql.Date - integrated Mario Grigioni's fix
|
||||||
|
* <li>BF [ 1974309 ] Exporting a report to XLS is not setting page format
|
||||||
*/
|
*/
|
||||||
public class PrintDataExcelExporter
|
public class PrintDataExcelExporter
|
||||||
extends AbstractExcelExporter
|
extends AbstractExcelExporter
|
||||||
|
@ -131,4 +137,56 @@ extends AbstractExcelExporter
|
||||||
protected boolean isFunctionRow() {
|
protected boolean isFunctionRow() {
|
||||||
return m_printData.isFunctionRow();
|
return m_printData.isFunctionRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void formatPage(HSSFSheet sheet) {
|
||||||
|
super.formatPage(sheet);
|
||||||
|
MPrintPaper paper = MPrintPaper.get(this.m_printFormat.getAD_PrintPaper_ID());
|
||||||
|
//
|
||||||
|
// Set paper size:
|
||||||
|
short paperSize = -1;
|
||||||
|
MediaSizeName mediaSizeName = paper.getMediaSize().getMediaSizeName();
|
||||||
|
if (MediaSizeName.NA_LETTER.equals(mediaSizeName)) {
|
||||||
|
paperSize = HSSFPrintSetup.LETTER_PAPERSIZE;
|
||||||
|
}
|
||||||
|
else if (MediaSizeName.NA_LEGAL.equals(mediaSizeName)) {
|
||||||
|
paperSize = HSSFPrintSetup.LEGAL_PAPERSIZE;
|
||||||
|
}
|
||||||
|
else if (MediaSizeName.EXECUTIVE.equals(mediaSizeName)) {
|
||||||
|
paperSize = HSSFPrintSetup.EXECUTIVE_PAPERSIZE;
|
||||||
|
}
|
||||||
|
else if (MediaSizeName.ISO_A4.equals(mediaSizeName)) {
|
||||||
|
paperSize = HSSFPrintSetup.A4_PAPERSIZE;
|
||||||
|
}
|
||||||
|
else if (MediaSizeName.ISO_A5.equals(mediaSizeName)) {
|
||||||
|
paperSize = HSSFPrintSetup.A5_PAPERSIZE;
|
||||||
|
}
|
||||||
|
else if (MediaSizeName.NA_NUMBER_10_ENVELOPE.equals(mediaSizeName)) {
|
||||||
|
paperSize = HSSFPrintSetup.ENVELOPE_10_PAPERSIZE;
|
||||||
|
}
|
||||||
|
// else if (MediaSizeName..equals(mediaSizeName)) {
|
||||||
|
// paperSize = HSSFPrintSetup.ENVELOPE_DL_PAPERSIZE;
|
||||||
|
// }
|
||||||
|
// else if (MediaSizeName..equals(mediaSizeName)) {
|
||||||
|
// paperSize = HSSFPrintSetup.ENVELOPE_CS_PAPERSIZE;
|
||||||
|
// }
|
||||||
|
else if (MediaSizeName.MONARCH_ENVELOPE.equals(mediaSizeName)) {
|
||||||
|
paperSize = HSSFPrintSetup.ENVELOPE_MONARCH_PAPERSIZE;
|
||||||
|
}
|
||||||
|
if (paperSize != -1) {
|
||||||
|
sheet.getPrintSetup().setPaperSize(paperSize);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// Set Landscape/Portrait:
|
||||||
|
sheet.getPrintSetup().setLandscape(paper.isLandscape());
|
||||||
|
//
|
||||||
|
// Set Paper Margin:
|
||||||
|
sheet.setMargin(HSSFSheet.TopMargin, ((double)paper.getMarginTop()) /72);
|
||||||
|
sheet.setMargin(HSSFSheet.RightMargin, ((double)paper.getMarginRight()) / 72);
|
||||||
|
sheet.setMargin(HSSFSheet.LeftMargin, ((double)paper.getMarginLeft()) / 72);
|
||||||
|
sheet.setMargin(HSSFSheet.BottomMargin, ((double)paper.getMarginBottom()) / 72);
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue