Search in sources :

Example 31 with HSSFFont

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

the class AbstractExcelExporter method getFont.

private HSSFFont getFont(boolean isHeader) {
    HSSFFont font = null;
    if (isHeader) {
        if (m_fontHeader == null) {
            m_fontHeader = m_workbook.createFont();
            m_fontHeader.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        }
        font = m_fontHeader;
    } else if (isFunctionRow()) {
        font = m_workbook.createFont();
        font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
        font.setItalic(true);
    } else {
        if (m_fontDefault == null) {
            m_fontDefault = m_workbook.createFont();
        }
        font = m_fontDefault;
    }
    return font;
}
Also used : HSSFFont(org.apache.poi.hssf.usermodel.HSSFFont)

Example 32 with HSSFFont

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

the class HSSFReadWrite method testCreateSampleSheet.

/**
	 * given a filename this outputs a sample sheet with just a set of
	 * rows/cells.
	 */
private static void testCreateSampleSheet(String outputFilename) throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    try {
        HSSFSheet s = wb.createSheet();
        HSSFCellStyle cs = wb.createCellStyle();
        HSSFCellStyle cs2 = wb.createCellStyle();
        HSSFCellStyle cs3 = wb.createCellStyle();
        HSSFFont f = wb.createFont();
        HSSFFont f2 = wb.createFont();
        f.setFontHeightInPoints((short) 12);
        f.setColor((short) 0xA);
        f.setBold(true);
        f2.setFontHeightInPoints((short) 10);
        f2.setColor((short) 0xf);
        f2.setBold(true);
        cs.setFont(f);
        cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)"));
        cs2.setBorderBottom(BorderStyle.THIN);
        cs2.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        cs2.setFillForegroundColor((short) 0xA);
        cs2.setFont(f2);
        wb.setSheetName(0, "HSSF Test");
        int rownum;
        for (rownum = 0; rownum < 300; rownum++) {
            HSSFRow r = s.createRow(rownum);
            if ((rownum % 2) == 0) {
                r.setHeight((short) 0x249);
            }
            for (int cellnum = 0; cellnum < 50; cellnum += 2) {
                HSSFCell c = r.createCell(cellnum);
                c.setCellValue(rownum * 10000 + cellnum + (((double) rownum / 1000) + ((double) cellnum / 10000)));
                if ((rownum % 2) == 0) {
                    c.setCellStyle(cs);
                }
                c = r.createCell(cellnum + 1);
                c.setCellValue(new HSSFRichTextString("TEST"));
                // 50 characters divided by 1/20th of a point
                s.setColumnWidth(cellnum + 1, (int) (50 * 8 / 0.05));
                if ((rownum % 2) == 0) {
                    c.setCellStyle(cs2);
                }
            }
        }
        // draw a thick black border on the row at the bottom using BLANKS
        rownum++;
        rownum++;
        HSSFRow r = s.createRow(rownum);
        cs3.setBorderBottom(BorderStyle.THICK);
        for (int cellnum = 0; cellnum < 50; cellnum++) {
            HSSFCell c = r.createCell(cellnum);
            c.setCellStyle(cs3);
        }
        s.addMergedRegion(new CellRangeAddress(0, 3, 0, 3));
        s.addMergedRegion(new CellRangeAddress(100, 110, 100, 110));
        // end draw thick black border
        // create a sheet, set its title then delete it
        wb.createSheet();
        wb.setSheetName(1, "DeletedSheet");
        wb.removeSheetAt(1);
        // end deleted sheet
        FileOutputStream out = new FileOutputStream(outputFilename);
        try {
            wb.write(out);
        } finally {
            out.close();
        }
    } finally {
        wb.close();
    }
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) FileOutputStream(java.io.FileOutputStream) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFFont(org.apache.poi.hssf.usermodel.HSSFFont) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 33 with HSSFFont

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

the class RepeatingRowsAndColumns method main.

public static void main(String[] args) throws IOException {
    HSSFWorkbook wb = new HSSFWorkbook();
    HSSFSheet sheet1 = wb.createSheet("first sheet");
    HSSFSheet sheet2 = wb.createSheet("second sheet");
    HSSFSheet sheet3 = wb.createSheet("third sheet");
    HSSFFont boldFont = wb.createFont();
    boldFont.setFontHeightInPoints((short) 22);
    boldFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    HSSFCellStyle boldStyle = wb.createCellStyle();
    boldStyle.setFont(boldFont);
    HSSFRow row = sheet1.createRow(1);
    HSSFCell cell = row.createCell(0);
    cell.setCellValue("This quick brown fox");
    cell.setCellStyle(boldStyle);
    // Set the columns to repeat from column 0 to 2 on the first sheet
    sheet1.setRepeatingColumns(CellRangeAddress.valueOf("A:C"));
    // Set the rows to repeat from row 0 to 2 on the second sheet.
    sheet2.setRepeatingRows(CellRangeAddress.valueOf("1:3"));
    // Set the the repeating rows and columns on the third sheet.
    CellRangeAddress cra = CellRangeAddress.valueOf("D1:E2");
    sheet3.setRepeatingColumns(cra);
    sheet3.setRepeatingRows(cra);
    FileOutputStream fileOut = new FileOutputStream("workbook.xls");
    wb.write(fileOut);
    fileOut.close();
    wb.close();
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFCell(org.apache.poi.hssf.usermodel.HSSFCell) FileOutputStream(java.io.FileOutputStream) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) HSSFFont(org.apache.poi.hssf.usermodel.HSSFFont) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook)

