IDEMPIERE-3804 - Reports exported to Excel don't use Print Format Item -> Format Pattern
This commit is contained in:
parent
7b8157861f
commit
6434e17bca
|
@ -228,7 +228,6 @@ public abstract class AbstractExcelExporter
|
|||
String key = "cell-"+col+"-"+displayType;
|
||||
HSSFCellStyle cs = m_styles.get(key);
|
||||
if (cs == null) {
|
||||
boolean isHighlightNegativeNumbers = true;
|
||||
cs = m_workbook.createCellStyle();
|
||||
HSSFFont font = getFont(false);
|
||||
cs.setFont(font);
|
||||
|
@ -238,18 +237,28 @@ public abstract class AbstractExcelExporter
|
|||
cs.setBorderRight((short)1);
|
||||
cs.setBorderBottom((short)1);
|
||||
//
|
||||
if (DisplayType.isDate(displayType)) {
|
||||
cs.setDataFormat(m_dataFormat.getFormat(DisplayType.getDateFormat(getLanguage()).toPattern()));
|
||||
}
|
||||
else if (DisplayType.isNumeric(displayType)) {
|
||||
DecimalFormat df = DisplayType.getNumberFormat(displayType, getLanguage());
|
||||
String format = getFormatString(df, isHighlightNegativeNumbers);
|
||||
cs.setDataFormat(m_dataFormat.getFormat(format));
|
||||
}
|
||||
String cellFormat = getCellFormat(row, col);
|
||||
if (cellFormat != null)
|
||||
cs.setDataFormat(m_dataFormat.getFormat(cellFormat));
|
||||
m_styles.put(key, cs);
|
||||
}
|
||||
return cs;
|
||||
}
|
||||
|
||||
protected String getCellFormat(int row, int col) {
|
||||
boolean isHighlightNegativeNumbers = true;
|
||||
int displayType = getDisplayType(row, col);
|
||||
String cellFormat = null;
|
||||
|
||||
if (DisplayType.isDate(displayType)) {
|
||||
cellFormat = DisplayType.getDateFormat(getLanguage()).toPattern();
|
||||
} else if (DisplayType.isNumeric(displayType)) {
|
||||
DecimalFormat df = DisplayType.getNumberFormat(displayType, getLanguage());
|
||||
cellFormat = getFormatString(df, isHighlightNegativeNumbers);
|
||||
}
|
||||
|
||||
return cellFormat;
|
||||
}
|
||||
|
||||
private HSSFCellStyle getHeaderStyle(int col)
|
||||
{
|
||||
|
|
|
@ -26,6 +26,8 @@ import org.compiere.print.MPrintFormatItem;
|
|||
import org.compiere.print.MPrintPaper;
|
||||
import org.compiere.print.PrintData;
|
||||
import org.compiere.print.PrintDataElement;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Util;
|
||||
|
||||
/**
|
||||
* Export PrintData to Excel (XLS) file
|
||||
|
@ -192,4 +194,24 @@ extends AbstractExcelExporter
|
|||
sheet.setMargin(HSSFSheet.BottomMargin, ((double)paper.getMarginBottom()) / 72);
|
||||
//
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getCellFormat(int row, int col) {
|
||||
String cellFormat = null;
|
||||
PrintDataElement pde = getPDE(row, col);
|
||||
|
||||
if (pde != null && !Util.isEmpty(pde.getM_formatPattern())) {
|
||||
String formatPattern = pde.getM_formatPattern();
|
||||
int displayType = pde.getDisplayType();
|
||||
if (DisplayType.isDate(displayType)) {
|
||||
cellFormat = DisplayType.getDateFormat(displayType, getLanguage(), formatPattern).toPattern();
|
||||
} else if (DisplayType.isNumeric(displayType)) {
|
||||
cellFormat = DisplayType.getNumberFormat(displayType, getLanguage(), formatPattern).toPattern();
|
||||
}
|
||||
} else {
|
||||
return super.getCellFormat(row, col);
|
||||
}
|
||||
|
||||
return cellFormat;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue