Search in sources :

Example 21 with HSSFRichTextString

use of org.apache.poi.hssf.usermodel.HSSFRichTextString 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 22 with HSSFRichTextString

use of org.apache.poi.hssf.usermodel.HSSFRichTextString 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 23 with HSSFRichTextString

use of org.apache.poi.hssf.usermodel.HSSFRichTextString 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 24 with HSSFRichTextString

use of org.apache.poi.hssf.usermodel.HSSFRichTextString 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)

Example 25 with HSSFRichTextString

use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project poi by apache.

the class InCellLists method numberedListInCell.

/**
     * Inserts a numbered list into a single cell.
     *
     * @param workbook A reference to the HSSFWorkbook that 'contains' the
     *                 cell.
     * @param listItems An ArrayList whose elements encapsulate the text for
     *                  the lists items.
     * @param cell An instance of the HSSFCell class that encapsulates a
     *             reference to the spreadsheet cell into which the list
     *             will be written.
     * @param startingValue A primitive int containing the number for the first
     *                      item in the list.
     * @param increment A primitive int containing the value that should be used
     *                  to calculate subsequent item numbers.
     */
public void numberedListInCell(HSSFWorkbook workbook, ArrayList<String> listItems, HSSFCell cell, int startingValue, int increment) {
    StringBuilder buffer = new StringBuilder();
    int itemNumber = startingValue;
    // Note that again, an HSSFCellStye object is required and that
    // it's wrap text property should be set to 'true'
    HSSFCellStyle wrapStyle = workbook.createCellStyle();
    wrapStyle.setWrapText(true);
    // with one difference; a number prefixed to the items text.
    for (String listItem : listItems) {
        buffer.append(itemNumber).append(". ");
        buffer.append(listItem);
        buffer.append("\n");
        itemNumber += increment;
    }
    // The StringBuffer's contents are the source for the contents
    // of the cell.
    cell.setCellValue(new HSSFRichTextString(buffer.toString().trim()));
    cell.setCellStyle(wrapStyle);
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Aggregations

HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)38 HSSFCellStyle (org.apache.poi.hssf.usermodel.HSSFCellStyle)17 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)16 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)9 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)8 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)7 HSSFClientAnchor (org.apache.poi.hssf.usermodel.HSSFClientAnchor)5 HSSFFont (org.apache.poi.hssf.usermodel.HSSFFont)5 HSSFPatriarch (org.apache.poi.hssf.usermodel.HSSFPatriarch)5 Test (org.junit.Test)5 HSSFSimpleShape (org.apache.poi.hssf.usermodel.HSSFSimpleShape)3 FileOutputStream (java.io.FileOutputStream)2 BigDecimal (java.math.BigDecimal)2 HSSFComment (org.apache.poi.hssf.usermodel.HSSFComment)2 Region (org.apache.poi.hssf.util.Region)2 Element (org.w3c.dom.Element)2 Text (org.w3c.dom.Text)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1