Search in sources :

Example 1 with XSSFFont

use of org.apache.poi.xssf.usermodel.XSSFFont 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 2 with XSSFFont

use of org.apache.poi.xssf.usermodel.XSSFFont in project poi by apache.

the class StylesTable method initialize.

private void initialize() {
    //CTFont ctFont = createDefaultFont();
    XSSFFont xssfFont = createDefaultFont();
    fonts.add(xssfFont);
    CTFill[] ctFill = createDefaultFills();
    fills.add(new XSSFCellFill(ctFill[0], indexedColors));
    fills.add(new XSSFCellFill(ctFill[1], indexedColors));
    CTBorder ctBorder = createDefaultBorder();
    borders.add(new XSSFCellBorder(ctBorder));
    CTXf styleXf = createDefaultXf();
    styleXfs.add(styleXf);
    CTXf xf = createDefaultXf();
    xf.setXfId(0);
    xfs.add(xf);
}
Also used : XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) XSSFCellFill(org.apache.poi.xssf.usermodel.extensions.XSSFCellFill) XSSFCellBorder(org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder)

Example 3 with XSSFFont

use of org.apache.poi.xssf.usermodel.XSSFFont in project poi by apache.

the class StylesTable method writeTo.

/**
     * Write this table out as XML.
     *
     * @param out The stream to write to.
     * @throws IOException if an error occurs while writing.
     */
public void writeTo(OutputStream out) throws IOException {
    // Work on the current one
    // Need to do this, as we don't handle
    //  all the possible entries yet
    CTStylesheet styleSheet = doc.getStyleSheet();
    // Formats
    CTNumFmts formats = CTNumFmts.Factory.newInstance();
    formats.setCount(numberFormats.size());
    for (final Entry<Short, String> entry : numberFormats.entrySet()) {
        CTNumFmt ctFmt = formats.addNewNumFmt();
        ctFmt.setNumFmtId(entry.getKey());
        ctFmt.setFormatCode(entry.getValue());
    }
    styleSheet.setNumFmts(formats);
    int idx;
    // Fonts
    CTFonts ctFonts = styleSheet.getFonts();
    if (ctFonts == null) {
        ctFonts = CTFonts.Factory.newInstance();
    }
    ctFonts.setCount(fonts.size());
    CTFont[] ctfnt = new CTFont[fonts.size()];
    idx = 0;
    for (XSSFFont f : fonts) ctfnt[idx++] = f.getCTFont();
    ctFonts.setFontArray(ctfnt);
    styleSheet.setFonts(ctFonts);
    // Fills
    CTFills ctFills = styleSheet.getFills();
    if (ctFills == null) {
        ctFills = CTFills.Factory.newInstance();
    }
    ctFills.setCount(fills.size());
    CTFill[] ctf = new CTFill[fills.size()];
    idx = 0;
    for (XSSFCellFill f : fills) ctf[idx++] = f.getCTFill();
    ctFills.setFillArray(ctf);
    styleSheet.setFills(ctFills);
    // Borders
    CTBorders ctBorders = styleSheet.getBorders();
    if (ctBorders == null) {
        ctBorders = CTBorders.Factory.newInstance();
    }
    ctBorders.setCount(borders.size());
    CTBorder[] ctb = new CTBorder[borders.size()];
    idx = 0;
    for (XSSFCellBorder b : borders) ctb[idx++] = b.getCTBorder();
    ctBorders.setBorderArray(ctb);
    styleSheet.setBorders(ctBorders);
    // Xfs
    if (xfs.size() > 0) {
        CTCellXfs ctXfs = styleSheet.getCellXfs();
        if (ctXfs == null) {
            ctXfs = CTCellXfs.Factory.newInstance();
        }
        ctXfs.setCount(xfs.size());
        ctXfs.setXfArray(xfs.toArray(new CTXf[xfs.size()]));
        styleSheet.setCellXfs(ctXfs);
    }
    // Style xfs
    if (styleXfs.size() > 0) {
        CTCellStyleXfs ctSXfs = styleSheet.getCellStyleXfs();
        if (ctSXfs == null) {
            ctSXfs = CTCellStyleXfs.Factory.newInstance();
        }
        ctSXfs.setCount(styleXfs.size());
        ctSXfs.setXfArray(styleXfs.toArray(new CTXf[styleXfs.size()]));
        styleSheet.setCellStyleXfs(ctSXfs);
    }
    // Style dxfs
    if (dxfs.size() > 0) {
        CTDxfs ctDxfs = styleSheet.getDxfs();
        if (ctDxfs == null) {
            ctDxfs = CTDxfs.Factory.newInstance();
        }
        ctDxfs.setCount(dxfs.size());
        ctDxfs.setDxfArray(dxfs.toArray(new CTDxf[dxfs.size()]));
        styleSheet.setDxfs(ctDxfs);
    }
    // Save
    doc.save(out, DEFAULT_XML_OPTIONS);
}
Also used : XSSFCellFill(org.apache.poi.xssf.usermodel.extensions.XSSFCellFill) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) XSSFCellBorder(org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder)

Example 4 with XSSFFont

use of org.apache.poi.xssf.usermodel.XSSFFont in project poi by apache.

the class StylesTable method readFrom.

/**
     * Read this shared styles table from an XML file.
     *
     * @param is The input stream containing the XML document.
     * @throws IOException if an error occurs while reading.
     */
