List of usage examples for org.apache.poi.ss.usermodel Row cellIterator
Iterator<Cell> cellIterator();
From source file:com.abixen.platform.service.businessintelligence.multivisualisation.application.service.file.reader.ExcelReaderService.java
License:Open Source License
private RowDto buildRowTypes(final Row row) { final RowDto rowDto = new RowDto(); final Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { rowDto.addColumn(new ColumnDto(getTypeAsString(cellIterator.next()))); }//w ww. j a v a2 s . c o m return rowDto; }
From source file:com.abixen.platform.service.businessintelligence.multivisualisation.application.service.file.reader.ExcelReaderService.java
License:Open Source License
private RowDto readRowAsRowInMemory(final Row row, final RowDto rowTypes) { final RowDto rowDto = new RowDto(); final Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { rowDto.addColumn(new ColumnDto(formatIfData(cellIterator.next()))); }/*w w w.ja va 2 s. c om*/ return rowDto; }
From source file:com.actelion.research.spiritapp.ui.util.PDFUtils.java
License:Open Source License
public static void convertHSSF2Pdf(Workbook wb, String header, File reportFile) throws Exception { assert wb != null; assert reportFile != null; //Precompute formula FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); for (int i = 0; i < wb.getNumberOfSheets(); i++) { Sheet sheet = wb.getSheetAt(i);/*from ww w . ja va2 s . c o m*/ for (Row r : sheet) { for (Cell c : r) { if (c.getCellType() == HSSFCell.CELL_TYPE_FORMULA) { try { evaluator.evaluateFormulaCell(c); } catch (Exception e) { System.err.println(e); } } } } } File tmp = File.createTempFile("tmp_", ".xlsx"); try (OutputStream out = new BufferedOutputStream(new FileOutputStream(tmp))) { wb.write(out); } //Find page orientation int maxColumnsGlobal = 0; for (int sheetNo = 0; sheetNo < wb.getNumberOfSheets(); sheetNo++) { Sheet sheet = wb.getSheetAt(sheetNo); for (Iterator<Row> rowIterator = sheet.iterator(); rowIterator.hasNext();) { Row row = rowIterator.next(); maxColumnsGlobal = Math.max(maxColumnsGlobal, row.getLastCellNum()); } } Rectangle pageSize = maxColumnsGlobal < 10 ? PageSize.A4 : PageSize.A4.rotate(); Document pdfDocument = new Document(pageSize, 10f, 10f, 20f, 20f); PdfWriter writer = PdfWriter.getInstance(pdfDocument, new FileOutputStream(reportFile)); addHeader(writer, header); pdfDocument.open(); //we have two columns in the Excel sheet, so we create a PDF table with two columns //Note: There are ways to make this dynamic in nature, if you want to. //Loop through sheets for (int sheetNo = 0; sheetNo < wb.getNumberOfSheets(); sheetNo++) { Sheet sheet = wb.getSheetAt(sheetNo); //Loop through rows, to find number of columns int minColumns = 1000; int maxColumns = 0; for (Iterator<Row> rowIterator = sheet.iterator(); rowIterator.hasNext();) { Row row = rowIterator.next(); if (row.getFirstCellNum() >= 0) minColumns = Math.min(minColumns, row.getFirstCellNum()); if (row.getLastCellNum() >= 0) maxColumns = Math.max(maxColumns, row.getLastCellNum()); } if (maxColumns == 0) continue; //Loop through first rows, to find relative width float[] widths = new float[maxColumns]; int totalWidth = 0; for (int c = 0; c < maxColumns; c++) { int w = sheet.getColumnWidth(c); widths[c] = w; totalWidth += w; } for (int c = 0; c < maxColumns; c++) { widths[c] /= totalWidth; } //Create new page and a new chapter with the sheet's name if (sheetNo > 0) pdfDocument.newPage(); Chapter pdfSheet = new Chapter(sheet.getSheetName(), sheetNo + 1); PdfPTable pdfTable = null; PdfPCell pdfCell = null; boolean inTable = false; //Loop through cells, to create the content // boolean leftBorder = true; // boolean[] topBorder = new boolean[maxColumns+1]; for (int r = 0; r <= sheet.getLastRowNum(); r++) { Row row = sheet.getRow(r); //Check if we exited a table (empty line) if (row == null) { if (pdfTable != null) { addTable(pdfDocument, pdfSheet, totalWidth, widths, pdfTable); pdfTable = null; } inTable = false; continue; } //Check if we start a table (>MIN_COL_IN_TABLE columns) if (row.getLastCellNum() >= MIN_COL_IN_TABLE) { inTable = true; } if (!inTable) { //Process the data outside table, just add the text boolean hasData = false; Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); if (cell.getCellType() == Cell.CELL_TYPE_BLANK) continue; Chunk chunk = getChunk(wb, cell); pdfSheet.add(chunk); pdfSheet.add(new Chunk(" ")); hasData = true; } if (hasData) pdfSheet.add(Chunk.NEWLINE); } else { //Process the data in table if (pdfTable == null) { //Create table pdfTable = new PdfPTable(maxColumns); pdfTable.setWidths(widths); // topBorder = new boolean[maxColumns+1]; } int cellNumber = minColumns; // leftBorder = false; Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); for (; cellNumber < cell.getColumnIndex(); cellNumber++) { pdfCell = new PdfPCell(); pdfCell.setBorder(0); pdfTable.addCell(pdfCell); } Chunk phrase = getChunk(wb, cell); pdfCell = new PdfPCell(new Phrase(phrase)); pdfCell.setFixedHeight(row.getHeightInPoints() - 3); pdfCell.setNoWrap(!cell.getCellStyle().getWrapText()); pdfCell.setPaddingLeft(1); pdfCell.setHorizontalAlignment( cell.getCellStyle().getAlignment() == CellStyle.ALIGN_CENTER ? PdfPCell.ALIGN_CENTER : cell.getCellStyle().getAlignment() == CellStyle.ALIGN_RIGHT ? PdfPCell.ALIGN_RIGHT : PdfPCell.ALIGN_LEFT); pdfCell.setUseBorderPadding(false); pdfCell.setUseVariableBorders(false); pdfCell.setBorderWidthRight(cell.getCellStyle().getBorderRight() == 0 ? 0 : .5f); pdfCell.setBorderWidthBottom(cell.getCellStyle().getBorderBottom() == 0 ? 0 : cell.getCellStyle().getBorderBottom() > 1 ? 1 : .5f); pdfCell.setBorderWidthLeft(cell.getCellStyle().getBorderLeft() == 0 ? 0 : cell.getCellStyle().getBorderLeft() > 1 ? 1 : .5f); pdfCell.setBorderWidthTop(cell.getCellStyle().getBorderTop() == 0 ? 0 : cell.getCellStyle().getBorderTop() > 1 ? 1 : .5f); String color = cell.getCellStyle().getFillForegroundColorColor() == null ? null : ((XSSFColor) cell.getCellStyle().getFillForegroundColorColor()).getARGBHex(); if (color != null) pdfCell.setBackgroundColor(new Color(Integer.decode("0x" + color.substring(2)))); pdfTable.addCell(pdfCell); cellNumber++; } for (; cellNumber < maxColumns; cellNumber++) { pdfCell = new PdfPCell(); pdfCell.setBorder(0); pdfTable.addCell(pdfCell); } } //Custom code to add all images on the first sheet (works for reporting) if (sheetNo == 0 && row.getRowNum() == 0) { for (PictureData pd : wb.getAllPictures()) { try { Image pdfImg = Image.getInstance(pd.getData()); pdfImg.scaleToFit( pageSize.getWidth() * .8f - pageSize.getBorderWidthLeft() - pageSize.getBorderWidthRight(), pageSize.getHeight() * .8f - pageSize.getBorderWidthTop() - pageSize.getBorderWidthBottom()); pdfSheet.add(pdfImg); } catch (Exception e) { e.printStackTrace(); } } } } if (pdfTable != null) { addTable(pdfDocument, pdfSheet, totalWidth, widths, pdfTable); } pdfDocument.add(pdfSheet); } pdfDocument.close(); }
From source file:com.adobe.acs.commons.data.Spreadsheet.java
License:Apache License
private List<Variant> readRow(Row row) { Iterator<Cell> iterator = row.cellIterator(); List<Variant> rowOut = new ArrayList<>(); while (iterator.hasNext()) { Cell c = iterator.next();// ww w . j av a 2 s . c o m while (c.getColumnIndex() > rowOut.size()) { rowOut.add(null); } Variant val = new Variant(c); rowOut.add(val.isEmpty() ? null : val); } return rowOut; }
From source file:com.adobe.acs.commons.mcp.impl.processes.AssetFolderCreator.java
License:Apache License
/** * Parse a row in the Excel that represents an asset folder and ancestors. * * @param row the row to process from the Excel sheet. *///from w w w. j ava2 s . co m private void parseAssetFolderRow(final Row row) { final Iterator<Cell> cells = row.cellIterator(); // The previousAssetFolderPath is reset on each new row. String previousAssetFolderPath = null; while (cells.hasNext()) { try { previousAssetFolderPath = parseAssetFolderCell(cells.next(), previousAssetFolderPath); } catch (IllegalArgumentException e) { // Error logged in throwing method parseAssetFolderCell. // Skip rest of row to avoid creating undesired structures with bad data. break; } } }
From source file:com.adobe.acs.commons.mcp.impl.processes.TagCreator.java
License:Apache License
/** * Parses the input Excel file and creates a list of TagDefinition objects to process. * * @param manager the action manager//from ww w . ja v a2s. c om * @throws IOException */ @SuppressWarnings({ "squid:S3776", "squid:S1141" }) public void parseTags(ActionManager manager) throws Exception { manager.withResolver(rr -> { final XSSFWorkbook workbook = new XSSFWorkbook(excelFile); final XSSFSheet sheet = workbook.getSheetAt(0); final Iterator<Row> rows = sheet.rowIterator(); final String tagsRootPath = new TagRootResolver(rr).getTagsLocationPath(); if (tagsRootPath == null) { record(ReportRowSatus.FAILED_TO_PARSE, "Abandoning Tag parsing. Unable to determine AEM Tags root (/content/cq:tags vs /etc/tags). Please ensure the path exists and is accessible by the user running Tag Creator.", "N/A", "N/A"); return; } while (rows.hasNext()) { final Row row = rows.next(); final Iterator<Cell> cells = row.cellIterator(); int cellIndex = 0; // The previousTagId is reset on each new row. String previousTagId = null; while (cells.hasNext()) { final Cell cell = cells.next(); final String cellValue = StringUtils.trimToNull(cell.getStringCellValue()); if (StringUtils.isBlank(cellValue)) { // Hitting a blank cell means its the end of this row; don't process anything past this break; } // Generate a tag definition that will in turn be used to drive the tag creation TagDefinition tagDefinition = getTagDefinition(primary, cellIndex, cellValue, previousTagId, tagsRootPath); if (tagDefinition == null) { tagDefinition = getTagDefinition(fallback, cellIndex, cellValue, previousTagId, tagsRootPath); } if (tagDefinition == null) { log.warn("Could not find a Tag Data Converter that accepts value [ {} ]; skipping...", cellValue); // Record parse failure record(ReportRowSatus.FAILED_TO_PARSE, cellValue, "", ""); // Break to next Row break; } else { /* Prepare for next Cell */ cellIndex++; previousTagId = tagDefinition.getId(); if (tagDefinitions.get(tagDefinition.getId()) == null) { tagDefinitions.put(tagDefinition.getId(), tagDefinition); } } } } log.info("Finished Parsing and collected [ {} ] tags for import.", tagDefinitions.size()); }); }
From source file:com.adobe.acs.commons.mcp.util.Spreadsheet.java
License:Apache License
private List<String> readRow(Row row) { Iterator<Cell> iterator = row.cellIterator(); List<String> rowOut = new ArrayList<>(); while (iterator.hasNext()) { Cell c = iterator.next();/*from ww w.ja v a2 s . c o m*/ while (c.getColumnIndex() > rowOut.size()) { rowOut.add(null); } rowOut.add(getStringValueFromCell(c)); } return rowOut; }
From source file:com.alphacell.controller.CargarDatosBean.java
public void handleFileUpload(FileUploadEvent event) { if (event.getFile().equals(null)) { FacesUtil.addInfoMessage("El archivo es null"); }//from w w w. j ava 2 s . co m InputStream file; HSSFWorkbook workbook = null; try { file = event.getFile().getInputstream(); workbook = new HSSFWorkbook(file); } catch (IOException e) { FacesUtil.addErrorMessage("Error Leyendo archivo : " + e); } HSSFSheet sheet = workbook.getSheetAt(1); Iterator<Row> rowIterator = sheet.iterator(); Calendar calendar = new GregorianCalendar(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); Iterator<Cell> cellIterator = row.cellIterator(); //Job job = new Job(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: if (HSSFDateUtil.isCellDateFormatted(cell) || HSSFDateUtil.isCellInternalDateFormatted(cell)) { calendar.setTime(cell.getDateCellValue()); } else { System.out.print(cell.getNumericCellValue() + "\t\t"); } break; case Cell.CELL_TYPE_STRING: System.out.print(cell.getStringCellValue() + "\t\t"); break; } } } }
From source file:com.amitycoin.enterprisetool.diagramInputServlet.java
@Override @SuppressWarnings({ "null", "ValueOfIncrementOrDecrementUsed", "UnusedAssignment" }) protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String filePath;/*from w w w. j a va2 s . c o m*/ String docids; String userid; String a[][]; a = new String[200][200]; // database connection settings String dbURL = "jdbc:mysql://localhost:3306/enterprisedb"; String dbUser = "root"; String dbPass = "sandy"; @SuppressWarnings("UnusedAssignment") Connection conn = null; // connection to the database userid = (String) request.getAttribute("uidM"); String fname = (String) request.getAttribute("fnameM"); int docid = (Integer) request.getAttribute("docidM"); docids = "" + docid; String pathToWeb; pathToWeb = getServletContext().getRealPath(File.separator); System.out.println("pathtoweb:\t" + pathToWeb); filePath = pathToWeb + "readFiles\\"; filePath = filePath + docids + userid + fname; //+.xls File myFile = new File(filePath); //boolean newExcel; //boolean oldExcel; String ext = FilenameUtils.getExtension(filePath); System.out.println("Extension: " + ext); FileInputStream fis = new FileInputStream(myFile); Workbook wb = null; if ("xls".equals(ext)) { // Finds the workbook instance for the file wb = new HSSFWorkbook(fis); } else if ("xlsx".equals(ext)) { wb = new XSSFWorkbook(fis); } @SuppressWarnings("null") Sheet mySheet; mySheet = wb.getSheetAt(0); // Get iterator to all the rows in current sheet Iterator<Row> rowIterator = mySheet.iterator(); @SuppressWarnings("UnusedAssignment") int rowct = 0, colct = 0, colit = 0, ci = 0, ri = 0; // Traversing over each row of XLSX file while (rowIterator.hasNext()) { ri++; System.out.println("\nRi:\t" + ri); //Iterate over Rows Row row = rowIterator.next(); if (1 == rowct) { colct = colit; } // For each row, iterate through each columns Iterator<Cell> cellIterator = row.cellIterator(); ci = 0; while (cellIterator.hasNext()) { ci++; System.out.println("\nCi:\t" + ci); //Iterate over Columns Cell cell = cellIterator.next(); switch (cell.getCellType()) { case Cell.CELL_TYPE_STRING: System.out.print(cell.getStringCellValue() + "\t"); a[ri][ci] = cell.getStringCellValue(); break; case Cell.CELL_TYPE_NUMERIC: System.out.print(cell.getNumericCellValue() + "\t"); double temp = cell.getNumericCellValue(); String dblValue = "" + temp; a[ri][ci] = dblValue; break; case Cell.CELL_TYPE_BOOLEAN: System.out.print(cell.getBooleanCellValue() + "\t"); String tmp = "" + cell.getBooleanCellValue(); a[ri][ci] = tmp; break; default: } colit++; } //rowit++; rowct++; //increase row count } System.out.println("Row Count:\t" + rowct); System.out.println("Column Count:\t" + colct); for (int i = 1; i <= rowct; i++) { for (int j = 1; j <= colct; j++) { System.out.println("a[" + i + "][" + j + "]=" + a[i][j] + "\n"); } } try { DriverManager.registerDriver(new com.mysql.jdbc.Driver()); conn = DriverManager.getConnection(dbURL, dbUser, dbPass); String append = "?, ?"; String quest = ", ?"; for (int j = 1; j <= colct; j++) { append += quest; } String crsql; String cappend = "`uid`,`doc_id`"; for (int j = 1; j <= colct; j++) { cappend = cappend + ",`" + j + "`"; } crsql = "CREATE TABLE IF NOT EXISTS `data" + userid + docid + "` (\n" + "`row_id` INT(11) NOT NULL AUTO_INCREMENT,\n" + "`uid` VARCHAR(50) NOT NULL,\n" + "`doc_id` INT(11) NOT NULL"; System.out.println(crsql); for (int j = 1; j <= colct; j++) { System.out.println("j:\t" + (j)); crsql = crsql + ",\n`" + (j) + "` VARCHAR(50)"; } crsql += ",\nPRIMARY KEY (`row_id`)\n)"; System.out.println(crsql); PreparedStatement cstmt = conn.prepareStatement(crsql); int c = cstmt.executeUpdate(); String sql = "INSERT INTO data" + userid + docid + "(" + cappend + ")" + " values (" + append + ")"; System.out.println("Append=\t" + append); PreparedStatement statement = conn.prepareStatement(sql); statement.setString(1, userid); statement.setInt(2, docid); for (int i = 1; i <= rowct; i++) { for (int j = 1; j <= (colct); j++) { statement.setString(j + 2, a[i][j]); System.out.println("j=" + (j) + "\ta[" + i + "][" + (j) + "]=" + a[i][j] + "\n"); } System.out.println("\n"); System.out.println("\nstatement:\t" + statement); int res = statement.executeUpdate(); } } catch (SQLException ex) { Logger.getLogger(diagramInputServlet.class.getName()).log(Level.SEVERE, null, ex); } for (int i = 1; i <= rowct; i++) { for (int j = 1; j <= colct; j++) { System.out.println("a[" + i + "][" + j + "]=" + a[i][j] + "\n"); } } System.out.println("Rowct:\t" + rowct + "\nColct:\t" + colct); @SuppressWarnings("UseOfObsoleteCollectionType") Hashtable<String, Object> style = new Hashtable<String, Object>(); style.put(mxConstants.STYLE_FILLCOLOR, mxUtils.getHexColorString(Color.WHITE)); style.put(mxConstants.STYLE_STROKEWIDTH, 1.5); style.put(mxConstants.STYLE_STROKECOLOR, mxUtils.getHexColorString(new Color(0, 0, 170))); style.put(mxConstants.STYLE_SHAPE, mxConstants.SHAPE_ELLIPSE); style.put(mxConstants.STYLE_PERIMETER, mxConstants.PERIMETER_ELLIPSE); graph = new mxGraph(); mxStylesheet stylesheet = graph.getStylesheet(); stylesheet.putCellStyle("process", createProcessStyle()); stylesheet.putCellStyle("object", createObjectStyle()); stylesheet.putCellStyle("state", createStateStyle()); stylesheet.putCellStyle("agent", createAgentLinkStyle()); fr = new JFrame("Enterprise Architecture Diagram"); fr.setSize(2000, 2000); graph.setMinimumGraphSize(new mxRectangle(0, 0, 1000, 1500)); graph.setMaximumGraphBounds(new mxRectangle(0, 0, 2000, 2000)); graph.setMinimumGraphSize(new mxRectangle(0, 0, 1000, 1000)); double rech1 = 200; double rech2 = 200; double rech3 = 170; double rech3e = 180; double rech4 = 120; Object defaultParent = graph.getDefaultParent(); graph.setConstrainChildren(true); graph.setExtendParents(true); graph.setExtendParentsOnAdd(true); graph.setDefaultOverlap(0); graph.setCellsMovable(true); // Moving cells in the graph. Note that an edge is also a cell. graph.setCellsEditable(true); graph.setCellsResizable(true); // Inhibit cell re-sizing. graph.getModel().beginUpdate(); Object[] obj = new Object[100]; int k = 1; for (int i = 2; i <= rowct; i++) { for (int j = 1; j <= 2; j++) { obj[k] = a[i][j]; k++; } } //print debug info for (int l = 1; l <= (rowct * 2) - 2; l++) { System.out.println("obj[" + l + "]:\t" + obj[l]); } List<Object> list = new ArrayList<Object>(); for (Object val : obj) { if (!list.contains(val)) { list.add(val); } } list.remove(null); list.toArray(new Object[0]); System.out.println("list:" + list); Object[] array = new Object[list.size()]; list.toArray(array); // fill the array System.out.println("Array:\t" + Arrays.toString(array)); Object[] gArray = new Object[array.length]; String[] sArray = new String[array.length]; for (int i = 0; i < array.length; i++) { sArray[i] = array[i].toString(); if (sArray[i].contains("Database") || sArray[i].contains("Server") || sArray[i].contains("DATABASE") || sArray[i].contains("SERVER") || sArray[i].contains("DB")) { System.out.println("Object type"); gArray[i] = graph.insertVertex(defaultParent, null, sArray[i], rech1, rech2, rech3, rech4, "object"); } else { System.out.println("Process type"); gArray[i] = graph.insertVertex(defaultParent, null, sArray[i], rech1, rech2, rech3e, rech4, "process"); } rech1 += 100; rech2 += 100; } for (int i = 2; i <= rowct; i++) { if (a[i][3].equals("Two Way") || a[i][3].equals("TWO WAY") || a[i][3].equals("TwoWay") || a[i][3].equals("TWOWAY") || a[i][3].equals("2 Way") || a[i][3].equals("Two way")) { System.out.println("Double Edges"); int l1 = 0, l2 = 0; for (int l = 1; l < gArray.length; l++) { System.out.println("gArray.toString=\t" + sArray[l]); System.out.println("gArray.length=\t" + sArray.length); if (sArray[l].equals(a[i][1])) { l1 = l; System.out.println("l2:\t" + l1); } if (sArray[l].equals(a[i][2])) { l2 = l; System.out.println("l2:\t" + l2); } } graph.insertEdge(defaultParent, null, a[i][4], gArray[l1], gArray[l2], "agent"); graph.insertEdge(defaultParent, null, a[i][4], gArray[l2], gArray[l1], "agent"); } else { System.out.println("Single Edges"); int l1 = 0, l2 = 0; for (int l = 1; l < gArray.length; l++) { System.out.println("gArray.toString=\t" + sArray[l]); System.out.println("gArray.length=\t" + sArray.length); if (sArray[l].equals(a[i][1])) { l1 = l; System.out.println("l2:\t" + l2); } if (sArray[l].equals(a[i][2])) { l2 = l; System.out.println("l2:\t" + l2); } } graph.insertEdge(defaultParent, null, a[i][4], gArray[l1], gArray[l2], "agent"); } } graph.setEnabled(true); graph.setAutoSizeCells(true); graph.getModel().endUpdate(); graphComponent = new mxGraphComponent(graph); mxFastOrganicLayout layout = new mxFastOrganicLayout(graph); // define layout //set all properties layout.setMinDistanceLimit(1); //layout.setInitialTemp(5); //layout.setInitialTemp(10); //layout.setForceConstant(10); //layout.setDisableEdgeStyle(true); //layout graph //layout.execute(graph.getDefaultParent()); // layout using morphing String fileWPath; graph.getModel().beginUpdate(); try { layout.execute(graph.getDefaultParent()); } finally { mxMorphing morph = new mxMorphing(graphComponent, 20, 1.2, 20); morph.addListener(mxEvent.DONE, new mxIEventListener() { @Override public void invoke(Object arg0, mxEventObject arg1) { graph.getModel().endUpdate(); // fitViewport(); } }); BufferedImage image; image = mxCellRenderer.createBufferedImage(graph, null, 2, Color.WHITE, true, null); Document d = mxCellRenderer.createVmlDocument(graph, null, 1, Color.WHITE, null); pathToWeb = getServletContext().getRealPath(File.separator); System.out.println("pathtoweb:\t" + pathToWeb); fileWPath = pathToWeb + "genImg\\" + userid + docid + ".png"; System.out.println("filewpath:\t" + fileWPath); //System.out.println(pathToWeb + userid + docid + ".svg"); ImageIO.write(image, "PNG", new File(fileWPath)); XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream( new FileOutputStream(new File(pathToWeb + "genXML\\" + userid + docid + ".xml")))); encoder.writeObject(graph); encoder.close(); morph.startAnimation(); } graphComponent.setConnectable(false); fr.getRootPane().setBorder(BorderFactory.createMatteBorder(4, 4, 4, 4, Color.WHITE)); // Inhibit edge creation in the graph. fr.getContentPane().add(graphComponent); //fr.setVisible(true); request.setAttribute("docidM", docid); request.setAttribute("useridM", userid); request.setAttribute("colCountM", colct); request.setAttribute("rowCountM", rowct); request.setAttribute("fileLinkM", fileWPath); request.setAttribute("pathToWebM", pathToWeb); System.out.println("Iteration Complete"); getServletContext().getRequestDispatcher("/success.jsp").forward(request, response); }
From source file:com.appspot.backstreetfoodies.server.XLSParser.java
License:Apache License
public XLSParser(InputStream inputStream, int sheetIndex, int numColumnsExpected) throws IOException { HSSFWorkbook workbook = new HSSFWorkbook(inputStream); HSSFSheet sheet = workbook.getSheetAt(sheetIndex); Iterator<Row> rowIterator = sheet.iterator(); Iterator<Cell> cellIterator; numColumns = numColumnsExpected;//from w w w . j ava 2s . com while (rowIterator.hasNext()) { int numCellsInRow = 0; Row row = rowIterator.next(); cellIterator = row.cellIterator(); ArrayList<String> temp = new ArrayList<String>(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); switch (cell.getCellType()) { case Cell.CELL_TYPE_NUMERIC: if (!String.valueOf(cell.getNumericCellValue()).isEmpty()) { numCellsInRow++; temp.add(String.valueOf(cell.getNumericCellValue())); } break; case Cell.CELL_TYPE_STRING: if (!cell.getStringCellValue().isEmpty()) { numCellsInRow++; temp.add(cell.getStringCellValue().trim()); } break; default: break; } } if (numCellsInRow == numColumnsExpected) { xlsData.add(temp); } } }