zdravím, používám Apache POI. a podle příkladů užití se snažím číst ze vstup.xls a zapsat hodnoty do vystup.xls.
problém je v tom, že mi to do vystu.xls zapíše POUZE poslední slopec... nechápu a chybu nevidím
HSSFWorkbook workbookOut = new HSSFWorkbook();
//Read input file and edit records
try {
FileInputStream fileIn = new FileInputStream(new File("vstup.xls"));
HSSFWorkbook workbookIn = new HSSFWorkbook(fileIn);
HSSFSheet sheetIn = workbookIn.getSheetAt(0);
HSSFSheet sheetOut = workbookOut.createSheet("List1");
int rows = sheetIn.getLastRowNum();
//Get maximum of columns
{ int cols = maximum() ... }
//Read of records
int colIn,colOut;
HSSFRow rowIn;
HSSFCell cellIn;
Row rowOut;
Cell cellOut;
for (colIn = colOut = 0; colIn < cols; ++colIn, ++colOut) {
for (int actRow = 0; actRow < rows; ++actRow) {
rowIn = sheetIn.getRow(actRow);
//Create a new row in output sheet
rowOut = sheetOut.createRow(actRow);
if (rowIn != null) {
cellIn = rowIn.getCell(colIn);
//Create a new cell in output row
cellOut = rowOut.createCell(colOut);
if (cellIn != null) {
switch(cellIn.getCellType()) {
case Cell.CELL_TYPE_BOOLEAN:
cellOut.setCellValue(cellIn.getBooleanCellValue());
break;
case Cell.CELL_TYPE_NUMERIC:
.....
break;
default: break;
}
}
}
}
}
fileIn.close();
} catch ...
}
//Write edit records to output file
try {
FileOutputStream fileOut = new FileOutputStream(new File("vystup.xls"));
workbookOut.write(fileOut);
fileOut.close();
} catch ...
}