Search in sources :

Example 1 with Region

use of org.apache.poi.hssf.util.Region in project adempiere by adempiere.

the class SmjXlsReport method reportTable.

// titleTable
/**
	 * llena los datos del reporte - fill report data
	 * @param book
	 * @param data
	 * @param sheet
	 * @param fila
	 */
public void reportTable(HSSFWorkbook book, LinkedList<ReportTO> data, HSSFSheet sheet, int fila) {
    HSSFRow row;
    // crea fuente - create font
    HSSFFont font = book.createFont();
    font.setFontHeightInPoints((short) 10);
    font.setFontName(HSSFFont.FONT_ARIAL);
    HSSFRichTextString text;
    Iterator<ReportTO> itRep = data.iterator();
    Boolean newRow = false;
    sheet.setColumnWidth((short) 0, (short) (13 * 256));
    sheet.setColumnWidth((short) 1, (short) (60 * 256));
    for (int i = 2; i < (cols); i++) {
        sheet.setColumnWidth((short) i, (short) (15 * 256));
    }
    //for
    // estio celda - cell style
    HSSFCellStyle cellStyle = book.createCellStyle();
    HSSFCellStyle cellStyleD = book.createCellStyle();
    HSSFCellStyle cellStyleN = book.createCellStyle();
    while (itRep.hasNext()) {
        short col = 0;
        ReportTO rpt = itRep.next();
        if (!newRow) {
            cellStyle = book.createCellStyle();
            cellStyleD = book.createCellStyle();
            cellStyleN = book.createCellStyle();
        }
        //if
        newRow = false;
        if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("T")) {
            // Coloca titulo - put title
            row = sheet.createRow(fila++);
            HSSFFont fontT = book.createFont();
            fontT.setFontHeightInPoints((short) 12);
            fontT.setFontName(HSSFFont.FONT_ARIAL);
            fontT.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            HSSFCellStyle cellStyleT = book.createCellStyle();
            cellStyleT.setWrapText(true);
            cellStyleT.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            cellStyleT.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
            cellStyleT.setFont(fontT);
            Region region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
            sheet.addMergedRegion(region);
            text = new HSSFRichTextString(rpt.getDescription());
            HSSFCell cellT = row.createCell(col);
            cellT.setCellStyle(cellStyleT);
            cellT.setCellValue(text);
            newRow = true;
        } else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("L")) {
            // coloca linea en el reporte - Put under line in the report
            cellStyle.setWrapText(true);
            cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
            cellStyle.setBottomBorderColor((short) 8);
            cellStyleD.setWrapText(true);
            cellStyleD.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
            cellStyleD.setBottomBorderColor((short) 8);
            cellStyleN.setWrapText(true);
            cellStyleN.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
            cellStyleN.setBottomBorderColor((short) 8);
            newRow = true;
        } else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("X")) {
            // coloca linea de total - Put total line
            cellStyle.setWrapText(true);
            cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
            cellStyle.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
            cellStyle.setBottomBorderColor((short) 8);
            newRow = true;
        } else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("Z")) {
            // coloca linea doble de total - Put total line doble
            cellStyle.setWrapText(true);
            cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
            cellStyle.setBorderTop(HSSFCellStyle.BORDER_DOUBLE);
            cellStyle.setBottomBorderColor((short) 8);
            //--------------
            row = sheet.createRow(fila++);
            ReportTO rptD = new ReportTO();
            putRow(cellStyle, cellStyleD, cellStyleN, sheet, row, fila, rptD);
            cellStyle = book.createCellStyle();
            newRow = true;
        } else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("D")) {
            // coloca liena de descripcion - put description line
            cellStyleD.setWrapText(true);
            cellStyleD.setVerticalAlignment(HSSFCellStyle.VERTICAL_TOP);
            cellStyleD.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
            cellStyleD.setBottomBorderColor((short) 8);
            newRow = true;
        } else if (rpt.getReportlinestyle() != null && rpt.getReportlinestyle().equals("S")) {
            // coloca linea en blanco - put empty line
            row = sheet.createRow(fila++);
            newRow = true;
        } else if (rpt.getTablevel() != null && rpt.getTablevel() > 0) {
            // coloca espacios a la izquierda para simular jeraquia - put
            // left spaces to simulate hierarchy
            row = sheet.createRow(fila++);
            String jerarchy = "";
            for (int i = 1; i <= rpt.getTablevel(); i++) {
                jerarchy = jerarchy + "   ";
            }
            //for
            Region region = new Region(fila - 1, (short) 0, fila - 1, endRegion);
            sheet.addMergedRegion(region);
            text = new HSSFRichTextString(jerarchy + rpt.getDescription());
            HSSFCell cellJ = row.createCell(col);
            cellJ.setCellValue(text);
            newRow = true;
        } else {
            row = sheet.createRow(fila++);
            putRow(cellStyle, cellStyleD, cellStyleN, sheet, row, fila, rpt);
        }
    //else
    }
