List of usage examples for org.apache.poi.hssf.usermodel HSSFRichTextString HSSFRichTextString
public HSSFRichTextString(String string)
From source file:HSSFReadWrite.java
License:Apache License
/** * given a filename this outputs a sample sheet with just a set of * rows/cells.//from w ww.j av a 2 s.c om */ private static void testCreateSampleSheet(String outputFilename) throws IOException { int rownum; HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet s = wb.createSheet(); HSSFCellStyle cs = wb.createCellStyle(); HSSFCellStyle cs2 = wb.createCellStyle(); HSSFCellStyle cs3 = wb.createCellStyle(); HSSFFont f = wb.createFont(); HSSFFont f2 = wb.createFont(); f.setFontHeightInPoints((short) 12); f.setColor((short) 0xA); f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); f2.setFontHeightInPoints((short) 10); f2.setColor((short) 0xf); f2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cs.setFont(f); cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("($#,##0_);[Red]($#,##0)")); cs2.setBorderBottom(HSSFCellStyle.BORDER_THIN); cs2.setFillPattern((short) 1); // fill w fg cs2.setFillForegroundColor((short) 0xA); cs2.setFont(f2); wb.setSheetName(0, "HSSF Test"); for (rownum = 0; rownum < 300; rownum++) { HSSFRow r = s.createRow(rownum); if ((rownum % 2) == 0) { r.setHeight((short) 0x249); } for (int cellnum = 0; cellnum < 50; cellnum += 2) { HSSFCell c = r.createCell(cellnum); c.setCellValue(rownum * 10000 + cellnum + (((double) rownum / 1000) + ((double) cellnum / 10000))); if ((rownum % 2) == 0) { c.setCellStyle(cs); } c = r.createCell(cellnum + 1); c.setCellValue(new HSSFRichTextString("TEST")); // 50 characters divided by 1/20th of a point s.setColumnWidth(cellnum + 1, (int) (50 * 8 / 0.05)); if ((rownum % 2) == 0) { c.setCellStyle(cs2); } } } // draw a thick black border on the row at the bottom using BLANKS rownum++; rownum++; HSSFRow r = s.createRow(rownum); cs3.setBorderBottom(HSSFCellStyle.BORDER_THICK); for (int cellnum = 0; cellnum < 50; cellnum++) { HSSFCell c = r.createCell(cellnum); c.setCellStyle(cs3); } s.addMergedRegion(new CellRangeAddress(0, 3, 0, 3)); s.addMergedRegion(new CellRangeAddress(100, 110, 100, 110)); // end draw thick black border // create a sheet, set its title then delete it s = wb.createSheet(); wb.setSheetName(1, "DeletedSheet"); wb.removeSheetAt(1); // end deleted sheet FileOutputStream out = new FileOutputStream(outputFilename); wb.write(out); out.close(); }
From source file:TestUtil.java
License:BSD License
private void writeDE(List<Node[]> cdeIdNodes, HSSFWorkbook wb) { HSSFSheet sheet = wb.getSheet("tbl_DATA_ELEMENTS"); int rowNo = -1; for (int i = 0; i < cdeIdNodes.size(); i++) { Node[] cdeIdRow = cdeIdNodes.get(i); Node cdeIdNode = cdeIdRow[0]; if (cdeIdNode != null) { rowNo++;//w w w .ja v a2s. c o m String cdeIdRep = cdeIdNode.getTextContent(); String[] cdeIdParts = cdeIdRep.split("v"); if (cdeIdParts != null && cdeIdParts.length >= 2) { HSSFRow row = sheet.createRow(10 + rowNo); HSSFCell seqIdCell = row.createCell(1); HSSFCell longNameCell = row.createCell(2); HSSFCell versionCell = row.createCell(3); HSSFCell ctxIdCell = row.createCell(4); HSSFCell prefNameCell = row.createCell(5); HSSFCell vdIdSeqCell = row.createCell(6); HSSFCell decIdSeqCell = row.createCell(7); HSSFCell prefDefCell = row.createCell(8); HSSFCell aslNameCell = row.createCell(9); HSSFCell dateCreatedCell = row.createCell(10); HSSFCell createdByCell = row.createCell(11); HSSFCell idCell = row.createCell(12); StringBuffer cdeId = new StringBuffer("DE" + rowNo); while (cdeId.length() < 36) { cdeId.append("x"); } seqIdCell.setCellValue(new HSSFRichTextString(cdeId.toString())); ctxIdCell.setCellValue(new HSSFRichTextString("6BF1D8AD-29FB-6CF3-E040-A8C0955834A9")); idCell.setCellValue(Double.parseDouble(cdeIdParts[0])); versionCell.setCellValue(Double.parseDouble(cdeIdParts[1])); if (cdeIdRow.length > 1 && cdeIdRow[1] != null) { longNameCell.setCellValue(new HSSFRichTextString(cdeIdRow[1].getTextContent())); } prefNameCell.setCellValue(new HSSFRichTextString("DE Pref Name" + rowNo)); prefDefCell.setCellValue(new HSSFRichTextString("DE Pref Def" + rowNo)); aslNameCell.setCellValue(new HSSFRichTextString("RELEASED")); dateCreatedCell.setCellValue(new Date()); createdByCell.setCellValue(new HSSFRichTextString("MATHURA")); if (cdeIdRow.length > 2 && cdeIdRow[2] != null) { decIdSeqCell.setCellValue(new HSSFRichTextString(decMap.get(cdeIdRow[2].getTextContent()))); } if (cdeIdRow.length > 3 && cdeIdRow[3] != null) { vdIdSeqCell.setCellValue(new HSSFRichTextString(vdMap.get(cdeIdRow[3].getTextContent()))); } } } } }
From source file:TestUtil.java
License:BSD License
private void writeDEC(List<Node[]> decIdNodes, HSSFWorkbook wb) { HSSFSheet sheet = wb.getSheet("tbl_DATA_ELEMENT_CONCEPTS"); int decRowNum = 9; for (int i = 0; i < decIdNodes.size(); i++) { Node[] decIdRow = decIdNodes.get(i); Node decIdNode = decIdRow[0]; if (decIdNode != null) { String decIdRep = decIdNode.getTextContent(); String[] decIdParts = decIdRep.split("v"); if (decIdParts != null && decIdParts.length >= 2 && !decIds.contains(decIdParts[0])) { decIds.add(decIdParts[0]); decRowNum++;/*from www . j a va2s . co m*/ HSSFRow row = sheet.createRow(decRowNum); HSSFCell seqIdCell = row.createCell(1); HSSFCell versionCell = row.createCell(2); HSSFCell ctxIdCell = row.createCell(4); HSSFCell prefNameCell = row.createCell(3); HSSFCell decIdSeqCell = row.createCell(5); HSSFCell prefDefCell = row.createCell(6); HSSFCell aslNameCell = row.createCell(7); HSSFCell dateCreatedCell = row.createCell(8); HSSFCell createdByCell = row.createCell(9); HSSFCell idCell = row.createCell(10); StringBuffer decId = new StringBuffer("DEC" + i); while (decId.length() < 36) { decId.append("x"); } seqIdCell.setCellValue(new HSSFRichTextString(decId.toString())); ctxIdCell.setCellValue(new HSSFRichTextString("6BF1D8AD-29FB-6CF3-E040-A8C0955834A9")); idCell.setCellValue(Double.parseDouble(decIdParts[0])); versionCell.setCellValue(Double.parseDouble(decIdParts[1].split(":")[0])); prefNameCell.setCellValue(new HSSFRichTextString("DEC Pref Name" + i)); prefDefCell.setCellValue(new HSSFRichTextString("DEC Pref Def" + i)); aslNameCell.setCellValue(new HSSFRichTextString("RELEASED")); dateCreatedCell.setCellValue(new Date()); createdByCell.setCellValue(new HSSFRichTextString("MATHURA")); if (decIdRow.length > 1 && decIdRow[1] != null) { String cdId = decIdRow[1].getTextContent(); if (cdMap.get(cdId) != null) { decIdSeqCell.setCellValue(new HSSFRichTextString(cdMap.get(cdId))); } } decMap.put(decIdRep, decId.toString()); } } } }
From source file:TestUtil.java
License:BSD License
private void writeVD(List<Node[]> vdIdNodes, HSSFWorkbook wb) { HSSFSheet sheet = wb.getSheet("tbl_VALUE_DOMAINS"); int vdRowNum = 9; for (int i = 0; i < vdIdNodes.size(); i++) { Node[] vdIdRow = vdIdNodes.get(i); Node vdIdNode = vdIdRow[0]; if (vdIdNode == null) { if (vdIdRow.length > 1) { String dt = vdIdRow[1].getTextContent().toUpperCase(); if (!dataTypes.contains(dt)) { try { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder parser = factory.newDocumentBuilder(); Document doc = parser.newDocument(); org.w3c.dom.Element elem = doc.createElement("node"); elem.setTextContent("1111v1.0:Sample VD"); vdIdNode = elem; } catch (DOMException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParserConfigurationException e) { // TODO Auto-generated catch block e.printStackTrace(); }/* ww w . j ava2 s . com*/ } } } if (vdIdNode != null) { String vdIdRep = vdIdNode.getTextContent(); String[] vdIdParts = vdIdRep.split("v"); if (vdIdParts != null && vdIdParts.length >= 2 && !vdIds.contains(vdIdParts[0])) { vdIds.add(vdIdParts[0]); vdRowNum++; HSSFRow row = sheet.createRow(vdRowNum); HSSFCell seqIdCell = row.createCell(1); HSSFCell versionCell = row.createCell(2); HSSFCell longNameCell = row.createCell(3); HSSFCell ctxIdCell = row.createCell(5); HSSFCell prefNameCell = row.createCell(4); HSSFCell prefDefCell = row.createCell(6); HSSFCell dtlNameCell = row.createCell(7); HSSFCell cdIdSeqCell = row.createCell(8); HSSFCell vdTypeCell = row.createCell(9); HSSFCell aslNameCell = row.createCell(10); HSSFCell dateCreatedCell = row.createCell(11); HSSFCell createdByCell = row.createCell(12); HSSFCell idCell = row.createCell(13); StringBuffer vdId = new StringBuffer("VD" + i); while (vdId.length() < 36) { vdId.append("x"); } seqIdCell.setCellValue(new HSSFRichTextString(vdId.toString())); ctxIdCell.setCellValue(new HSSFRichTextString("6BF1D8AD-29FB-6CF3-E040-A8C0955834A9")); idCell.setCellValue(Double.parseDouble(vdIdParts[0])); versionCell.setCellValue(Double.parseDouble(vdIdParts[1].split(":")[0])); longNameCell.setCellValue(new HSSFRichTextString(vdIdParts[1].split(":")[1])); prefNameCell.setCellValue(new HSSFRichTextString("VD Pref Name" + i)); prefDefCell.setCellValue(new HSSFRichTextString("VD Pref Def" + i)); aslNameCell.setCellValue(new HSSFRichTextString("RELEASED")); dateCreatedCell.setCellValue(new Date()); createdByCell.setCellValue(new HSSFRichTextString("MATHURA")); if (vdIdRow.length > 1 && vdIdRow[1] != null) { dtlNameCell.setCellValue(new HSSFRichTextString(vdIdRow[1].getTextContent().toUpperCase())); } if (vdIdRow.length > 2 && vdIdRow[2] != null) { String enumYesNo = vdIdRow[2].getTextContent(); String enumer = enumYesNo.equalsIgnoreCase("Yes") ? "E" : "N"; vdTypeCell.setCellValue(new HSSFRichTextString(enumer)); } if (vdIdRow.length > 3 && vdIdRow[3] != null) { String cdId = vdIdRow[3].getTextContent(); if (cdMap.get(cdId) != null) { cdIdSeqCell.setCellValue(new HSSFRichTextString(cdMap.get(cdId))); } } vdMap.put(vdIdRep, vdId.toString()); } } } }
From source file:TestUtil.java
License:BSD License
private void writeCD(List<Node[]> cdIdNodes, HSSFWorkbook wb) { HSSFSheet sheet = wb.getSheet("tbl_CONCEPTUAL_DOMAINS"); int cdRowNum = 10; for (int i = 0; i < cdIdNodes.size(); i++) { Node[] cdIdRow = cdIdNodes.get(i); Node cdIdNode = cdIdRow[0]; String cdIdRep = cdIdNode.getTextContent(); String[] cdIdParts = cdIdRep.split("v"); if (cdIdParts != null && cdIdParts.length >= 2 && !cdIds.contains(cdIdParts[0])) { cdIds.add(cdIdParts[0]);//from ww w . ja va2s. com cdRowNum++; HSSFRow row = sheet.createRow(cdRowNum); HSSFCell seqIdCell = row.createCell(1); HSSFCell versionCell = row.createCell(2); HSSFCell ctxIdCell = row.createCell(4); HSSFCell prefNameCell = row.createCell(3); HSSFCell prefDefCell = row.createCell(5); HSSFCell aslNameCell = row.createCell(6); HSSFCell dateCreatedCell = row.createCell(7); HSSFCell createdByCell = row.createCell(8); HSSFCell idCell = row.createCell(9); StringBuffer cdId = new StringBuffer("CD" + i); while (cdId.length() < 36) { cdId.append("x"); } seqIdCell.setCellValue(new HSSFRichTextString(cdId.toString())); ctxIdCell.setCellValue(new HSSFRichTextString("6BF1D8AD-29FB-6CF3-E040-A8C0955834A9")); idCell.setCellValue(Double.parseDouble(cdIdParts[0])); versionCell.setCellValue(Double.parseDouble(cdIdParts[1].split(":")[0])); prefNameCell.setCellValue(new HSSFRichTextString("CD Pref Name" + i)); prefDefCell.setCellValue(new HSSFRichTextString("CD Pref Def" + i)); aslNameCell.setCellValue(new HSSFRichTextString("RELEASED")); dateCreatedCell.setCellValue(new Date()); createdByCell.setCellValue(new HSSFRichTextString("MATHURA")); cdMap.put(cdIdRep, cdId.toString()); } } }
From source file:TestUtil.java
License:BSD License
private void writeCS(Node csNode, HSSFWorkbook wb) { HSSFSheet sheet = wb.getSheet("tbl_CLASSIFICATION_SCHEMES"); HSSFRow row = sheet.getRow(10);//from w w w . j a va2 s . c o m HSSFCell prefNameCell = row.createCell(3); HSSFCell longNameCell = row.createCell(4); HSSFCell prefDefCell = row.createCell(5); prefNameCell.setCellValue(new HSSFRichTextString(csNode.getTextContent())); longNameCell.setCellValue(new HSSFRichTextString(csNode.getTextContent())); prefDefCell.setCellValue(new HSSFRichTextString(csNode.getTextContent())); }
From source file:TestUtil.java
License:BSD License
private void writeCSI(Node csiNode, HSSFWorkbook wb) { HSSFSheet sheet = wb.getSheet("tbl_CS_ITEMS"); HSSFRow row = sheet.getRow(10);/* w ww. jav a 2 s . c om*/ HSSFCell prefNameCell = row.createCell(6); HSSFCell longNameCell = row.createCell(7); HSSFCell prefDefCell = row.createCell(8); prefNameCell.setCellValue(new HSSFRichTextString(csiNode.getTextContent())); longNameCell.setCellValue(new HSSFRichTextString(csiNode.getTextContent())); prefDefCell.setCellValue(new HSSFRichTextString(csiNode.getTextContent())); }
From source file:TestUtil.java
License:BSD License
private void writeCon(List<Node[]> conIdNodes, HSSFWorkbook wb) { HSSFSheet sheet = wb.getSheet("tbl_CONCEPTS_EXT"); int conRowNum = 9; int id = 1110; int j = -1;//from w ww . j av a 2s . com for (int i = 0; i < conIdNodes.size(); i++) { Node[] conIdRow = conIdNodes.get(i); Node conIdNode = conIdRow[0]; String conIdRep = conIdNode.getTextContent(); String[] concepts = conIdRep.split(";"); for (String concept : concepts) { j++; String[] cdeIdParts = concept.split(":"); if (cdeIdParts != null && cdeIdParts.length >= 2 && !conIds.contains(cdeIdParts[0])) { String cdeId = cdeIdParts[0].trim(); String longName = cdeIdParts[1].trim(); conIds.add(cdeId); conRowNum++; id++; HSSFRow row = sheet.createRow(conRowNum); HSSFCell seqIdCell = row.createCell(1); HSSFCell versionCell = row.createCell(6); HSSFCell ctxIdCell = row.createCell(5); HSSFCell prefNameCell = row.createCell(2); HSSFCell longNameCell = row.createCell(3); HSSFCell prefDefCell = row.createCell(4); HSSFCell aslNameCell = row.createCell(7); HSSFCell idCell = row.createCell(8); HSSFCell defSourceCell = row.createCell(9); StringBuffer conId = new StringBuffer("CON" + j); while (conId.length() < 36) { conId.append("x"); } seqIdCell.setCellValue(new HSSFRichTextString(conId.toString())); ctxIdCell.setCellValue(new HSSFRichTextString("6BF1D8AD-29FB-6CF3-E040-A8C0955834A9")); idCell.setCellValue(Double.parseDouble(id + "")); versionCell.setCellValue(Double.parseDouble("1.0")); prefNameCell.setCellValue(new HSSFRichTextString(cdeId)); longNameCell.setCellValue(new HSSFRichTextString(longName)); prefDefCell.setCellValue(new HSSFRichTextString("DEC Pref Def" + i)); aslNameCell.setCellValue(new HSSFRichTextString("RELEASED")); defSourceCell.setCellValue(new HSSFRichTextString("NCI")); } } } }
From source file:angiotool.SaveToExcel.java
License:Open Source License
private HSSFCell createCell(int column, Object obj, HSSFCellStyle cellStyle) { if (column < 0) column = 0;//from w w w .j a v a 2 s .co m HSSFCell cell = r.createCell(column); if (obj instanceof String) cell.setCellValue(new HSSFRichTextString((String) obj)); else if (obj instanceof Double) cell.setCellValue((Double) obj); else if (obj instanceof Integer) cell.setCellValue((Integer) obj); else if (obj instanceof Long) cell.setCellValue((Long) obj); cell.setCellStyle(cellStyle); return cell; }
From source file:binky.reportrunner.engine.renderers.exporters.TabbedXLSExporter.java
License:Open Source License
@SuppressWarnings("deprecation") @Override/* w w w . jav a 2 s . co m*/ public void export(ResultSet resultSet, String label, OutputStream outputStream) throws ExportException { if (this.outputStream == null) this.outputStream = outputStream; try { if (wb == null) { logger.trace("creating new workbook"); wb = new HSSFWorkbook(); } logger.trace("creaing worksheet " + label); HSSFSheet sheet = wb.createSheet(label); ResultSetMetaData metaData; metaData = resultSet.getMetaData(); short rowCount = 0; // logger.debug("writing header"); HSSFRow headerRow = sheet.createRow(rowCount); for (int i = 1; i <= metaData.getColumnCount(); i++) { // TODO:fix HSSFCell cell = headerRow.createCell((short) (i - 1)); HSSFRichTextString string = new HSSFRichTextString(metaData.getColumnName(i)); string.applyFont(HSSFFont.BOLDWEIGHT_BOLD); cell.setCellValue(string); } while (resultSet.next()) { rowCount++; HSSFRow row = sheet.createRow(rowCount); for (int i = 1; i <= metaData.getColumnCount(); i++) { // TODO:fix HSSFCell cell = row.createCell((short) (i - 1)); // TODO:make this better by using types HSSFRichTextString string = new HSSFRichTextString("" + resultSet.getObject(i)); cell.setCellValue(string); } } } catch (SQLException e) { throw new ExportException(e.getMessage(), e); } }