Skip to content

Commit

Permalink
Fixed error with bad value for lookups at export report
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih committed Aug 23, 2024
1 parent 68d938a commit b2918f3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
13 changes: 13 additions & 0 deletions src/main/java/org/spin/report_engine/data/ColumnInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class ColumnInfo {
private int columnCharactersSize;
private boolean isFixedWidth;
private String fontCode;
private String mappingClassName;
private PrintFormatItem item;


private ColumnInfo(PrintFormatItem item) {
this.title = item.getPrintText();
Expand All @@ -49,12 +52,22 @@ private ColumnInfo(PrintFormatItem item) {
this.isFixedWidth = item.isFixedWidth();
this.fontCode = item.getFontCode();
this.color = item.getColor();
this.mappingClassName = item.getMappingClassName();
this.item = item;
}

public static ColumnInfo newInstance(PrintFormatItem item) {
return new ColumnInfo(item);
}

public PrintFormatItem getPrintformatItem() {
return item;
}

public String getMappingClassName() {
return mappingClassName;
}

public int getColumnCharactersSize() {
return columnCharactersSize;
}
Expand Down
43 changes: 30 additions & 13 deletions src/main/java/org/spin/report_engine/export/XlsxExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
import org.spin.model.MADAppRegistration;
import org.spin.report_engine.data.ColumnInfo;
import org.spin.report_engine.data.ReportInfo;
import org.spin.report_engine.mapper.DefaultMapping;
import org.spin.report_engine.mapper.IColumnMapping;
import org.spin.report_engine.util.ClassLoaderMapping;
import org.spin.util.support.AppSupportHandler;
import org.spin.util.support.IAppSupport;

Expand Down Expand Up @@ -185,6 +188,15 @@ public String export(ReportInfo reportInfo) {
ColumnInfo columnInfo = columns.get(columnNumber);
org.spin.report_engine.data.Row rowValue = rows.get(rowNumber);
org.spin.report_engine.data.Cell cell = rowValue.getCell(columnInfo.getPrintFormatItemId());
// Apply Default Mask
if(!Util.isEmpty(columnInfo.getMappingClassName())) {
IColumnMapping customMapping = ClassLoaderMapping.loadClass(columnInfo.getMappingClassName());
if(customMapping != null) {
customMapping.processValue(columnInfo.getPrintformatItem(), language, cell);
}
} else {
DefaultMapping.newInstance().processValue(columnInfo.getPrintformatItem(), language, cell);
}
int displayType = columnInfo.getDisplayTypeId();
Object valueasObject = cell.getValue();
if(valueasObject != null) {
Expand All @@ -203,20 +215,25 @@ public String export(ReportInfo reportInfo) {
} else {
String displayValue = cell.getDisplayValue();
if(Util.isEmpty(displayValue)) {
if(valueasObject instanceof BigDecimal) {
sheetCell.setCellValue(((BigDecimal) valueasObject).doubleValue());
} else if (valueasObject instanceof Integer) {
sheetCell.setCellValue((Integer) valueasObject);
} else if (valueasObject instanceof String) {
displayValue = (String) valueasObject;
displayValue = Util.stripDiacritics(displayValue);
sheetCell.setCellValue(sheet.getWorkbook().getCreationHelper().createRichTextString(displayValue));
} else if (valueasObject instanceof Boolean) {
sheetCell.setCellValue((Boolean) valueasObject);
} else if(valueasObject instanceof Timestamp) {
Timestamp value = (Timestamp) valueasObject;
sheetCell.setCellValue(value);
if(!DisplayType.isLookup(displayType)) {
if(valueasObject instanceof BigDecimal) {
sheetCell.setCellValue(((BigDecimal) valueasObject).doubleValue());
} else if (valueasObject instanceof Integer) {
sheetCell.setCellValue((Integer) valueasObject);
} else if (valueasObject instanceof String) {
displayValue = (String) valueasObject;
displayValue = Util.stripDiacritics(displayValue);
sheetCell.setCellValue(sheet.getWorkbook().getCreationHelper().createRichTextString(displayValue));
} else if (valueasObject instanceof Boolean) {
sheetCell.setCellValue((Boolean) valueasObject);
} else if(valueasObject instanceof Timestamp) {
Timestamp value = (Timestamp) valueasObject;
sheetCell.setCellValue(value);
}
}
} else {
displayValue = Util.stripDiacritics(displayValue);
sheetCell.setCellValue(sheet.getWorkbook().getCreationHelper().createRichTextString(displayValue));
}
}
}
Expand Down

0 comments on commit b2918f3

Please sign in to comment.