public void readFrom(InputStream is) throws IOException {
    try {
        doc = StyleSheetDocument.Factory.parse(is, DEFAULT_XML_OPTIONS);
        CTStylesheet styleSheet = doc.getStyleSheet();
        // Grab all the different bits we care about
        // keep this first, as some constructors below want it
        IndexedColorMap customColors = CustomIndexedColorMap.fromColors(styleSheet.getColors());
        if (customColors != null)
            indexedColors = customColors;
        CTNumFmts ctfmts = styleSheet.getNumFmts();
        if (ctfmts != null) {
            for (CTNumFmt nfmt : ctfmts.getNumFmtArray()) {
                short formatId = (short) nfmt.getNumFmtId();
                numberFormats.put(formatId, nfmt.getFormatCode());
            }
        }
        CTFonts ctfonts = styleSheet.getFonts();
        if (ctfonts != null) {
            int idx = 0;
            for (CTFont font : ctfonts.getFontArray()) {
                // Create the font and save it. Themes Table supplied later
                XSSFFont f = new XSSFFont(font, idx, indexedColors);
                fonts.add(f);
                idx++;
            }
        }
        CTFills ctfills = styleSheet.getFills();
        if (ctfills != null) {
            for (CTFill fill : ctfills.getFillArray()) {
                fills.add(new XSSFCellFill(fill, indexedColors));
            }
        }
        CTBorders ctborders = styleSheet.getBorders();
        if (ctborders != null) {
            for (CTBorder border : ctborders.getBorderArray()) {
                borders.add(new XSSFCellBorder(border, indexedColors));
            }
        }
        CTCellXfs cellXfs = styleSheet.getCellXfs();
        if (cellXfs != null)
            xfs.addAll(Arrays.asList(cellXfs.getXfArray()));
        CTCellStyleXfs cellStyleXfs = styleSheet.getCellStyleXfs();
        if (cellStyleXfs != null)
            styleXfs.addAll(Arrays.asList(cellStyleXfs.getXfArray()));
        CTDxfs styleDxfs = styleSheet.getDxfs();
        if (styleDxfs != null)
            dxfs.addAll(Arrays.asList(styleDxfs.getDxfArray()));
        CTTableStyles ctTableStyles = styleSheet.getTableStyles();
        if (ctTableStyles != null) {
            int idx = 0;
            for (CTTableStyle style : Arrays.asList(ctTableStyles.getTableStyleArray())) {
                tableStyles.put(style.getName(), new XSSFTableStyle(idx, styleDxfs, style, indexedColors));
                idx++;
            }
        }
    } catch (XmlException e) {
        throw new IOException(e.getLocalizedMessage());
    }
}
Also used : DefaultIndexedColorMap(org.apache.poi.xssf.usermodel.DefaultIndexedColorMap) IndexedColorMap(org.apache.poi.xssf.usermodel.IndexedColorMap) CustomIndexedColorMap(org.apache.poi.xssf.usermodel.CustomIndexedColorMap) XSSFTableStyle(org.apache.poi.xssf.usermodel.XSSFTableStyle) IOException(java.io.IOException) XSSFCellFill(org.apache.poi.xssf.usermodel.extensions.XSSFCellFill) XmlException(org.apache.xmlbeans.XmlException) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) XSSFCellBorder(org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder)

Example 5 with XSSFFont

use of org.apache.poi.xssf.usermodel.XSSFFont in project poi by apache.

the class StylesTable method createDefaultFont.

private static XSSFFont createDefaultFont() {
    CTFont ctFont = CTFont.Factory.newInstance();
    XSSFFont xssfFont = new XSSFFont(ctFont, 0, null);
    xssfFont.setFontHeightInPoints(XSSFFont.DEFAULT_FONT_SIZE);
    //setTheme
    xssfFont.setColor(XSSFFont.DEFAULT_FONT_COLOR);
    xssfFont.setFontName(XSSFFont.DEFAULT_FONT_NAME);
    xssfFont.setFamily(FontFamily.SWISS);
    xssfFont.setScheme(FontScheme.MINOR);
    return xssfFont;
}
Also used : XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont)

Aggregations

XSSFFont (org.apache.poi.xssf.usermodel.XSSFFont)27 XSSFCellStyle (org.apache.poi.xssf.usermodel.XSSFCellStyle)22 Cell (org.apache.poi.ss.usermodel.Cell)17 Row (org.apache.poi.ss.usermodel.Row)17 XSSFColor (org.apache.poi.xssf.usermodel.XSSFColor)17 CellRangeAddress (org.apache.poi.ss.util.CellRangeAddress)13 List (java.util.List)6 KpiVO (com.netsteadfast.greenstep.vo.KpiVO)5 DateRangeScoreVO (com.netsteadfast.greenstep.vo.DateRangeScoreVO)4 ObjectiveVO (com.netsteadfast.greenstep.vo.ObjectiveVO)4 PerspectiveVO (com.netsteadfast.greenstep.vo.PerspectiveVO)4 Map (java.util.Map)4 XSSFWorkbook (org.apache.poi.xssf.usermodel.XSSFWorkbook)4 BufferedImage (java.awt.image.BufferedImage)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 HashMap (java.util.HashMap)3 XSSFCell (org.apache.poi.xssf.usermodel.XSSFCell)3 XSSFRow (org.apache.poi.xssf.usermodel.XSSFRow)3 XSSFCellBorder (org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder)3 XSSFCellFill (org.apache.poi.xssf.usermodel.extensions.XSSFCellFill)3