Matrice Trasposta
Da Opengate.
private void getTransposedSheet(HSSFSheet sheet, Object whatever) {
int firstRow = sheet.getFirstRowNum(); int lastRow = sheet.getLastRowNum(); int offsetFromTop = 2; int offsetData = ((Grid)whatever).getRows().getChildren().size();
// Creating the new transposed table below the existing one
for (int i = firstRow ; i<=lastRow; ++i) {
try { HSSFRow row = sheet.getRow(i); int rowNum = row.getRowNum(); Iterator it = row.cellIterator(); while (it.hasNext()) {
HSSFCell cell = (HSSFCell) it.next(); HSSFRow newRow = sheet.createRow(cell.getCellNum() + offsetData + offsetFromTop); HSSFCell newCell = newRow.createCell((short)rowNum);
if (cell.getCellType()==HSSFCell.CELL_TYPE_NUMERIC) {
newCell.setCellValue((double)cell.getNumericCellValue());
}else {
newCell.setCellValue((String)cell.getStringCellValue());
} newCell.setCellStyle(cell.getCellStyle()); }
} catch (Exception e) { // TODO Auto-generated catch block
}
} // Deleting the old one
for (int i = firstRow ; i<=lastRow; ++i) { try { HSSFRow row = sheet.getRow(i); Iterator it = row.cellIterator();
while(it.hasNext()) {
HSSFCell cell = (HSSFCell) it.next(); sheet.removeMergedRegion(cell.getCellNum()); cell.setCellValue(""); cell.setCellStyle(blank_style); } } catch(Exception e){
e.printStackTrace();
}
} System.out.println("PRIMA: " + (offsetFromTop + offsetData)+ " ULTIMA: " + sheet.getLastRowNum()); // Shifting up the new one //sheet.shiftRows(offsetData + offsetFromTop, sheet.getLastRowNum(), -offsetData); A ME NON FUNZIONA (SHIFTA L'ULTIMA COLONNA, BAH),
for (int i = firstRow ; i<=lastRow; ++i) { try { // se la montagna non va a Maometto.... sheet.getRow(i).setHeight((short)0); }catch(Exception e){} }
}