// while itData
}
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) ReportTO(org.compiere.model.ReportTO) Region(org.apache.poi.hssf.util.Region) HSSFFont(org.apache.poi.hssf.usermodel.HSSFFont) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Example 2 with Region

use of org.apache.poi.hssf.util.Region 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 3 with Region

use of org.apache.poi.hssf.util.Region in project my_curd by qinyou.

the class PoiKit method export.

public HSSFWorkbook export() {
    Preconditions.checkNotNull(headers, "headers can not be null");
    Preconditions.checkNotNull(columns, "columns can not be null");
    Preconditions.checkArgument(cellWidth >= 0, "cellWidth < 0");
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet = wb.createSheet(sheetName);
    HSSFRow row = null;
    HSSFCell cell = null;
    if (headers.length > 0) {
        row = sheet.createRow(0);
        if (headerRow <= 0) {
            headerRow = HEADER_ROW;
        }
        headerRow = Math.min(headerRow, MAX_ROWS);
        for (int h = 0, lenH = headers.length; h < lenH; h++) {
            @SuppressWarnings("deprecation") Region // 合并从第rowFrom行columnFrom列
            region = new Region(0, (short) h, (short) headerRow - 1, (short) h);
            // 到rowTo行columnTo的区域
            sheet.addMergedRegion(region);
            // 得到所有区域
            sheet.getNumMergedRegions();
            if (cellWidth > 0) {
                sheet.setColumnWidth(h, cellWidth);
            }
            cell = row.createCell(h);
            cell.setCellValue(headers[h]);
            HSSFCellStyle style = wb.createCellStyle();
            style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
            style.setFillForegroundColor(HSSFColor.AQUA.index);
            cell.setCellStyle(style);
        }
    }
    if (data.size() == 0) {
        return wb;
    }
    for (int i = 0, len = data.size(); i < len; i++) {
        row = sheet.createRow(i + headerRow);
        Object obj = data.get(i);
        if (obj == null) {
            continue;
        }
        if (obj instanceof Map) {
            processAsMap(columns, row, obj);
        } else if (obj instanceof Model) {
            processAsModel(columns, row, obj);
        } else if (obj instanceof Record) {
            processAsRecord(columns, row, obj);
        }
    }
    return wb;
}
Also used : Model(com.jfinal.plugin.activerecord.Model) Region(org.apache.poi.hssf.util.Region) Record(com.jfinal.plugin.activerecord.Record) Map(java.util.Map)

Aggregations

Region (org.apache.poi.hssf.util.Region)3 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)2 HSSFCellStyle (org.apache.poi.hssf.usermodel.HSSFCellStyle)2 HSSFFont (org.apache.poi.hssf.usermodel.HSSFFont)2 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)2 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)2 Model (com.jfinal.plugin.activerecord.Model)1 Record (com.jfinal.plugin.activerecord.Record)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 Map (java.util.Map)1 HSSFClientAnchor (org.apache.poi.hssf.usermodel.HSSFClientAnchor)1 HSSFPatriarch (org.apache.poi.hssf.usermodel.HSSFPatriarch)1 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 MImage (org.compiere.model.MImage)1 ReportTO (org.compiere.model.ReportTO)1