Search in sources :

Example 11 with XSSFCellStyle

use of org.apache.poi.xssf.usermodel.XSSFCellStyle in project cubrid-manager by CUBRID.

the class XlsxWriterHelper method getStyles.

/**
	 * create the cell style which is used for the head or date type cell
	 *
	 * @param workbook the instance of XSSFWorkbook
	 * @return Map<String, XSSFCellStyle>
	 */
public Map<String, XSSFCellStyle> getStyles(XSSFWorkbook workbook) {
    Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();
    XSSFDataFormat fmt = workbook.createDataFormat();
    XSSFCellStyle datetimeStyle = workbook.createCellStyle();
    datetimeStyle.setAlignment((short) 3);
    datetimeStyle.setDataFormat(fmt.getFormat("yyyy-mmm-dd h:mm:ss.ss"));
    styles.put("datetime", datetimeStyle);
    XSSFCellStyle timestampStyle = workbook.createCellStyle();
    timestampStyle.setAlignment((short) 3);
    timestampStyle.setDataFormat(fmt.getFormat("yyyy-mmm-dd h:mm:ss"));
    styles.put("timestamp", timestampStyle);
    XSSFCellStyle dateStyle = workbook.createCellStyle();
    dateStyle.setAlignment((short) 3);
    dateStyle.setDataFormat(fmt.getFormat("yyyy-mmm-dd"));
    styles.put("date", dateStyle);
    XSSFCellStyle timeStyle = workbook.createCellStyle();
    timeStyle.setAlignment((short) 3);
    timeStyle.setDataFormat(fmt.getFormat("h:mm:ss"));
    styles.put("time", timeStyle);
    XSSFCellStyle headerStyle = workbook.createCellStyle();
    XSSFFont headerFont = workbook.createFont();
    headerFont.setBold(true);
    headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
    headerStyle.setFillPattern((short) 1);
    headerStyle.setFont(headerFont);
    styles.put("header", headerStyle);
    return styles;
}
Also used : XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) HashMap(java.util.HashMap) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) XSSFDataFormat(org.apache.poi.xssf.usermodel.XSSFDataFormat)

Example 12 with XSSFCellStyle

use of org.apache.poi.xssf.usermodel.XSSFCellStyle in project cubrid-manager by CUBRID.

the class ExportToXlsxHandler method createSheetWriter.

/**
	 * Create the instance of SpreadsheetWriter and based upon the given
	 * condition writing the header of a sheet
	 *
	 * @param workbook the instance of Workbook
	 * @param xlsxWriterhelper the instance of XlsxWriterHelper
	 * @param sheetNum the number of a sheet
	 * @param fileMap a map includes the temporary file and its name
	 * @param columnTitles the column title
	 * @param xssfRowNum the number of row
	 * @throws IOException the exception
	 * @return the instance of XlsxWriterHelper.SpreadsheetWriter
	 */
private XlsxWriterHelper.SpreadsheetWriter createSheetWriter(XSSFWorkbook workbook, XlsxWriterHelper xlsxWriterhelper, int sheetNum, Map<String, File> fileMap, List<String> columnTitles, int xssfRowNum) throws IOException {
    // FIXME move this logic to core module
    XSSFSheet sheet = workbook.createSheet("sheet" + sheetNum);
    String sheetRef = sheet.getPackagePart().getPartName().getName().substring(1);
    File tmp = File.createTempFile("sheet" + sheetNum, ".xml");
    fileMap.put(sheetRef, tmp);
    String charset = null;
    if (StringUtil.isEmpty(exportConfig.getFileCharset())) {
        charset = "UTF-8";
    } else {
        charset = exportConfig.getFileCharset();
    }
    OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tmp), charset);
    XlsxWriterHelper.SpreadsheetWriter sheetWriter = new XlsxWriterHelper.SpreadsheetWriter(writer);
    sheetWriter.setCharset(charset);
    sheetWriter.beginSheet();
    if (exportConfig.isFirstRowAsColumnName() && columnTitles != null) {
        sheetWriter.insertRow(xssfRowNum);
        int styleIndex = ((XSSFCellStyle) xlsxWriterhelper.getStyles(workbook).get("header")).getIndex();
        for (int index = 0; index < columnTitles.size(); index++) {
            sheetWriter.createCell(index, columnTitles.get(index), styleIndex);
        }
        sheetWriter.endRow();
    }
    return sheetWriter;
}
Also used : XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) XlsxWriterHelper(com.cubrid.common.ui.cubrid.table.control.XlsxWriterHelper) File(java.io.File)

Example 13 with XSSFCellStyle

