IDEMPIERE-3994 Show Report Parameters for Excel Export

This commit is contained in:
Heng Sin Low 2019-06-25 21:42:16 +08:00
parent 37cf63c31f
commit c573b240e9
3 changed files with 91 additions and 4 deletions

View File

@ -121,7 +121,7 @@ public abstract class AbstractExcelExporter
/** Logger */ /** Logger */
protected final CLogger log = CLogger.getCLogger(getClass()); protected final CLogger log = CLogger.getCLogger(getClass());
// //
private HSSFWorkbook m_workbook; protected HSSFWorkbook m_workbook;
private HSSFDataFormat m_dataFormat; private HSSFDataFormat m_dataFormat;
private HSSFFont m_fontHeader = null; private HSSFFont m_fontHeader = null;
private HSSFFont m_fontDefault = null; private HSSFFont m_fontDefault = null;
@ -135,6 +135,7 @@ public abstract class AbstractExcelExporter
private HashMap<String, HSSFCellStyle> m_styles = new HashMap<String, HSSFCellStyle>(); private HashMap<String, HSSFCellStyle> m_styles = new HashMap<String, HSSFCellStyle>();
protected Boolean[] colSuppressRepeats; protected Boolean[] colSuppressRepeats;
private int noOfParameter = 0;
public AbstractExcelExporter() { public AbstractExcelExporter() {
m_workbook = new HSSFWorkbook(); m_workbook = new HSSFWorkbook();
@ -311,6 +312,7 @@ public abstract class AbstractExcelExporter
HSSFSheet sheet= m_workbook.createSheet(); HSSFSheet sheet= m_workbook.createSheet();
formatPage(sheet); formatPage(sheet);
createHeaderFooter(sheet); createHeaderFooter(sheet);
createParameter(sheet);
createTableHeader(sheet); createTableHeader(sheet);
m_sheetCount++; m_sheetCount++;
// //
@ -318,10 +320,15 @@ public abstract class AbstractExcelExporter
} }
private void createTableHeader(HSSFSheet sheet) private void createTableHeader(HSSFSheet sheet)
{
createTableHeader(sheet, Math.max(noOfParameter, 0));
}
private void createTableHeader(HSSFSheet sheet, int headerRowNum)
{ {
int colnumMax = 0; int colnumMax = 0;
HSSFRow row = sheet.createRow(0); HSSFRow row = sheet.createRow(headerRowNum);
// for all columns // for all columns
int colnum = 0; int colnum = 0;
for (int col = 0; col < getColumnCount(); col++) for (int col = 0; col < getColumnCount(); col++)
@ -343,6 +350,21 @@ public abstract class AbstractExcelExporter
// m_workbook.setRepeatingRowsAndColumns(m_sheetCount, 0, 0, 0, 0); // m_workbook.setRepeatingRowsAndColumns(m_sheetCount, 0, 0, 0, 0);
} }
protected int getNoOfParameter()
{
return noOfParameter;
}
protected void setNoOfParameter(int noOfParameter)
{
this.noOfParameter = noOfParameter;
}
protected void createParameter(HSSFSheet sheet)
{
}
protected void createHeaderFooter(HSSFSheet sheet) protected void createHeaderFooter(HSSFSheet sheet)
{ {
// Sheet Header // Sheet Header
@ -408,7 +430,9 @@ public abstract class AbstractExcelExporter
preValues = new Object [colSuppressRepeats.length]; preValues = new Object [colSuppressRepeats.length];
} }
for (int xls_rownum = 1; rownum < lastRowNum; rownum++, xls_rownum++) int initxls_rownum = Math.max(noOfParameter+1, 1);
for (int xls_rownum = initxls_rownum; rownum < lastRowNum; rownum++, xls_rownum++)
{ {
if (!isCurrentRowOnly()) if (!isCurrentRowOnly())
setCurrentRow(rownum); setCurrentRow(rownum);

View File

@ -19,14 +19,21 @@ import java.util.Date;
import javax.print.attribute.standard.MediaSizeName; import javax.print.attribute.standard.MediaSizeName;
import org.adempiere.impexp.AbstractExcelExporter; import org.adempiere.impexp.AbstractExcelExporter;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFPrintSetup; import org.apache.poi.hssf.usermodel.HSSFPrintSetup;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.compiere.model.MQuery;
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.MPrintPaper;
import org.compiere.print.PrintData; import org.compiere.print.PrintData;
import org.compiere.print.PrintDataElement; import org.compiere.print.PrintDataElement;
import org.compiere.util.DisplayType; import org.compiere.util.DisplayType;
import org.compiere.util.Msg;
import org.compiere.util.Util; import org.compiere.util.Util;
/** /**
@ -40,12 +47,18 @@ extends AbstractExcelExporter
{ {
private PrintData m_printData; private PrintData m_printData;
private MPrintFormat m_printFormat; private MPrintFormat m_printFormat;
private MQuery m_query;
public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat, Boolean[] colSuppressRepeats) { public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat, Boolean[] colSuppressRepeats) {
this(printData, printFormat, colSuppressRepeats, null);
}
public PrintDataExcelExporter(PrintData printData, MPrintFormat printFormat, Boolean[] colSuppressRepeats, MQuery query) {
super(); super();
this.m_printData = printData; this.m_printData = printData;
this.m_printFormat = printFormat; this.m_printFormat = printFormat;
this.colSuppressRepeats = colSuppressRepeats; this.colSuppressRepeats = colSuppressRepeats;
this.m_query = query;
} }
@Override @Override
@ -218,4 +231,54 @@ extends AbstractExcelExporter
return cellFormat; return cellFormat;
} }
@Override
protected void createParameter(HSSFSheet sheet) {
if (!m_printFormat.isForm()) {
if (m_query != null && m_query.isActive()) {
int rows = m_query.getReportProcessQuery() != null ? m_query.getReportProcessQuery().getRestrictionCount() : m_query.getRestrictionCount();
if (rows > 0) {
setNoOfParameter(rows);
setFreezePane(1, rows + 1);
HSSFCellStyle parameterStyle = m_workbook.createCellStyle();
HSSFFont parameterFont = m_workbook.createFont();
parameterFont.setItalic(true);
parameterStyle.setFont(parameterFont);
MQuery query = m_query;
if (m_query.getReportProcessQuery() != null)
query = m_query.getReportProcessQuery();
for (int r = 0; r < query.getRestrictionCount(); r++)
{
HSSFRow row = sheet.createRow(r);
if (r == 0) {
HSSFCell cell = row.createCell(0);
HSSFCellStyle style = m_workbook.createCellStyle();
HSSFFont font = m_workbook.createFont();
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
style.setFont(font);
cell.setCellStyle(style);
String value = Util.stripDiacritics(Msg.getMsg(getCtx(), "Parameter") + ":");
cell.setCellValue(new HSSFRichTextString(value));
}
HSSFCell cell = row.createCell(1);
cell.setCellStyle(parameterStyle);
String value = Util.stripDiacritics(query.getInfoName(r));
cell.setCellValue(new HSSFRichTextString(value));
cell = row.createCell(2);
cell.setCellStyle(parameterStyle);
value = Util.stripDiacritics(query.getInfoOperator(r));
cell.setCellValue(new HSSFRichTextString(value));
cell = row.createCell(3);
cell.setCellStyle(parameterStyle);
value = Util.stripDiacritics(query.getInfoDisplayAll(r));
cell.setCellValue(new HSSFRichTextString(value));
}
}
}
}
}
} }

View File

@ -1470,7 +1470,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
throws Exception throws Exception
{ {
Boolean [] colSuppressRepeats = m_layout == null || m_layout.colSuppressRepeats == null? LayoutEngine.getColSuppressRepeats(m_printFormat):m_layout.colSuppressRepeats; Boolean [] colSuppressRepeats = m_layout == null || m_layout.colSuppressRepeats == null? LayoutEngine.getColSuppressRepeats(m_printFormat):m_layout.colSuppressRepeats;
PrintDataExcelExporter exp = new PrintDataExcelExporter(getPrintData(), getPrintFormat(), colSuppressRepeats); PrintDataExcelExporter exp = new PrintDataExcelExporter(getPrintData(), getPrintFormat(), colSuppressRepeats, m_query);
exp.export(outFile, language); exp.export(outFile, language);
} }