ByteArrayOutputStream output = new ByteArrayOutputStream();
try
{
WritableWorkbook wb = Workbook.createWorkbook(output);
WritableSheet sheet = wb.createSheet("Foglio 1", 0);
WritableFont wfBold = new WritableFont(WritableFont.COURIER, 8, WritableFont.BOLD);
WritableCellFormat cfBold = new WritableCellFormat(wfBold);
WritableFont wfNormal = new WritableFont(WritableFont.COURIER, 8, WritableFont.NO_BOLD);
WritableCellFormat cfNormal = new WritableCellFormat(wfNormal);
WritableCellFormat cfRight = new WritableCellFormat(wfNormal);
cfRight.setAlignment(Alignment.RIGHT);
WritableCellFormat cfRightBold = new WritableCellFormat(wfBold);
cfRightBold.setAlignment(Alignment.RIGHT);
DisplayFormat df = new NumberFormat("###,##0.00");
WritableCellFormat cfNumber = new WritableCellFormat(wfNormal, df);
cfNumber.setAlignment(Alignment.RIGHT);
WritableCellFormat cfNumberBold = new WritableCellFormat(wfBold, df);
cfNumberBold.setAlignment(Alignment.RIGHT);
DisplayFormat df_ = new NumberFormat("########0");
WritableCellFormat cfIntNumber = new WritableCellFormat(wfNormal, df_);
cfIntNumber.setAlignment(Alignment.RIGHT);
WritableCellFormat cfIntRightBold = new WritableCellFormat(wfBold, df_);
cfIntRightBold.setAlignment(Alignment.RIGHT);
WritableCellFormat cfIntRight = new WritableCellFormat(wfNormal, df_);
cfIntRight.setAlignment(Alignment.RIGHT);
Label cellValue;
Number cellNumber;
int col = 0;
cellValue = new Label(col, 2, "", cfBold);
sheet.setColumnView(col, 10);
sheet.addCell(cellValue);
col++;
cellValue = new Label(col, 2, "Gruppo", cfBold);
sheet.setColumnView(col, 10);
sheet.addCell(cellValue);
col++;
cellValue = new Label(col, 2, "Mastro", cfBold);
sheet.setColumnView(col, 10);
sheet.addCell(cellValue);
if(visible)
{
col++;
cellValue = new Label(col, 2, "Conto", cfBold);
sheet.setColumnView(col, 10);
sheet.addCell(cellValue);
}
col++;
cellValue = new Label(col, 2, "Descrizione", cfBold);
sheet.setColumnView(col, 40);
sheet.addCell(cellValue);
col++;
cellValue = new Label(col, 2, "Dare", cfBold);
sheet.setColumnView(col, 20);
sheet.addCell(cellValue);
col++;
cellValue = new Label(col, 2, "Avere", cfBold);
sheet.setColumnView(col, 20);
sheet.addCell(cellValue);
col++;
cellValue = new Label(col, 2, "Dare extr.", cfBold);
sheet.setColumnView(col, 20);
sheet.addCell(cellValue);
col++;
cellValue = new Label(col, 2, "Avere Extr.", cfBold);
sheet.setColumnView(col, 20);
sheet.addCell(cellValue);
col++;
cellValue = new Label(col, 2, "Saldo Dare", cfBold);
sheet.setColumnView(col, 20);
sheet.addCell(cellValue);
col++;
cellValue = new Label(col, 2, "Saldo Avere", cfBold);
sheet.setColumnView(col, 20);
sheet.addCell(cellValue);
int riga = 2;
for (RowBilancio bilancio : listaBilancio)
{
riga++;
col = 0;
if((StringUtility.checkNull(bilancio.getTipoAttivita())).equals(" ")) {
cellValue = new Label(col, riga, "", cfNormal);
} else {
cellValue = new Label(col, riga, StringUtility.checkNull(bilancio.getTipoAttivita()), cfBold);
}
sheet.addCell(cellValue);
col++;
if((StringUtility.checkNull(bilancio.getGruppo())).equals(" ")) {
cellValue = new Label(col, riga, "", cfIntNumber);
sheet.addCell(cellValue);
} else {
cellNumber = new Number(col, riga, Integer.parseInt((StringUtility.checkNull(bilancio.getGruppo()))), cfIntRightBold);
sheet.addCell(cellNumber);
}
col++;
if((StringUtility.checkNull(bilancio.getMastro())).equals(" ")) {
cellValue = new Label(col, riga, "", cfIntNumber);
sheet.addCell(cellValue);
} else {
cellNumber = new Number(col, riga, Integer.parseInt((StringUtility.checkNull(bilancio.getMastro()))), cfIntRight);
sheet.addCell(cellNumber);
}
if(visible)
{
col++;
if((StringUtility.checkNull(bilancio.getConto())).equals(" ")) {
cellValue = new Label(col, riga, "", cfIntNumber);
sheet.addCell(cellValue);
} else {
cellNumber = new Number(col, riga, Integer.parseInt((StringUtility.checkNull(bilancio.getConto()))), cfIntRight);
sheet.addCell(cellNumber);
}
}
col++;
if((StringUtility.checkNull(bilancio.getDescrizione())).equals(" ")) {
cellValue = new Label(col, riga, "", cfNormal);
} else {
if(NumberUtils.checkNull(bilancio.getTipoRiga()) == 0 || NumberUtils.checkNull(bilancio.getTipoRiga()) == 1
|| NumberUtils.checkNull(bilancio.getTipoRiga()) == 2) {
cellValue = new Label(col, riga, StringUtility.checkNull(bilancio.getDescrizione()), cfBold);
} else {
cellValue = new Label(col, riga, StringUtility.checkNull(bilancio.getDescrizione()), cfNormal);
}
}
sheet.addCell(cellValue);
col++;
if(NumberUtils.checkNull(bilancio.getTipoRiga()) == 0 || NumberUtils.checkNull(bilancio.getTipoRiga()) == 1
|| NumberUtils.checkNull(bilancio.getTipoRiga()) == 2) {
cellNumber = new Number(col, riga, NumberUtils.checkNull(bilancio.getDare()), cfNumberBold);
} else {
cellNumber = new Number(col, riga, NumberUtils.checkNull(bilancio.getDare()), cfNumber);
}
sheet.addCell(cellNumber);
col++;
if(NumberUtils.checkNull(bilancio.getTipoRiga()) == 0 || NumberUtils.checkNull(bilancio.getTipoRiga()) == 1
|| NumberUtils.checkNull(bilancio.getTipoRiga()) == 2) {
cellNumber = new Number(col, riga, NumberUtils.checkNull(bilancio.getAvere()), cfNumberBold);
} else {
cellNumber = new Number(col, riga, NumberUtils.checkNull(bilancio.getAvere()), cfNumber);
}
sheet.addCell(cellNumber);
col++;
if(NumberUtils.checkNull(bilancio.getTipoRiga()) == 0 || NumberUtils.checkNull(bilancio.getTipoRiga()) == 1
|| NumberUtils.checkNull(bilancio.getTipoRiga()) == 2) {
cellNumber = new Number(col, riga, NumberUtils.checkNull(bilancio.getDareExtr()), cfNumberBold);
} else {
cellNumber = new Number(col, riga, NumberUtils.checkNull(bilancio.getDareExtr()), cfNumber);
}
sheet.addCell(cellNumber);
col++;
if(NumberUtils.checkNull(bilancio.getTipoRiga()) == 0 || NumberUtils.checkNull(bilancio.getTipoRiga()) == 1
|| NumberUtils.checkNull(bilancio.getTipoRiga()) == 2) {
cellNumber = new Number(col, riga, NumberUtils.checkNull(bilancio.getAvereExtr()), cfNumberBold);
} else {
cellNumber = new Number(col, riga, NumberUtils.checkNull(bilancio.getAvereExtr()), cfNumber);
}
sheet.addCell(cellNumber);
col++;
if(NumberUtils.checkNull(bilancio.getTipoRiga()) == 0 || NumberUtils.checkNull(bilancio.getTipoRiga()) == 1
|| NumberUtils.checkNull(bilancio.getTipoRiga()) == 2) {
cellNumber = new Number(col, riga, NumberUtils.checkNull(bilancio.getDareSaldo()), cfNumberBold);
} else {
cellNumber = new Number(col, riga, NumberUtils.checkNull(bilancio.getDareSaldo()), cfNumber);
}
sheet.addCell(cellNumber);
col++;
if(NumberUtils.checkNull(bilancio.getTipoRiga()) == 0 || NumberUtils.checkNull(bilancio.getTipoRiga()) == 1
|| NumberUtils.checkNull(bilancio.getTipoRiga()) == 2) {
cellNumber = new Number(col, riga, NumberUtils.checkNull(bilancio.getAvereSaldo()), cfNumberBold);
} else {
cellNumber = new Number(col, riga, NumberUtils.checkNull(bilancio.getAvereSaldo()), cfNumber);
}
sheet.addCell(cellNumber);
}
wb.write();
wb.close();