List of usage examples for org.apache.poi.xssf.usermodel XSSFWorkbook getStylesSource
public StylesTable getStylesSource()
From source file:com.miraisolutions.xlconnect.XCellStyle.java
License:Open Source License
public static XCellStyle create(XSSFWorkbook workbook, String name) { int styleXfSize = 0; CTXf xf = CTXf.Factory.newInstance(); xf.setNumFmtId(0);//from w w w . j av a 2 s . c o m xf.setFontId(0); xf.setFillId(0); xf.setBorderId(0); if (name != null) { CTCellStyles ctCellStyles = workbook.getStylesSource().getCTStylesheet().getCellStyles(); if (ctCellStyles == null) { ctCellStyles = workbook.getStylesSource().getCTStylesheet().addNewCellStyles(); ctCellStyles.setCount(0); } if (ctCellStyles.getCount() == 0) { CTCellStyle standardCellStyle = ctCellStyles.addNewCellStyle(); standardCellStyle.setName("Standard"); standardCellStyle.setXfId(0); standardCellStyle.setBuiltinId(0); ctCellStyles.setCount(1); } CTXf styleXf = CTXf.Factory.newInstance(); styleXf.setNumFmtId(0); styleXf.setFontId(0); styleXf.setFillId(0); styleXf.setBorderId(0); styleXfSize = workbook.getStylesSource().putCellStyleXf(styleXf); xf.setXfId(styleXfSize - 1); CTCellStyle ctCellStyle = ctCellStyles.addNewCellStyle(); ctCellStyle.setName(name); ctCellStyle.setXfId(styleXfSize - 1); ctCellStyles.setCount(ctCellStyles.getCount() + 1); } int xfSize = workbook.getStylesSource().putCellXf(xf); return new XCellStyle(workbook, xfSize - 1, styleXfSize - 1); }
From source file:com.miraisolutions.xlconnect.XCellStyle.java
License:Open Source License
/** * Used for querying user-named cell styles (style xf only). * * @param workbook// w w w . java 2 s .c o m * @param name * @return XCellStyle with corresponding (named) style xf */ public static XCellStyle get(XSSFWorkbook workbook, String name) { StylesTable stylesSource = workbook.getStylesSource(); CTCellStyles ctCellStyles = stylesSource.getCTStylesheet().getCellStyles(); if (ctCellStyles != null) { for (int i = 0; i < ctCellStyles.getCount(); i++) { CTCellStyle ctCellStyle = ctCellStyles.getCellStyleArray(i); if (ctCellStyle.getName().equals(name)) { int styleXfId = (int) ctCellStyle.getXfId(); return new XCellStyle(workbook, -1, styleXfId); } } } return null; }
From source file:org.addition.epanet.network.io.input.ExcelParser.java
License:Open Source License
private void findTimeStyle(XSSFWorkbook workbook) { final List<Short> validTimeFormats = Arrays.asList(new Short[] { 0x12, // "h:mm AM/PM" 0x13, // "h:mm:ss AM/PM" 0x14, // "h:mm" 0x15, // "h:mm:ss" 0x16, // "m/d/yy h:mm" 0x2d, // "mm:ss" 0x2e, // "[h]:mm:ss" 0x2f, // "mm:ss.0" });/*www . j a va 2 s . c om*/ StylesTable styleTable = workbook.getStylesSource(); int stylesCount = styleTable.getNumCellStyles(); for (int i = 0; i < stylesCount; i++) { XSSFCellStyle style = styleTable.getStyleAt(i); //if(org.apache.poi.ss.usermodel.DateUtil.isInternalDateFormat(style.getDataFormat())) if (validTimeFormats.contains(style.getDataFormat())) timeStyles.add(style); else if (style.getDataFormatString().toLowerCase().contains("[h]:mm") || style.getDataFormatString().toLowerCase().contains("[hh]:mm")) timeStyles.add(style); } }
From source file:org.tiefaces.components.websheet.utility.ChartUtility.java
License:MIT License
/** * init chart data./*w w w .ja v a 2 s . c om*/ * * @param chartId * chartId. * @param chart * chart. * @param wb * wb. * @return chartdata. */ public static ChartData initChartDataFromXSSFChart(final String chartId, final XSSFChart chart, final XSSFWorkbook wb) { ThemesTable themeTable = wb.getStylesSource().getTheme(); ChartData chartData = new ChartData(); XSSFRichTextString chartTitle = chart.getTitle(); if (chartTitle != null) { chartData.setTitle(chartTitle.toString()); } CTChart ctChart = chart.getCTChart(); ChartType chartType = ChartUtility.getChartType(ctChart); if (chartType == null) { throw new IllegalChartException("Unknown chart type"); } chartData.setBgColor(ColorUtility.getBgColor(ctChart.getPlotArea(), themeTable)); chartData.setId(chartId); chartData.setType(chartType); List<CTCatAx> ctCatAxList = ctChart.getPlotArea().getCatAxList(); if ((ctCatAxList != null) && (!ctCatAxList.isEmpty())) { chartData.setCatAx(new ChartAxis(ctCatAxList.get(0))); } List<CTValAx> ctValAxList = ctChart.getPlotArea().getValAxList(); if ((ctValAxList != null) && (!ctValAxList.isEmpty())) { chartData.setValAx(new ChartAxis(ctValAxList.get(0))); } ChartObject ctObj = chartType.createChartObject(); if (ctObj == null) { throw new IllegalChartException("Cannot create chart object."); } setUpChartData(chartData, ctChart, themeTable, ctObj); return chartData; }