use of org.apache.poi.xssf.usermodel.XSSFCellStyle in project Gargoyle by callakrsos.

the class FxExcelUtil method style.

/**
	 * 셀 스타일 처리.
	 * @작성자 : KYJ
	 * @작성일 : 2016. 9. 8. 
	 * @param cell
	 * @param defaultStyle 
	 *    전역적으로 설정할 디폴트 스타일
	 * @param options
	 */
static void style(Cell cell, Consumer<XSSFCellStyle> defaultStyle, Consumer<XSSFCellStyle> options) {
    Workbook workbook = cell.getSheet().getWorkbook();
    XSSFCellStyle style = (XSSFCellStyle) workbook.createCellStyle();
    //default style.
    defaultStyle.accept(style);
    /*
		 * 2016-09-09 싱글톤형태로 사용시 에러발생. 내부적으로 생성하고 관리해야함.
		 */
    //		if (DEFAULT_FONT == null) {
    XSSFFont DEFAULT_FONT = (XSSFFont) workbook.createFont();
    DEFAULT_FONT.setColor(DEFAULT_HEADER_FONT_COLOR);
    DEFAULT_FONT.setBold(true);
    //		}
    style.setFont(DEFAULT_FONT);
    if (options != null)
        options.accept(style);
    cell.setCellStyle(style);
}
Also used : XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) Workbook(org.apache.poi.ss.usermodel.Workbook)

Example 14 with XSSFCellStyle

use of org.apache.poi.xssf.usermodel.XSSFCellStyle in project dhis2-core by dhis2.

the class ExcelNodeSerializer method startSerialize.

@Override
protected void startSerialize(RootNode rootNode, OutputStream outputStream) throws Exception {
    workbook = new XSSFWorkbook();
    sheet = workbook.createSheet("Sheet1");
    XSSFFont boldFont = workbook.createFont();
    boldFont.setBold(true);
    XSSFCellStyle boldCellStyle = workbook.createCellStyle();
    boldCellStyle.setFont(boldFont);
    // build schema
    for (Node child : rootNode.getChildren()) {
        if (child.isCollection()) {
            if (!child.getChildren().isEmpty()) {
                Node node = child.getChildren().get(0);
                XSSFRow row = sheet.createRow(0);
                int cellIdx = 0;
                for (Node property : node.getChildren()) {
                    if (property.isSimple()) {
                        XSSFCell cell = row.createCell(cellIdx++);
                        cell.setCellValue(property.getName());
                        cell.setCellStyle(boldCellStyle);
                    }
                }
            }
        }
    }
}
Also used : XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) XSSFRow(org.apache.poi.xssf.usermodel.XSSFRow) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) CollectionNode(org.hisp.dhis.node.types.CollectionNode) Node(org.hisp.dhis.node.Node) SimpleNode(org.hisp.dhis.node.types.SimpleNode) ComplexNode(org.hisp.dhis.node.types.ComplexNode) RootNode(org.hisp.dhis.node.types.RootNode) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) XSSFCell(org.apache.poi.xssf.usermodel.XSSFCell)

Example 15 with XSSFCellStyle

use of org.apache.poi.xssf.usermodel.XSSFCellStyle in project bamboobsc by billchen198318.

the class PerspectivesDashboardExcelCommand method putCharts.

