List of usage examples for org.apache.poi.xssf.usermodel XSSFRichTextString XSSFRichTextString
@Internal
public XSSFRichTextString(CTRst st)
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
protected void exportCells(DataList list, Sheet sheet) { int sheetRowIndex = sheet.getLastRowNum() + 1; Row row = sheet.createRow(sheetRowIndex); for (UIComponent component : list.getChildren()) { if (component instanceof Column) { UIColumn column = (UIColumn) component; for (UIComponent childComponent : column.getChildren()) { int cellIndex = row.getLastCellNum() == -1 ? 0 : row.getLastCellNum(); Cell cell = row.createCell(cellIndex); if (component.isRendered()) { String value = component == null ? "" : exportValue(FacesContext.getCurrentInstance(), childComponent); cell.setCellValue(new XSSFRichTextString(value)); cell.setCellStyle(cellStyle); }//from w w w. j a v a 2 s . c om } } else { int cellIndex = row.getLastCellNum() == -1 ? 0 : row.getLastCellNum(); Cell cell = row.createCell(cellIndex); if (component.isRendered()) { String value = component == null ? "" : exportValue(FacesContext.getCurrentInstance(), component); cell.setCellValue(new XSSFRichTextString(value)); cell.setCellStyle(cellStyle); } } } }
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
protected void addColumnFacets(DataTable table, Sheet sheet, ColumnType columnType) { int sheetRowIndex = sheet.getLastRowNum() + 1; Row rowHeader = sheet.createRow(sheetRowIndex); for (UIColumn col : table.getColumns()) { if (!col.isRendered()) { continue; }/*from w w w . j av a2 s . c om*/ if (col instanceof DynamicColumn) { ((DynamicColumn) col).applyModel(); } if (col.isExportable()) { //Adding RowIndex for custom Export UIComponent component = (UIComponent) col; if (component.getId().equalsIgnoreCase("subject")) { Cell cell = rowHeader.createCell(0); String value = "Index"; cell.setCellValue(new XSSFRichTextString(value)); } //Adding RowIndex for custom Export addColumnValue(rowHeader, col.getFacet(columnType.facet()), "facet"); } } }
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
protected void addColumnValue(Row row, UIComponent component, String type) { int cellIndex = row.getLastCellNum() == -1 ? 0 : row.getLastCellNum(); Cell cell = row.createCell(cellIndex); String value = component == null ? "" : exportValue(FacesContext.getCurrentInstance(), component); cell.setCellValue(new XSSFRichTextString(value)); if (type.equalsIgnoreCase("facet")) { // addColumnAlignments(component,facetStyle); cell.setCellStyle(facetStyle);//from ww w. j av a 2s.c om } else { CellStyle cellStyle = this.cellStyle; cellStyle = addColumnAlignments(component, cellStyle); cell.setCellStyle(cellStyle); } }
From source file:com.crm.webapp.util.ExcelCustomExporter.java
License:Apache License
protected void addColumnValue(Row row, List<UIComponent> components, String type) { int cellIndex = row.getLastCellNum() == -1 ? 0 : row.getLastCellNum(); Cell cell = row.createCell(cellIndex); StringBuilder builder = new StringBuilder(); FacesContext context = FacesContext.getCurrentInstance(); for (UIComponent component : components) { if (component.isRendered()) { String value = exportValue(context, component); if (value != null) { builder.append(value);/*from www . j av a 2 s . c o m*/ } } } cell.setCellValue(new XSSFRichTextString(builder.toString())); if (type.equalsIgnoreCase("facet")) { //addColumnAlignments(components,facetStyle); cell.setCellStyle(facetStyle); } else { CellStyle cellStyle = this.cellStyle; for (UIComponent component : components) { cellStyle = addColumnAlignments(component, cellStyle); cell.setCellStyle(cellStyle); } } }
From source file:com.dhenton9000.excel.ExcelParser.java
@Override public void endElement(String uri, String localName, String name) throws SAXException { String currentVal = ""; //end of row//from www. jav a 2 s . c om if ("row".equals(name)) { insideRow = false; //if rowIndex is 0, then its the header row so validate if (rowIndex == 0) { LOG.debug("end for header index: {}", headerIndexMap); } //if rowIndex > 0 and rowValueMap has data, then add data to the mediaFilter list else if (!rowValueMap.isEmpty()) { LOG.debug("end for row index: {}", rowValueMap); HashMap<String, Object> tMap = new HashMap<String, Object>(); for (String k : rowValueMap.keySet()) { tMap.put(k, rowValueMap.get(k)); } accumulatedRows.add(tMap); } } //inside row if (insideRow) { //next element is a cell value so process if ("v".equals(name) && (nextIsString || nextIsNumber)) { int idx = Integer.valueOf(cellContents.toString()); if (nextIsString) { currentVal = new XSSFRichTextString(sst.getEntryAt(idx)).toString(); } else { currentVal = String.valueOf(idx); } //header row so update header maps if (rowIndex == 0) { headerIndexMap.put(currentVal, colIndex); indexHeaderMap.put(colIndex, currentVal); } //update row maps else { rowValueMap.put(indexHeaderMap.get(colIndex), currentVal); } nextIsString = false; nextIsNumber = false; } } // LOG.debug(String.format("end row %d col %d name %s", rowIndex,colIndex, name)); }
From source file:com.github.wnameless.workbookaccessor.WorkbookWriterTest.java
License:Apache License
@Test public void testAddRow() { Calendar cal = Calendar.getInstance(); Date date = new Date(); writer.addRow("def"); writer.addRow(null, true, cal, date, 1.1, new HSSFRichTextString("Hello!"), new XSSFRichTextString("World."), new HSSFWorkbook().getCreationHelper().createHyperlink(Hyperlink.LINK_URL), 123, "abc"); assertEquals("def", writer.getWorkbook().getSheetAt(0).rowIterator().next().cellIterator().next().getStringCellValue()); WorkbookWriter.openXLSX().addRow(new HSSFRichTextString("Hello!"), new XSSFRichTextString("World.")); WorkbookWriter.openXLS().addRow(new HSSFRichTextString("Hello!"), new XSSFRichTextString("World.")); }
From source file:com.globalsight.everest.qachecks.DITAQAChecker.java
License:Apache License
private RichTextString getRichTextString(Workbook p_workBook, String segment, List<String> highlightIndexes) { RichTextString ts = new XSSFRichTextString(segment); ts.applyFont(getNormalFont(p_workBook)); for (String red : highlightIndexes) { String[] arr = red.split("-"); int indexStart = Integer.parseInt(arr[0]); int indexEnd = Integer.parseInt(arr[1]); ts.applyFont(indexStart, indexEnd, getRedFont(p_workBook)); }//from ww w. j a v a 2s. co m return ts; }
From source file:com.heimaide.server.common.utils.excel.ExportExcel.java
License:Open Source License
private void initialize(String title, List<String> headerList) { this.wb = new SXSSFWorkbook(500); this.sheet = wb.createSheet("Export"); this.styles = createStyles(wb); // Create title if (StringUtils.isNotBlank(title)) { Row titleRow = sheet.createRow(rownum++); titleRow.setHeightInPoints(30);/*from w ww . j a v a 2 s. co m*/ Cell titleCell = titleRow.createCell(0); titleCell.setCellStyle(styles.get("title")); titleCell.setCellValue(title); sheet.addMergedRegion(new CellRangeAddress(titleRow.getRowNum(), titleRow.getRowNum(), titleRow.getRowNum(), headerList.size() - 1)); } // Create header if (headerList == null) { throw new RuntimeException("headerList not null!"); } Row headerRow = sheet.createRow(rownum++); headerRow.setHeightInPoints(16); for (int i = 0; i < headerList.size(); i++) { Cell cell = headerRow.createCell(i); cell.setCellStyle(styles.get("header")); String[] ss = StringUtils.split(headerList.get(i), "**", 2); if (ss.length == 2) { cell.setCellValue(ss[0]); Comment comment = this.sheet.createDrawingPatriarch() .createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 3, (short) 5, 6)); comment.setString(new XSSFRichTextString(ss[1])); cell.setCellComment(comment); } else { cell.setCellValue(headerList.get(i)); } sheet.autoSizeColumn(i); } for (int i = 0; i < headerList.size(); i++) { int colWidth = sheet.getColumnWidth(i) * 2; sheet.setColumnWidth(i, colWidth < 3000 ? 3000 : colWidth); } log.debug("Initialize success."); }
From source file:com.linus.excel.poi.MergingCells.java
License:Apache License
public static void main(String[] args) throws Exception { Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook(); Sheet sheet = wb.createSheet("new sheet"); Row row = sheet.createRow((short) 1); Cell cell = row.createCell((short) 1); cell.setCellValue(new XSSFRichTextString("This is a test of merging")); sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 2)); // Write the output to a file FileOutputStream fileOut = new FileOutputStream("excel/merging_cells.xlsx"); wb.write(fileOut);//from w w w. j a v a2 s . c o m fileOut.close(); }
From source file:com.myjeeva.poi.CustomXSSFSheetXMLHandler.java
License:Apache License
/** * Mtodo alterado de forma a produzir, alm dos valores formatados para apresentao ao usurio final, os valores * originais sem qualquer tipo de formatao e nos tipos STRING ou NUMERICOS * Obs: Nmeros podem ser, na verdade, datas, ficando a cargo do cliente da classe definir como considera-lo. *///from w w w .j ava 2s.com public void endElement(String uri, String localName, String name) throws SAXException { String thisStr = null; // v => contents of a cell if (isTextTag(name)) { vIsOpen = false; // Process the value contents as required, now we have it all switch (nextDataType) { case BOOLEAN: char first = value.charAt(0); thisStr = first == '0' ? "FALSE" : "TRUE"; break; case ERROR: thisStr = "ERROR:" + value.toString(); break; case FORMULA: if (formulasNotResults) { thisStr = formula.toString(); } else { String fv = value.toString(); if (this.formatString != null) { try { // Try to use the value as a formattable number double d = Double.parseDouble(fv); thisStr = formatter.formatRawCellContents(d, this.formatIndex, this.formatString); } catch (NumberFormatException e) { // Formula is a String result not a Numeric one thisStr = fv; } } else { // No formating applied, just do raw value in all cases thisStr = fv; } } break; case INLINE_STRING: // TODO: Can these ever have formatting on them? XSSFRichTextString rtsi = new XSSFRichTextString(value.toString()); thisStr = rtsi.toString(); break; case SST_STRING: String sstIndex = value.toString(); try { int idx = Integer.parseInt(sstIndex); XSSFRichTextString rtss = new XSSFRichTextString(sharedStringsTable.getEntryAt(idx)); thisStr = rtss.toString(); } catch (NumberFormatException ex) { System.err.println("Failed to parse SST index '" + sstIndex + "': " + ex.toString()); } break; case NUMBER: String n = value.toString(); if (this.formatString != null) thisStr = formatter.formatRawCellContents(Double.parseDouble(n), this.formatIndex, this.formatString); else thisStr = n; break; default: thisStr = "(TODO: Unexpected type: " + nextDataType + ")"; break; } // Modificada para armazenar tambm as informaes: valor original e tipo do contedo, e formato de apresentacao do excel output.cell(cellRef, thisStr, value.toString(), this.formatString, nextDataType); } else if ("f".equals(name)) { fIsOpen = false; } else if ("is".equals(name)) { isIsOpen = false; } else if ("row".equals(name)) { output.endRow(); } else if ("oddHeader".equals(name) || "evenHeader".equals(name) || "firstHeader".equals(name)) { hfIsOpen = false; output.headerFooter(headerFooter.toString(), true, name); } else if ("oddFooter".equals(name) || "evenFooter".equals(name) || "firstFooter".equals(name)) { hfIsOpen = false; output.headerFooter(headerFooter.toString(), false, name); } }