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;
}
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;
}
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);
}
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);
}
}
}
}
}
}
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;
}
Aggregations