Search in sources :

Example 76 with HSSFCell

use of org.apache.poi.hssf.usermodel.HSSFCell in project adempiere by adempiere.

the class SmjXlsReport method generate.

public HSSFWorkbook generate(LinkedList<ReportTO> data, String[] generalTitle, String clientName, String clientNIT, String periodName, String currencyName, MReportColumn[] m_columns, String city, Integer logoId) {
    int fila = 0;
    HSSFRow row;
    cols = m_columns.length + 2;
    endRegion = (short) (cols - 1);
    try {
        // create workbook
        HSSFWorkbook book = new HSSFWorkbook();
        // crea hoja - create sheet
        // Goodwill BF: Invalid sheet name
        HSSFSheet sheet = book.createSheet(StringUtils.makePrefix(generalTitle[0]));
        // crea fuente - Create Font
        HSSFFont font = book.createFont();
        font.setFontHeightInPoints((short) 13);
        font.setFontName(HSSFFont.FONT_ARIAL);
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        // estio celda - cell style
        HSSFCellStyle cellStyle = book.createCellStyle();
        cellStyle.setWrapText(true);
        cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
        cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
        cellStyle.setFont(font);
        // add logo
        if (logoId > 0) {
            MImage mimage = MImage.get(Env.getCtx(), logoId);
            byte[] imageData = mimage.getData();
            HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
            HSSFClientAnchor anchor;
            anchor = new HSSFClientAnchor(100, 50, 200, 255, (short) 0, 0, (short) 1, 1);
            anchor.setAnchorType(2);
            int pictureIndex = book.addPicture(imageData, HSSFWorkbook.PICTURE_TYPE_PNG);
            patriarch.createPicture(anchor, pictureIndex);
            for (int i = 0; i < 5; i++) row = sheet.createRow(fila++);
        }
        //if Logo report
        // Titulo General - general Title
        row = sheet.createRow(fila++);
        HSSFRichTextString text = new HSSFRichTextString(generalTitle[0]);
        HSSFCell cell = row.createCell((short) 0);
        cell.setCellStyle(cellStyle);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(text);
        Region region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
        sheet.addMergedRegion(region);
        // empresa - Company
        row = sheet.createRow(fila++);
        text = new HSSFRichTextString(clientName);
        cell = row.createCell((short) 0);
        cell.setCellStyle(cellStyle);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(text);
        region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
        sheet.addMergedRegion(region);
        // Ciudad - City
        row = sheet.createRow(fila++);
        text = new HSSFRichTextString(city);
        cell = row.createCell((short) 0);
        cell.setCellStyle(cellStyle);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(text);
        region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
        sheet.addMergedRegion(region);
        // NIT
        row = sheet.createRow(fila++);
        text = new HSSFRichTextString(clientNIT);
        cell = row.createCell((short) 0);
        cell.setCellStyle(cellStyle);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(text);
        region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
        sheet.addMergedRegion(region);
        // periodo - Period
        String pn = "";
        if (generalTitle[1] != null && generalTitle[1].length() > 0) {
            pn = generalTitle[1] + " " + periodName;
        } else {
            pn = periodName;
        }
        if (generalTitle[2] != null && generalTitle[2].length() > 0) {
            pn = pn + " " + generalTitle[2];
        }
        row = sheet.createRow(fila++);
        text = new HSSFRichTextString(pn);
        cell = row.createCell((short) 0);
        cell.setCellStyle(cellStyle);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(text);
        region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
        sheet.addMergedRegion(region);
        // tipo moneda - currency
        row = sheet.createRow(fila++);
        text = new HSSFRichTextString(currencyName);
        cell = row.createCell((short) 0);
        cell.setCellStyle(cellStyle);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(text);
        region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
        sheet.addMergedRegion(region);
        row = sheet.createRow(fila++);
        titleTable(book, sheet, fila++, m_columns);
        // llena datos del reporte - fill data report
        reportTable(book, data, sheet, fila);
        return book;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
//try/catch
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFClientAnchor(org.apache.poi.hssf.usermodel.HSSFClientAnchor) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) MImage(org.compiere.model.MImage) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) Region(org.apache.poi.hssf.util.Region) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFFont(org.apache.poi.hssf.usermodel.HSSFFont)

Example 77 with HSSFCell

use of org.apache.poi.hssf.usermodel.HSSFCell in project adempiere by adempiere.

the class SmjXlsReport method putRow.

// reportTable
/**
	 * pone la linea de informacion en el XLS
	 * put information line into XLS
	 * @param cellStyle
	 * @param cellStyleD
	 * @param cellStyleN
	 * @param sheet
	 * @param row
	 * @param fila
	 * @param rpt
	 */
