List of usage examples for org.apache.poi.xssf.usermodel XSSFRichTextString XSSFRichTextString
@Internal
public XSSFRichTextString(CTRst st)
From source file:com.qihang.winter.poi.excel.export.base.ExcelExportBase.java
License:Apache License
/** * Cell/*ww w .j ava 2 s. co m*/ * * @param row * @param index * @param text * @param style * @param entity */ public void createStringCell(Row row, int index, String text, CellStyle style, com.qihang.winter.poi.excel.entity.params.ExcelExportEntity entity) { Cell cell = row.createCell(index); if (style != null && style.getDataFormat() > 0 && style.getDataFormat() < 12) { cell.setCellValue(Double.parseDouble(text)); cell.setCellType(Cell.CELL_TYPE_NUMERIC); } else { RichTextString Rtext; if (type.equals(com.qihang.winter.poi.excel.entity.enmus.ExcelType.HSSF)) { Rtext = new HSSFRichTextString(text); } else { Rtext = new XSSFRichTextString(text); } cell.setCellValue(Rtext); } if (style != null) { cell.setCellStyle(style); } addStatisticsData(index, text, entity); }
From source file:com.qihang.winter.poi.excel.imports.sax.SheetHandler.java
License:Apache License
@Override public void endElement(String uri, String localName, String name) throws SAXException { // ?SST?? //from ww w . ja va 2s . c om // characters()? if (com.qihang.winter.poi.excel.entity.enmus.CellValueType.String.equals(type)) { try { int idx = Integer.parseInt(lastContents); lastContents = new XSSFRichTextString(sst.getEntryAt(idx)).toString(); } catch (Exception e) { } } //t? if (com.qihang.winter.poi.excel.entity.enmus.CellValueType.TElement.equals(type)) { String value = lastContents.trim(); rowlist.add(curCol, new SaxReadCellEntity(com.qihang.winter.poi.excel.entity.enmus.CellValueType.String, value)); curCol++; type = com.qihang.winter.poi.excel.entity.enmus.CellValueType.None; // v => ??vSST // ?rowlist??? } else if ("v".equals(name)) { String value = lastContents.trim(); value = value.equals("") ? " " : value; if (com.qihang.winter.poi.excel.entity.enmus.CellValueType.Date.equals(type)) { Date date = HSSFDateUtil.getJavaDate(Double.valueOf(value)); rowlist.add(curCol, new SaxReadCellEntity(com.qihang.winter.poi.excel.entity.enmus.CellValueType.Date, date)); } else if (com.qihang.winter.poi.excel.entity.enmus.CellValueType.Number.equals(type)) { BigDecimal bd = new BigDecimal(value); rowlist.add(curCol, new SaxReadCellEntity(com.qihang.winter.poi.excel.entity.enmus.CellValueType.Number, bd)); } else if (com.qihang.winter.poi.excel.entity.enmus.CellValueType.String.equals(type)) { rowlist.add(curCol, new SaxReadCellEntity( com.qihang.winter.poi.excel.entity.enmus.CellValueType.String, value)); } curCol++; } else if (name.equals("row")) {//?? row optRows() read.parse(curRow, rowlist); rowlist.clear(); curRow++; curCol = 0; } }
From source file:com.sec.ose.osi.report.standard.CoverSheetTemplate.java
License:Open Source License
public void writeCoverSheet(String projectName, String creatorName, String creatorEmail, String organizationName, String toolInfo) { sheet.getRow(ROW_10).getCell(COL_D).setCellValue(new XSSFRichTextString(projectName)); sheet.getRow(ROW_10).getCell(COL_F)/* www . j a v a 2 s . c o m*/ .setCellValue(new XSSFRichTextString(DateUtil.getCurrentTime("%1$tY-%1$tm-%1$te (%1$ta)"))); sheet.getRow(ROW_11).getCell(COL_D).setCellValue(new XSSFRichTextString(creatorEmail)); sheet.getRow(ROW_12).getCell(COL_D).setCellValue(new XSSFRichTextString(organizationName)); sheet.getRow(ROW_13).getCell(COL_D).setCellValue(new XSSFRichTextString(toolInfo)); }
From source file:com.teradata.demo.utils.excel.XSSFSheetXMLHandler.java
License:Apache License
public void endElement(String uri, String localName, String name) throws SAXException { String thisStr = null;//from w w w .jav a2 s .c om // 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) { if (this.formatString.equals("m/d/yy")) this.formatString = "yyyy-MM-dd"; thisStr = formatter.formatRawCellContents(Double.parseDouble(n), this.formatIndex, this.formatString); } else thisStr = n; break; default: thisStr = "(TODO: Unexpected type: " + nextDataType + ")"; break; } // Output output.cell(cellRef, thisStr); } 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); } }
From source file:com.tremolosecurity.scale.ui.reports.GenerateSpreadsheet.java
License:Apache License
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate"); resp.setHeader("Pragma", "no-cache"); ReportViewer scaleReport = (ReportViewer) req.getSession().getAttribute("scaleReportCached"); Workbook wb = new XSSFWorkbook(); Font font = wb.createFont();// w w w. j a va 2s .c o m font.setBold(true); Font titleFont = wb.createFont(); titleFont.setBold(true); titleFont.setFontHeightInPoints((short) 16); Sheet sheet = wb.createSheet(WorkbookUtil.createSafeSheetName(scaleReport.getReportInfo().getName())); //Create a header Row row = sheet.createRow(0); Cell cell = row.createCell(0); RichTextString title = new XSSFRichTextString(scaleReport.getReportInfo().getName()); title.applyFont(titleFont); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3)); cell.setCellValue(title); row = sheet.createRow(1); cell = row.createCell(0); cell.setCellValue(scaleReport.getReportInfo().getDescription()); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 3)); row = sheet.createRow(2); cell = row.createCell(0); cell.setCellValue(scaleReport.getRunDateTime()); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 3)); row = sheet.createRow(3); int rowNum = 4; if (scaleReport.getResults().getGrouping().isEmpty()) { row = sheet.createRow(rowNum); cell = row.createCell(0); cell.setCellValue("There is no data for this report"); } else { for (ReportGrouping group : scaleReport.getResults().getGrouping()) { for (String colHeader : scaleReport.getResults().getHeaderFields()) { row = sheet.createRow(rowNum); cell = row.createCell(0); RichTextString rcolHeader = new XSSFRichTextString(colHeader); rcolHeader.applyFont(font); cell.setCellValue(rcolHeader); cell = row.createCell(1); cell.setCellValue(group.getHeader().get(colHeader)); rowNum++; } row = sheet.createRow(rowNum); int cellNum = 0; for (String colHeader : scaleReport.getResults().getDataFields()) { cell = row.createCell(cellNum); RichTextString rcolHeader = new XSSFRichTextString(colHeader); rcolHeader.applyFont(font); cell.setCellValue(rcolHeader); cellNum++; } rowNum++; for (Map<String, String> dataRow : group.getData()) { cellNum = 0; row = sheet.createRow(rowNum); for (String colHeader : scaleReport.getResults().getDataFields()) { cell = row.createCell(cellNum); cell.setCellValue(dataRow.get(colHeader)); cellNum++; } rowNum++; } row = sheet.createRow(rowNum); rowNum++; } } resp.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); wb.write(resp.getOutputStream()); }
From source file:com.tremolosecurity.scalejs.ws.ScaleMain.java
License:Apache License
private void exportToExcel(HttpFilterRequest request, HttpFilterResponse response, Gson gson) throws IOException { int lastslash = request.getRequestURI().lastIndexOf('/'); int secondlastslash = request.getRequestURI().lastIndexOf('/', lastslash - 1); String id = request.getRequestURI().substring(secondlastslash + 1, lastslash); ReportResults res = (ReportResults) request.getSession().getAttribute(id); if (res == null) { response.setStatus(404);// w ww . j av a 2s .c o m ScaleError error = new ScaleError(); error.getErrors().add("Report no longer available"); ScaleJSUtils.addCacheHeaders(response); response.getWriter().print(gson.toJson(error).trim()); response.getWriter().flush(); } else { response.setHeader("Cache-Control", "private, no-store, no-cache, must-revalidate"); response.setHeader("Pragma", "no-cache"); Workbook wb = new XSSFWorkbook(); Font font = wb.createFont(); font.setBold(true); Font titleFont = wb.createFont(); titleFont.setBold(true); titleFont.setFontHeightInPoints((short) 16); Sheet sheet = wb.createSheet(WorkbookUtil.createSafeSheetName(res.getName())); //Create a header Row row = sheet.createRow(0); Cell cell = row.createCell(0); RichTextString title = new XSSFRichTextString(res.getName()); title.applyFont(titleFont); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 3)); cell.setCellValue(title); row = sheet.createRow(1); cell = row.createCell(0); cell.setCellValue(res.getDescription()); sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 3)); row = sheet.createRow(2); cell = row.createCell(0); //cell.setCellValue(new DateTime().toString("MMMM Do, YYYY h:mm:ss a")); sheet.addMergedRegion(new CellRangeAddress(2, 2, 0, 3)); row = sheet.createRow(3); int rowNum = 4; if (res.getGrouping().isEmpty()) { row = sheet.createRow(rowNum); cell = row.createCell(0); cell.setCellValue("There is no data for this report"); } else { for (ReportGrouping group : res.getGrouping()) { for (String colHeader : res.getHeaderFields()) { row = sheet.createRow(rowNum); cell = row.createCell(0); RichTextString rcolHeader = new XSSFRichTextString(colHeader); rcolHeader.applyFont(font); cell.setCellValue(rcolHeader); cell = row.createCell(1); cell.setCellValue(group.getHeader().get(colHeader)); rowNum++; } row = sheet.createRow(rowNum); int cellNum = 0; for (String colHeader : res.getDataFields()) { cell = row.createCell(cellNum); RichTextString rcolHeader = new XSSFRichTextString(colHeader); rcolHeader.applyFont(font); cell.setCellValue(rcolHeader); cellNum++; } rowNum++; for (Map<String, String> dataRow : group.getData()) { cellNum = 0; row = sheet.createRow(rowNum); for (String colHeader : res.getDataFields()) { cell = row.createCell(cellNum); cell.setCellValue(dataRow.get(colHeader)); cellNum++; } rowNum++; } row = sheet.createRow(rowNum); rowNum++; } } response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); wb.write(response.getOutputStream()); } }
From source file:de.ks.idnadrev.expimp.xls.sheet.InlineStringValueParser.java
License:Apache License
@Override public String getValue() { return new XSSFRichTextString(builder.toString()).getString(); }
From source file:de.ks.idnadrev.expimp.xls.sheet.SharedStringValueParser.java
License:Apache License
@Override public String getValue() { int tableIndex = Integer.parseInt(builder.toString()); return new XSSFRichTextString(table.getEntryAt(tableIndex)).getString(); }
From source file:ec.edu.chyc.manejopersonal.managebean.ExcelCustomExporter.java
License:Apache License
@Override protected void addColumnValue(Row row, UIComponent component, String type) { int cellIndex = row.getLastCellNum() == -1 ? 0 : row.getLastCellNum(); Cell cell = row.createCell(cellIndex); String value = ""; if (component != null && component instanceof UIPanel) { for (UIComponent childComponent : component.getChildren()) { if (childComponent.isRendered()) { String valChild = exportValue(FacesContext.getCurrentInstance(), childComponent); if (valChild != null && !valChild.isEmpty()) { valChild = valChild.replace("<br/>", " "); value += valChild + "\n"; }/*from w w w. j a va 2 s. c o m*/ } } } else { value = component == null ? "" : exportValue(FacesContext.getCurrentInstance(), component); } cell.setCellValue(new XSSFRichTextString(value)); if (type.equalsIgnoreCase("facet")) { addFacetAlignments(component, cell); } else { addColumnAlignments(component, cell); } }
From source file:ec.edu.chyc.manejopersonal.managebean.ExcelCustomExporter.java
License:Apache License
@Override 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()) { if (component instanceof HtmlPanelGroup) { for (UIComponent childComponent : component.getChildren()) { if (component.isRendered()) { String valChild = exportValue(context, childComponent); if (valChild != null && !valChild.isEmpty()) { valChild = valChild.replace("<br/>", " "); builder.append(valChild).append("\n"); }/*from w ww. j a v a 2 s . c o m*/ } } } else { String value = exportValue(context, component); if (value != null) { builder.append(value); } } } } cell.setCellValue(new XSSFRichTextString(builder.toString())); if (type.equalsIgnoreCase("facet")) { for (UIComponent component : components) { addFacetAlignments(component, cell); } } else { for (UIComponent component : components) { addColumnAlignments(component, cell); } } }