List of usage examples for org.apache.poi.hssf.usermodel HSSFCell setCellValue
@SuppressWarnings("fallthrough") public void setCellValue(boolean value)
From source file:HSSFReadWrite.java
License:Apache License
/** * given a filename this outputs a sample sheet with just a set of * rows/cells./* w ww . jav a 2 s .com*/ */ 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:Main3.java
private static void transferRow(HSSFRow rowA, HSSFRow rowB) { for (int c = 0; c < 9; c++) { HSSFCell cell1 = rowA.createCell(c); if (rowB.getCell(c) != null) { String replacement = rowB.getCell(c).getStringCellValue(); System.out.println(replacement); cell1.setCellValue(replacement); }//from ww w.j a v a 2 s. co m } }
From source file:NewMain.java
/** * @param args the command line arguments *///from w ww .jav a2 s.c om public static void main(String[] args) throws FileNotFoundException, IOException { HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream("workbook.xls")); HSSFSheet sheet = wb.getSheetAt(0); int written = 2; //2997 for (int r = 2; r < 2997; r += 6) { HSSFCell cell1 = sheet.getRow(r).getCell(1); HSSFCell cell2 = sheet.getRow(r + 1).getCell(1); HSSFCell cell3 = sheet.getRow(r + 2).getCell(1); Contact c = new Contact(cell1, cell2, cell3); System.out.println(c); HSSFRow row = sheet.getRow(written); if (row == null) row = sheet.createRow(written); HSSFCell cellComp = row.createCell(4); cellComp.setCellValue(c.getCompany()); HSSFCell cellAdd = row.createCell(5); cellAdd.setCellValue(c.getAddress()); HSSFCell cellCity = row.createCell(6); cellCity.setCellValue(c.getCity()); HSSFCell cellState = row.createCell(7); cellState.setCellValue(c.getState()); HSSFCell cellZip = row.createCell(8); cellZip.setCellValue(c.getZip()); HSSFCell cellPhone = row.createCell(9); cellPhone.setCellValue(c.getPhone()); HSSFCell cellSite = row.createCell(10); cellSite.setCellValue(c.getSite()); written++; } FileOutputStream out = new FileOutputStream("okay.xls"); wb.write(out); out.close(); }
From source file:erp_frame.java
private void btnExportMouseClicked(java.awt.event.MouseEvent evt) { String outputFile = "D:/ERPOutputFile/" + path + ".xls"; switch (path) { case "": fields = employeeFields;/* w w w . ja v a 2 s. co m*/ break; case "": fields = attendanceFields; break; case "": fields = achivevmentFields; break; case "": fields = payRollFields; break; case "": fields = materialFields; break; case "?": fields = productFields; break; case "": fields = memberFields; break; case "": fields = orderListFields; break; case "": fields = orderItemFields; break; case "": fields = issueFields; break; case "": fields = vendorFields; break; case "?": fields = adminFields; break; case "": fields = purchaseFields; break; case "?": fields = payableFields; break; case "?": fields = assetFields; break; case "?": fields = billboardFields; break; case "?": fields = departFields; break; default: JOptionPane.showMessageDialog(JToolBar, "?"); break; } try { // Create a excel file HSSFWorkbook workbook = new HSSFWorkbook(); // Create a sheet with name HSSFSheet sheet = workbook.createSheet(path); HSSFRow row = null; HSSFCell cell = null; // set the sheet row count and set the first row data with title for (int i = 0; i < table_firmData.getRowCount() + 1; i++) { if (i == 0) { row = sheet.createRow((short) i); for (int k = 0; k < fields.length; k++) { cell = row.createCell((short) k); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue(fields[k]); } } else { // Insert table data in next row row = sheet.createRow((short) i); for (int k = 0; k < fields.length; k++) { cell = row.createCell((short) k); cell.setCellType(HSSFCell.CELL_TYPE_STRING); cell.setCellValue((String) table_firmData.getValueAt(i - 1, k)); } } } FileOutputStream fOut = new FileOutputStream(outputFile); workbook.write(fOut); fOut.flush(); fOut.close(); JOptionPane.showMessageDialog(JToolBar, "?!\n ? :" + outputFile); } catch (Exception ee) { JOptionPane.showMessageDialog(JToolBar, " : " + ee.getMessage()); System.out.println(ee.toString()); } }
From source file:Main2.java
/** * @param args the command line arguments *//*w w w.j a v a 2s . c o m*/ public static void main(String[] args) throws FileNotFoundException, IOException { HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream("workbook2.xls")); HSSFSheet sheet = wb.getSheetAt(1); //Advanced Imaging of Port Charlotte 2625 Tamiami Trail, Unit 1 Port Charlotte, FL 33952 941-235-4646 for (int r = 0; r < 3815; r++) { HSSFRow row = sheet.getRow(r); if (row == null) continue; HSSFCell cell = row.getCell(0); if (cell == null) continue; String parse = cell.getStringCellValue().trim(); if (parse.length() == 0) continue; //Check if the last character is a digit if (Character.isDigit(parse.charAt(parse.length() - 1)) || parse.charAt(parse.length() - 1) == ')') { int stop = parse.length() - 1; char stopChar = parse.charAt(stop); while (stopChar != ' ') { stop--; if (stop == -1) break; stopChar = parse.charAt(stop); } String number = parse.substring(stop + 1); //If it's a phone number if (number.length() > 11) { //HSSFCell cellPhone = row.createCell(8); //cellPhone.setCellValue(number); //Now search for the zip int stopZip = stop - 1; char stopCharZip = parse.charAt(stopZip); if (Character.isDigit(stopCharZip)) { //Cycle through the string backwards until you find a space while (stopCharZip != ' ') { stopZip--; if (stopZip == -1) continue; stopCharZip = parse.charAt(stopZip); } //Write down the zip in the correct spot String zipNumber = parse.substring(stopZip + 1, stop); HSSFCell cellZip = row.createCell(6); cellZip.setCellValue(zipNumber); System.out.println((cellZip == null) + " " + zipNumber); } String state = parse.substring(stopZip - 2, stopZip); //HSSFCell cellState = row.createCell(6); //cellState.setCellValue(state); } } //Find the string before the first dash int firstDash = parse.indexOf('-'); if (firstDash != -1) { String preDash = parse.substring(0, firstDash).trim(); boolean noDigits = true; for (int i = 0; i < 10; i++) { if (preDash.contains(Integer.toString(i))) { noDigits = false; } } if (noDigits && preDash.contains(" ")) { HSSFCell cellComp = row.createCell(2); //cellComp.setCellValue(preDash); } } else { int stopNum = 0; char stopCharNum = parse.charAt(stopNum); while (stopNum < parse.length() - 1 && !Character.isDigit(stopCharNum)) { stopNum++; stopCharNum = parse.charAt(stopNum); } String possTitle = parse.substring(0, stopNum); if (!possTitle.contains(",") && possTitle.length() >= 8) { HSSFCell cellComp = row.createCell(2); //cellComp.setCellValue(possTitle); } } } FileOutputStream out = new FileOutputStream("okay3.xls"); wb.write(out); out.close(); // 2997 // for (int r = 2; r < 2997 ; r += 6) // { // HSSFCell cell1 = sheet.getRow(r).getCell(1); // HSSFCell cell2 = sheet.getRow(r + 1).getCell(1); // HSSFCell cell3 = sheet.getRow(r + 2).getCell(1); // // Contact c = new Contact(cell1, cell2, cell3); // System.out.println(c); // // HSSFRow row = sheet.getRow(written); // if (row == null) // row = sheet.createRow(written); // // HSSFCell cellComp = row.createCell(4); // cellComp.setCellValue(c.getCompany()); // // HSSFCell cellAdd = row.createCell(5); // cellAdd.setCellValue(c.getAddress()); // // HSSFCell cellCity = row.createCell(6); // cellCity.setCellValue(c.getCity()); // // HSSFCell cellState = row.createCell(7); // cellState.setCellValue(c.getState()); // // HSSFCell cellZip = row.createCell(8); // cellZip.setCellValue(c.getZip()); // // HSSFCell cellPhone = row.createCell(9); // cellPhone.setCellValue(c.getPhone()); // // HSSFCell cellSite = row.createCell(10); // cellSite.setCellValue(c.getSite()); // // written++; // // } // // FileOutputStream out = new FileOutputStream("okay.xls"); // 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 .j a v a 2 s.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 w w w .jav a 2 s . com 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(); }/*from ww w. j a va 2s .c o m*/ } } } 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 w w w. ja v a 2s .c om 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 va 2 s. co 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())); }