private void putRow(HSSFCellStyle cellStyle, HSSFCellStyle cellStyleD, HSSFCellStyle cellStyleN, HSSFSheet sheet, HSSFRow row, int fila, ReportTO rpt) {
    HSSFRichTextString text;
    short col = 0;
    cellStyle.setAlignment(HSSFCellStyle.ALIGN_RIGHT);
    //Nombre - Name
    text = new HSSFRichTextString(rpt.getName());
    HSSFCell cell = row.createCell(col++);
    cell.setCellStyle(cellStyleN);
    cell.setCellValue(text);
    //Descripcion - Description
    text = new HSSFRichTextString(rpt.getDescription());
    cell.setCellStyle(cellStyleD);
    cell = row.createCell(col++);
    cell.setCellValue(text);
    if (cols >= 3) {
        //Col0
        text = new HSSFRichTextString(formatValue(rpt.getCol_0()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 4) {
        //Col1
        text = new HSSFRichTextString(formatValue(rpt.getCol_1()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 5) {
        //Col2
        text = new HSSFRichTextString(formatValue(rpt.getCol_2()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 6) {
        //Col3
        text = new HSSFRichTextString(formatValue(rpt.getCol_3()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 7) {
        //Col4
        text = new HSSFRichTextString(formatValue(rpt.getCol_4()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 8) {
        //Col5
        text = new HSSFRichTextString(formatValue(rpt.getCol_5()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 9) {
        //Col6
        text = new HSSFRichTextString(formatValue(rpt.getCol_6()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 10) {
        //Col7
        text = new HSSFRichTextString(formatValue(rpt.getCol_7()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 11) {
        //Col8
        text = new HSSFRichTextString(formatValue(rpt.getCol_8()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 12) {
        //Col9
        text = new HSSFRichTextString(formatValue(rpt.getCol_9()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 13) {
        //Col10
        text = new HSSFRichTextString(formatValue(rpt.getCol_10()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 14) {
        //Col11
        text = new HSSFRichTextString(formatValue(rpt.getCol_11()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 15) {
        //Col12
        text = new HSSFRichTextString(formatValue(rpt.getCol_12()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 16) {
        //Col13
        text = new HSSFRichTextString(formatValue(rpt.getCol_13()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 17) {
        //Col14
        text = new HSSFRichTextString(formatValue(rpt.getCol_14()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 18) {
        //Col15
        text = new HSSFRichTextString(formatValue(rpt.getCol_15()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 19) {
        //Col16
        text = new HSSFRichTextString(formatValue(rpt.getCol_16()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 20) {
        //Col17
        text = new HSSFRichTextString(formatValue(rpt.getCol_17()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 21) {
        //Col18
        text = new HSSFRichTextString(formatValue(rpt.getCol_18()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 22) {
        //Col19
        text = new HSSFRichTextString(formatValue(rpt.getCol_19()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
    if (cols >= 23) {
        //Col20
        text = new HSSFRichTextString(formatValue(rpt.getCol_20()));
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellValue(text);
    }
}
Also used : HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell)

Example 78 with HSSFCell

use of org.apache.poi.hssf.usermodel.HSSFCell in project adempiere by adempiere.

the class SmjXlsReport method titleTable.

// generate
/**
	 * Crea la fila de titulos - create title row
	 * @param wb
	 * @param hs
	 * @param fila
	 * @param colsName
	 */
private void titleTable(HSSFWorkbook book, HSSFSheet sheet, int fila, MReportColumn[] m_columns) {
    short col = 0;
    // crea fuente - create font
    HSSFFont font = book.createFont();
    font.setFontHeightInPoints((short) 13);
    font.setFontName(HSSFFont.FONT_ARIAL);
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    //		font.setColor(HSSFColor.BLUE.index);
    // estio celda - cell style
    HSSFCellStyle cellStyle = book.createCellStyle();
    cellStyle.setWrapText(true);
    cellStyle.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY);
    cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
    //		cellStyle.setFillPattern(HSSFCellStyle.SPARSE_DOTS);
    //		cellStyle.setFillBackgroundColor(HSSFColor.GREY_40_PERCENT.index);
    cellStyle.setFont(font);
    // //Titulos de la tabla - Table titles
    HSSFRow row = sheet.createRow(fila);
    // Nombre - name
    HSSFRichTextString text = new HSSFRichTextString(Msg.translate(Env.getCtx(), "name").toUpperCase());
    HSSFCell cell = row.createCell(col++);
    cell.setCellStyle(cellStyle);
    cell.setCellType(HSSFCell.CELL_TYPE_STRING);
    cell.setCellValue(text);
    // Desripcion - description
    text = new HSSFRichTextString(Msg.translate(Env.getCtx(), "description").toUpperCase());
    cell = row.createCell(col++);
    cell.setCellStyle(cellStyle);
    cell.setCellType(HSSFCell.CELL_TYPE_STRING);
    cell.setCellValue(text);
    // columnas de valores - Value Columns
    for (MReportColumn mcol : m_columns) {
        String colName = mcol.getName();
        text = new HSSFRichTextString(colName.toUpperCase());
        cell = row.createCell(col++);
        cell.setCellStyle(cellStyle);
        cell.setCellType(HSSFCell.CELL_TYPE_STRING);
        cell.setCellValue(text);
    }
//for columnas
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) MReportColumn(org.compiere.report.MReportColumn) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFFont(org.apache.poi.hssf.usermodel.HSSFFont) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Example 79 with HSSFCell

use of org.apache.poi.hssf.usermodel.HSSFCell in project adempiere by adempiere.

the class AbstractExcelExporter method export.

/**
	 * Export to given stream
	 * @param out
	 * @throws Exception
	 */
private void export(OutputStream out) throws Exception {
    HSSFSheet sheet = createTableSheet();
    String sheetName = null;
    //
    int colnumMax = 0;
    for (int rownum = 0, xls_rownum = 1; rownum < getRowCount(); rownum++, xls_rownum++) {
        setCurrentRow(rownum);
        boolean isPageBreak = false;
        HSSFRow row = sheet.createRow(xls_rownum);
        //	for all columns
        int colnum = 0;
        for (int col = 0; col < getColumnCount(); col++) {
            if (colnum > colnumMax)
                colnumMax = colnum;
            //
            if (isColumnPrinted(col)) {
                HSSFCell cell = row.createCell(colnum);
                // line row
                Object obj = getValueAt(rownum, col);
                int displayType = getDisplayType(rownum, col);
                if (obj == null)
                    ;
                else if (DisplayType.isDate(displayType)) {
                    Timestamp value = (Timestamp) obj;
                    cell.setCellValue(value);
                } else if (DisplayType.isNumeric(displayType)) {
                    double value = 0;
                    if (obj instanceof Number) {
                        value = ((Number) obj).doubleValue();
                    }
                    cell.setCellValue(value);
                } else if (DisplayType.YesNo == displayType) {
                    boolean value = false;
                    if (obj instanceof Boolean)
                        value = (Boolean) obj;
                    else
                        value = "Y".equals(obj);
                    cell.setCellValue(new HSSFRichTextString(Msg.getMsg(getLanguage(), value == true ? "Y" : "N")));
                } else {
                    //	formatted
                    String value = fixString(obj.toString());
                    cell.setCellValue(new HSSFRichTextString(value));
                }
                //
                HSSFCellStyle style = getStyle(rownum, col);
                cell.setCellStyle(style);
                // Page break
                if (isPageBreak(rownum, col)) {
                    isPageBreak = true;
                    sheetName = fixString(cell.getRichStringCellValue().getString());
                }
                //
                colnum++;
            }
        //	printed
        }
        // Page Break
        if (isPageBreak) {
            closeTableSheet(sheet, sheetName, colnumMax);
            sheet = createTableSheet();
            xls_rownum = 0;
            isPageBreak = false;
        }
    }
    //	for all rows
    closeTableSheet(sheet, sheetName, colnumMax);
    //
    m_workbook.write(out);
    out.close();
    // Workbook Info
    if (CLogMgt.isLevelFine()) {
        log.fine("Sheets #" + m_sheetCount);
        log.fine("Styles used #" + m_styles.size());
    }
}
Also used : HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) Timestamp(java.sql.Timestamp) HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet)

Example 80 with HSSFCell

use of org.apache.poi.hssf.usermodel.HSSFCell in project adempiere by adempiere.

the class AbstractExcelExporter method createTableHeader.

private void createTableHeader(HSSFSheet sheet) {
    short colnumMax = 0;
    HSSFRow row = sheet.createRow(0);
    //	for all columns
    short colnum = 0;
    for (int col = 0; col < getColumnCount(); col++) {
        if (colnum > colnumMax)
            colnumMax = colnum;
        //
        if (isColumnPrinted(col)) {
            HSSFCell cell = row.createCell(colnum);
            //	header row
            HSSFCellStyle style = getHeaderStyle(col);
            cell.setCellStyle(style);
            String str = fixString(getHeaderName(col));
            cell.setCellValue(new HSSFRichTextString(str));
            colnum++;
        }
    //	printed
    }
//	for all columns
//		m_workbook.setRepeatingRowsAndColumns(m_sheetCount, 0, 0, 0, 0);
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Aggregations

HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)147 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)96 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)93 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)91 HSSFCellStyle (org.apache.poi.hssf.usermodel.HSSFCellStyle)31 HSSFFormulaEvaluator (org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator)30 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)28 Test (org.junit.Test)25 FileOutputStream (java.io.FileOutputStream)24 IOException (java.io.IOException)18 HSSFFont (org.apache.poi.hssf.usermodel.HSSFFont)16 File (java.io.File)13 CellValue (org.apache.poi.ss.usermodel.CellValue)13 ArrayList (java.util.ArrayList)11 AssertionFailedError (junit.framework.AssertionFailedError)10 HashMap (java.util.HashMap)9 OutputStream (java.io.OutputStream)8 Map (java.util.Map)8 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)8 FileInputStream (java.io.FileInputStream)6