@SuppressWarnings("unchecked")
private int putCharts(XSSFWorkbook wb, XSSFSheet sh, Context context) throws Exception {
    String pieBase64Content = SimpleUtils.getPNGBase64Content((String) context.get("pieCanvasToData"));
    String barBase64Content = SimpleUtils.getPNGBase64Content((String) context.get("barCanvasToData"));
    BufferedImage pieImage = SimpleUtils.decodeToImage(pieBase64Content);
    BufferedImage barImage = SimpleUtils.decodeToImage(barBase64Content);
    ByteArrayOutputStream pieBos = new ByteArrayOutputStream();
    ImageIO.write(pieImage, "png", pieBos);
    pieBos.flush();
    ByteArrayOutputStream barBos = new ByteArrayOutputStream();
    ImageIO.write(barImage, "png", barBos);
    barBos.flush();
    SimpleUtils.setCellPicture(wb, sh, pieBos.toByteArray(), 0, 0);
    SimpleUtils.setCellPicture(wb, sh, barBos.toByteArray(), 0, 9);
    int row = 21;
    List<Map<String, Object>> chartDatas = (List<Map<String, Object>>) context.get("chartDatas");
    String year = (String) context.get("year");
    XSSFCellStyle cellHeadStyle = wb.createCellStyle();
    cellHeadStyle.setFillForegroundColor(new XSSFColor(SimpleUtils.getColorRGB4POIColor("#f5f5f5")));
    cellHeadStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
    XSSFFont cellHeadFont = wb.createFont();
    cellHeadFont.setBold(true);
    //cellHeadFont.setColor( new XSSFColor( SimpleUtils.getColorRGB4POIColor( "#000000" ) ) );		
    cellHeadStyle.setFont(cellHeadFont);
    int titleRow = row - 1;
    int titleCellSize = 14;
    Row headRow = sh.createRow(titleRow);
    for (int i = 0; i < titleCellSize; i++) {
        Cell headCell = headRow.createCell(i);
        headCell.setCellStyle(cellHeadStyle);
        headCell.setCellValue("Perspectives metrics gauge ( " + year + " )");
    }
    sh.addMergedRegion(new CellRangeAddress(titleRow, titleRow, 0, titleCellSize - 1));
    int cellLeft = 10;
    int rowSpace = 17;
    for (Map<String, Object> data : chartDatas) {
        Map<String, Object> nodeData = (Map<String, Object>) ((List<Object>) data.get("datas")).get(0);
        String pngImageData = SimpleUtils.getPNGBase64Content((String) nodeData.get("outerHTML"));
        BufferedImage imageData = SimpleUtils.decodeToImage(pngImageData);
        ByteArrayOutputStream imgBos = new ByteArrayOutputStream();
        ImageIO.write(imageData, "png", imgBos);
        imgBos.flush();
        SimpleUtils.setCellPicture(wb, sh, imgBos.toByteArray(), row, 0);
        XSSFColor bgColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor((String) nodeData.get("bgColor")));
        XSSFColor fnColor = new XSSFColor(SimpleUtils.getColorRGB4POIColor((String) nodeData.get("fontColor")));
        XSSFCellStyle cellStyle = wb.createCellStyle();
        cellStyle.setFillForegroundColor(bgColor);
        cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
        XSSFFont cellFont = wb.createFont();
        cellFont.setBold(true);
        cellFont.setColor(fnColor);
        cellStyle.setFont(cellFont);
        int perTitleCellSize = 4;
        Row nowRow = sh.createRow(row);
        for (int i = 0; i < perTitleCellSize; i++) {
            Cell cell1 = nowRow.createCell(cellLeft);
            cell1.setCellStyle(cellStyle);
            cell1.setCellValue((String) nodeData.get("name"));
        }
        sh.addMergedRegion(new CellRangeAddress(row, row, cellLeft, cellLeft + perTitleCellSize - 1));
        nowRow = sh.createRow(row + 1);
        Cell cell2 = nowRow.createCell(cellLeft);
        cell2.setCellValue("Target: " + String.valueOf(nodeData.get("target")));
        nowRow = sh.createRow(row + 2);
        Cell cell3 = nowRow.createCell(cellLeft);
        cell3.setCellValue("Min: " + String.valueOf(nodeData.get("min")));
        nowRow = sh.createRow(row + 3);
        Cell cell4 = nowRow.createCell(cellLeft);
        cell4.setCellValue("Score: " + String.valueOf(nodeData.get("score")));
        row += rowSpace;
    }
    return row;
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage) XSSFColor(org.apache.poi.xssf.usermodel.XSSFColor) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) List(java.util.List) Row(org.apache.poi.ss.usermodel.Row) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Map(java.util.Map) Cell(org.apache.poi.ss.usermodel.Cell)

Aggregations

XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)38 XSSFFont (org.apache.poi.xssf.usermodel.XSSFFont)22 XSSFColor (org.apache.poi.xssf.usermodel.XSSFColor)20 Cell (org.apache.poi.ss.usermodel.Cell)16 Row (org.apache.poi.ss.usermodel.Row)16 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)13 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)12 File (java.io.File)8 XSSFSheet (org.apache.poi.xssf.usermodel.XSSFSheet)8 HashMap (java.util.HashMap)7 XlsxWriterHelper (com.cubrid.common.ui.cubrid.table.control.XlsxWriterHelper)6 FileOutputStream (java.io.FileOutputStream)6 List (java.util.List)6 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)6 KpiVO (com.netsteadfast.greenstep.vo.KpiVO)5 ArrayList (java.util.ArrayList)5 DateRangeScoreVO (com.netsteadfast.greenstep.vo.DateRangeScoreVO)4 ObjectiveVO (com.netsteadfast.greenstep.vo.ObjectiveVO)4 PerspectiveVO (com.netsteadfast.greenstep.vo.PerspectiveVO)4 OutputStreamWriter (java.io.OutputStreamWriter)4