Example 34 with HSSFFont

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

the class ExcelToHtmlConverter method buildStyle.

protected String buildStyle(HSSFWorkbook workbook, HSSFCellStyle cellStyle) {
    StringBuilder style = new StringBuilder();
    style.append("white-space:pre-wrap;");
    ExcelToHtmlUtils.appendAlign(style, cellStyle.getAlignment());
    switch(cellStyle.getFillPattern()) {
        // no fill
        case 0:
            break;
        case 1:
            final HSSFColor foregroundColor = cellStyle.getFillForegroundColorColor();
            if (foregroundColor == null)
                break;
            String fgCol = ExcelToHtmlUtils.getColor(foregroundColor);
            style.append("background-color:" + fgCol + ";");
            break;
        default:
            final HSSFColor backgroundColor = cellStyle.getFillBackgroundColorColor();
            if (backgroundColor == null)
                break;
            String bgCol = ExcelToHtmlUtils.getColor(backgroundColor);
            style.append("background-color:" + bgCol + ";");
            break;
    }
    buildStyle_border(workbook, style, "top", cellStyle.getBorderTopEnum(), cellStyle.getTopBorderColor());
    buildStyle_border(workbook, style, "right", cellStyle.getBorderRightEnum(), cellStyle.getRightBorderColor());
    buildStyle_border(workbook, style, "bottom", cellStyle.getBorderBottomEnum(), cellStyle.getBottomBorderColor());
    buildStyle_border(workbook, style, "left", cellStyle.getBorderLeftEnum(), cellStyle.getLeftBorderColor());
    HSSFFont font = cellStyle.getFont(workbook);
    buildStyle_font(workbook, style, font);
    return style.toString();
}
Also used : HSSFColor(org.apache.poi.hssf.util.HSSFColor) HSSFFont(org.apache.poi.hssf.usermodel.HSSFFont) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Example 35 with HSSFFont

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

the class NumberComparingSpreadsheetGenerator method writeHeaderRow.

static void writeHeaderRow(HSSFWorkbook wb, HSSFSheet sheet) {
    sheet.setColumnWidth(0, 6000);
    sheet.setColumnWidth(1, 6000);
    sheet.setColumnWidth(2, 3600);
    sheet.setColumnWidth(3, 3600);
    sheet.setColumnWidth(4, 2400);
    sheet.setColumnWidth(5, 2400);
    sheet.setColumnWidth(6, 2400);
    sheet.setColumnWidth(7, 2400);
    sheet.setColumnWidth(8, 2400);
    HSSFRow row = sheet.createRow(0);
    HSSFCellStyle style = wb.createCellStyle();
    HSSFFont font = wb.createFont();
    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
    style.setFont(font);
    writeHeaderCell(row, 0, "Raw Long Bits A", style);
    writeHeaderCell(row, 1, "Raw Long Bits B", style);
    writeHeaderCell(row, 2, "Value A", style);
    writeHeaderCell(row, 3, "Value B", style);
    writeHeaderCell(row, 4, "Exp Cmp", style);
    writeHeaderCell(row, 5, "LT", style);
    writeHeaderCell(row, 6, "EQ", style);
    writeHeaderCell(row, 7, "GT", style);
    writeHeaderCell(row, 8, "Check", style);
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFFont(org.apache.poi.hssf.usermodel.HSSFFont)

Aggregations

HSSFFont (org.apache.poi.hssf.usermodel.HSSFFont)49 HSSFCellStyle (org.apache.poi.hssf.usermodel.HSSFCellStyle)43 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)19 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)16 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)14 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)12 FileOutputStream (java.io.FileOutputStream)11 HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)11 SimpleDateFormat (java.text.SimpleDateFormat)7 Row (org.apache.poi.ss.usermodel.Row)7 Sheet (org.apache.poi.ss.usermodel.Sheet)7 PostMapping (org.springframework.web.bind.annotation.PostMapping)6 MachineType (com.eservice.api.model.machine_type.MachineType)5 FileNotFoundException (java.io.FileNotFoundException)5 IOException (java.io.IOException)5 CellStyle (org.apache.poi.ss.usermodel.CellStyle)4 Machine (com.eservice.api.model.machine.Machine)3 MachineOrder (com.eservice.api.model.machine_order.MachineOrder)3 MachineOrderDetail (com.eservice.api.model.machine_order.MachineOrderDetail)3 ArrayList (java.util.ArrayList)3