use of org.apache.poi.ss.usermodel.CellStyle in project poi by apache.
the class TestXSSFWorkbook method getCellStyleAt.
@Test
public void getCellStyleAt() throws IOException {
XSSFWorkbook workbook = new XSSFWorkbook();
try {
short i = 0;
//get default style
CellStyle cellStyleAt = workbook.getCellStyleAt(i);
assertNotNull(cellStyleAt);
//get custom style
StylesTable styleSource = workbook.getStylesSource();
XSSFCellStyle customStyle = new XSSFCellStyle(styleSource);
XSSFFont font = new XSSFFont();
font.setFontName("Verdana");
customStyle.setFont(font);
int x = styleSource.putStyle(customStyle);
cellStyleAt = workbook.getCellStyleAt((short) x);
assertNotNull(cellStyleAt);
} finally {
workbook.close();
}
}
use of org.apache.poi.ss.usermodel.CellStyle in project Gargoyle by callakrsos.
the class IExcelDataSetHandler method createCell.
/**
* 셀 생성
*
* @작성자 : KYJ
* @작성일 : 2016. 9. 6.
* @param sheet
* @param value
* @param row
* @param column
* @return
* @throws Exception
*/
public default default Cell createCell(Sheet sheet, Object value, int row, int column) throws Exception {
Row row2 = sheet.getRow(row);
if (row2 == null) {
row2 = sheet.createRow(row);
}
Cell createCell = null;
try {
createCell = row2.getCell(column);
if (createCell == null) {
createCell = row2.createCell(column);
}
} catch (NullPointerException e) {
createCell = row2.createCell(column);
}
if (value instanceof String) {
createCell.setCellValue((String) value);
} else if (value instanceof Integer) {
createCell.setCellValue((Integer) value);
} else if (value instanceof Double) {
createCell.setCellValue((Double) value);
} else if (value instanceof Float) {
createCell.setCellValue((Float) value);
} else if (value == null) {
createCell.setCellValue("");
} else if (value instanceof Date) {
createCell.setCellValue((Date) value);
} else /*그 이외 특이 사항은 구현. else if로 구현할것.*/
{
createCell.setCellValue(value.toString());
}
/*
* Border 처리시 속도 저하의 원인...
*
*/
Callback<CellStyle, CellStyle> cellStyleFactory = dataCellStyleFactory();
if (cellStyleFactory != null) {
CellStyle call = cellStyleFactory.call(sheet.getWorkbook().createCellStyle());
if (call != null)
createCell.setCellStyle(call);
}
return createCell;
}
use of org.apache.poi.ss.usermodel.CellStyle in project ddf by codice.
the class RrdMetricsRetriever method createSheet.
/**
* Creates an Excel worksheet containing the metric's data (timestamps and values) for the
* specified time range. This worksheet is titled with the trhe metric's name and added to the
* specified Workbook.
*
* @param wb the workbook to add this worksheet to
* @param metricName the name of the metric whose data is being rendered in this worksheet
* @param rrdFilename the name of the RRD file to retrieve the metric's data from
* @param startTime start time, in seconds since Unix epoch, to fetch metric's data
* @param endTime end time, in seconds since Unix epoch, to fetch metric's data
* @throws IOException
* @throws MetricsGraphException
*/
private void createSheet(Workbook wb, String metricName, String rrdFilename, long startTime, long endTime) throws IOException, MetricsGraphException {
LOGGER.trace("ENTERING: createSheet");
MetricData metricData = getMetricData(rrdFilename, startTime, endTime);
String displayableMetricName = convertCamelCase(metricName);
String title = displayableMetricName + " for " + getCalendarTime(startTime) + " to " + getCalendarTime(endTime);
Sheet sheet = wb.createSheet(displayableMetricName);
Font headerFont = wb.createFont();
headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
CellStyle columnHeadingsStyle = wb.createCellStyle();
columnHeadingsStyle.setFont(headerFont);
CellStyle bannerStyle = wb.createCellStyle();
bannerStyle.setFont(headerFont);
bannerStyle.setFillForegroundColor(HSSFColor.PALE_BLUE.index);
bannerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
int rowCount = 0;
Row row = sheet.createRow((short) rowCount);
Cell cell = row.createCell(0);
cell.setCellValue(title);
cell.setCellStyle(bannerStyle);
rowCount++;
// Blank row for spacing/readability
row = sheet.createRow((short) rowCount);
cell = row.createCell(0);
cell.setCellValue("");
rowCount++;
row = sheet.createRow((short) rowCount);
cell = row.createCell(0);
cell.setCellValue("Timestamp");
cell.setCellStyle(columnHeadingsStyle);
cell = row.createCell(1);
cell.setCellValue("Value");
cell.setCellStyle(columnHeadingsStyle);
rowCount++;
List<Long> timestamps = metricData.getTimestamps();
List<Double> values = metricData.getValues();
for (int i = 0; i < timestamps.size(); i++) {
String timestamp = getCalendarTime(timestamps.get(i));
row = sheet.createRow((short) rowCount);
row.createCell(0).setCellValue(timestamp);
row.createCell(1).setCellValue(values.get(i));
rowCount++;
}
if (metricData.hasTotalCount()) {
// Blank row for spacing/readability
row = sheet.createRow((short) rowCount);
cell = row.createCell(0);
cell.setCellValue("");
rowCount++;
row = sheet.createRow((short) rowCount);
cell = row.createCell(0);
cell.setCellValue("Total Count: ");
cell.setCellStyle(columnHeadingsStyle);
row.createCell(1).setCellValue(metricData.getTotalCount());
}
sheet.autoSizeColumn(0);
sheet.autoSizeColumn(1);
LOGGER.trace("EXITING: createSheet");
}
Aggregations