https://issues.apache.org/bugzilla/show_bug.cgi?id=56999
Bug ID: 56999
Summary: SXSSF Workbook with Java5 is producing unreadable xlsx
document
Product: POI
Version: 3.10-FINAL
Hardware: PC
OS: Windows XP
Status: NEW
Severity: blocker
Priority: P2
Component: SXSSF
Assignee: [email protected]
Reporter: [email protected]
Hi ,
I am using Apache POI 3.10 Final version to generate an excel document as per
my application requirement. My application runs on JDK 1.5 version and it is
producing an unreadable xlsx document saying " Excel found unreadable content
in XXX.XLSX. Do you want to recover the contents of the workbook?"
Please find the simulation of code i have used
public static void main(String[] args) {
SXSSFWorkbook workbook = new SXSSFWorkbook(300);
SXSSFSheet sheet = (SXSSFSheet)
workbook.createSheet("Teller_Discrepancy");
Map<String, Object[]> data = new HashMap<String, Object[]>();
final String[] titles = {
"Col1","Col2","Col3",.......,"Col15"
};
createHeaderRow(workbook, sheet, titles);
writeToExcel(sheet, data, getColumnStyle(workbook));
sheet.setDefaultColumnWidth(15);
FileOutputStream out = new FileOutputStream(new File("C:\Temp"));
workbook.write(out);
out.close();
}
private void writeToExcel(SXSSFSheet sheet, Map<String, Object[]> data,
CellStyle columnStyle){
Set<String> keyset = data.keySet();
int rownum = 1;
for (String key : keyset) {
SXSSFRow row = (SXSSFRow) sheet.createRow(rownum++);
Object [] objArr = data.get(key);
int cellnum = 0;
for (Object obj : objArr) {
SXSSFCell cell = (SXSSFCell) row.createCell(cellnum++);
cell.setCellStyle(columnStyle);
if (obj == null) {
cell.setCellValue("");
}
else {
cell.setCellValue(String.valueOf(obj));
}
}
}
}
private void createHeaderRow(SXSSFWorkbook workbook, SXSSFSheet sheet,
String[] titles) {
// Setting Title Font properties
Font titleFont = workbook.createFont();
titleFont.setFontHeightInPoints((short)9);
titleFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
// Setting Header Style
CellStyle style = workbook.createCellStyle();
style.setAlignment(CellStyle.ALIGN_CENTER);
style.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
style.setFillForegroundColor(IndexedColors.YELLOW.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
style.setFont(titleFont);
style.setWrapText(true);
style.setBorderBottom(CellStyle.BORDER_THIN);
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderLeft(CellStyle.BORDER_THIN);
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderRight(CellStyle.BORDER_THIN);
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
style.setBorderTop(CellStyle.BORDER_THIN);
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
// Creating Header Row
SXSSFRow headerRow = (SXSSFRow) sheet.createRow(0);
headerRow.setHeightInPoints(40);
SXSSFCell headerCell;
for (int i = 0; i < titles.length; i++) {
headerCell = (SXSSFCell) headerRow.createCell(i);
headerCell.setCellValue(titles[i]);
headerCell.setCellStyle(style);
}
}
private CellStyle getColumnStyle(SXSSFWorkbook workbook) {
CellStyle columnStyle = workbook.createCellStyle();
columnStyle.setAlignment(CellStyle.ALIGN_CENTER);
columnStyle.setVerticalAlignment(CellStyle.VERTICAL_CENTER);
columnStyle.setBorderBottom(CellStyle.BORDER_THIN);
columnStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
columnStyle.setBorderLeft(CellStyle.BORDER_THIN);
columnStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
columnStyle.setBorderRight(CellStyle.BORDER_THIN);
columnStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
columnStyle.setBorderTop(CellStyle.BORDER_THIN);
columnStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
return columnStyle;
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]