List of usage examples for org.apache.poi.xssf.usermodel XSSFSheet getLastRowNum
@Override public int getLastRowNum()
From source file:com.envisioncn.it.super_sonic.showcase.evaluation.biz.EvaluationService.java
License:Open Source License
public void export(HttpServletResponse response, HttpServletRequest request, List<EvaluationPageBean> lists, String code, String condition) throws Exception { //1.excel//from www .j av a 2s. c o m XSSFWorkbook xssfWorkbook = new XSSFWorkbook(); //2.sheet //HSSFSheet sheet = hssfWorkbook.createSheet(); XSSFSheet sheet = xssfWorkbook.createSheet("Challenger"); //3.? XSSFRow headerRow = sheet.createRow(0); // // ExcelUtils.createTitle(headerRow, code); // lists = getOrderEvas(lists);//? lists = getEvaList(lists, code, condition); for (EvaluationPageBean pb : lists) { XSSFRow dataRow = sheet.createRow(sheet.getLastRowNum() + 1); // dataRow.createCell(0).setCellValue(pb.getPeriod()); dataRow.createCell(1).setCellValue(pb.getManagerId()); dataRow.createCell(2).setCellValue(pb.getManager()); dataRow.createCell(3).setCellValue(pb.getManagerLocation()); dataRow.createCell(4).setCellValue(pb.getManagerDivision()); dataRow.createCell(5).setCellValue(pb.getManagerDepartment()); dataRow.createCell(6).setCellValue(pb.getUserId()); dataRow.createCell(7).setCellValue(pb.getUser()); dataRow.createCell(8).setCellValue(pb.getUserLocation()); dataRow.createCell(9).setCellValue(pb.getUserDivision()); dataRow.createCell(10).setCellValue(pb.getUserDepartment()); dataRow.createCell(11).setCellValue(pb.getPriseWill()); dataRow.createCell(12).setCellValue(pb.getPriseWisdom()); dataRow.createCell(13).setCellValue(pb.getPriseLove()); dataRow.createCell(14).setCellValue(pb.getProsWill()); dataRow.createCell(15).setCellValue(pb.getProsWisdom()); dataRow.createCell(16).setCellValue(pb.getProsLove()); dataRow.createCell(17).setCellValue(pb.getCts()); dataRow.createCell(18).setCellValue(pb.getRemark()); } // ExcelUtils.downFile(response, request, xssfWorkbook); }
From source file:com.esd.cs.common.XExcelSheetParser.java
License:Open Source License
public List<List<Object>> getDatasInSheet(int sheetNumber) { List<List<Object>> result = new ArrayList<List<Object>>(); // sheet// w ww . j a v a 2 s . com XSSFSheet sheet = workbook.getSheetAt(sheetNumber); // sheet int rowCount = sheet.getLastRowNum(); logger.info("found excel rows count:" + rowCount); if (rowCount < 1) { return result; } // ??row for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) { // XSSFRow row = sheet.getRow(rowIndex); if (null != row) { List<Object> rowData = new ArrayList<Object>(); // ? int cellCount = row.getLastCellNum(); // ??cell for (short cellIndex = 0; cellIndex < cellCount; cellIndex++) { XSSFCell cell = row.getCell(cellIndex); // ?? Object cellStr = this.getCellString(cell); rowData.add(cellStr); } result.add(rowData); } } return result; }
From source file:com.excel.javafx.frames.MainFrame.java
public boolean compareTwoSheets(XSSFSheet sheet1, XSSFSheet sheet2) { sourceRow = new ArrayList<String>(); destRow = new ArrayList<String>(); int firstRow1 = sheet1.getFirstRowNum() + 1; int lastRow1 = sheet1.getLastRowNum(); boolean equalSheets = true; for (int i = firstRow1; i <= lastRow1; i++) { System.out.println("\n\nComparing Row " + i); XSSFRow row1 = sheet1.getRow(i); XSSFRow row2 = sheet2.getRow(i); if (!compareTwoRows(row1, row2)) { equalSheets = false;//from www.j a v a2s .co m System.out.println("Row " + i + " - Not Equal"); sourceRow.add("Row" + i); destRow.add("Row" + i); } else { System.out.println("Row " + i + " - Equal"); } } return equalSheets; }
From source file:com.FuntionLibrary.java
public void writetoExcel(String Name, String EmailId, String Password, String MobileNo, XSSFSheet sheet, String MailPaswd) throws InvalidFormatException, IOException { try {//ww w . j av a 2 s . c o m //String excelFileName = "";//name of excel file int r = sheet.getLastRowNum(); XSSFRow r1 = sheet.createRow(0); XSSFCell Srnocell = r1.createCell(0); Srnocell.setCellValue("Name"); XSSFCell actioncell = r1.createCell(1); actioncell.setCellValue("EmailId"); XSSFCell loccell = r1.createCell(2); loccell.setCellValue("Password"); XSSFCell valuecell = r1.createCell(3); valuecell.setCellValue("Mobile Number"); XSSFCell EmailPassword = r1.createCell(4); EmailPassword.setCellValue("Email Password"); XSSFRow row = sheet.createRow(r + 1); //iterating c number of columns XSSFCell cell = row.createCell(0); cell.setCellValue(Name); System.out.println(Name); XSSFCell cell1 = row.createCell(1); cell1.setCellValue(EmailId); System.out.println(EmailId); XSSFCell cell2 = row.createCell(2); cell2.setCellValue(Password); System.out.println(Password); XSSFCell cell3 = row.createCell(3); cell3.setCellValue(MobileNo); System.out.println(MobileNo); XSSFCell cell4 = row.createCell(4); cell4.setCellValue(MailPaswd); System.out.println(MailPaswd); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Oops Something Went wrong Error - > " + e.getMessage()); } }
From source file:com.heimaide.server.common.utils.excel.ExportExcel.java
License:Open Source License
private void exportFile(List<String> list, String rootPath, HttpServletResponse response, List<List<Object>> bodyList) throws FileNotFoundException, IOException { String importFileName = rootPath + "WEB-INF" + File.separator + "xlsx" + File.separator + "order.xlsx"; String tmpDir = rootPath + "tmpDir" + File.separator; XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(importFileName)); this.styles = createStyles(wb); //?excel? /* w w w . j a va 2 s . com*/ //??sheet XSSFSheet sheet = wb.getSheetAt(0); XSSFCell cell1 = sheet.getRow(1).getCell(0); String cell1str = cell1.getStringCellValue(); //???? cell1str = cell1str.replace("X", list.get(0)); cell1.setCellValue(cell1str); XSSFCell cell2 = sheet.getRow(2).getCell(0); String cell2str = cell2.getStringCellValue(); //?? cell2str = cell2str.replace("X", list.get(1)); //? cell2str = cell2str.replace("Y", list.get(2)); //??? cell2str = cell2str.replace("Z", list.get(3)); cell2.setCellValue(cell2str); XSSFCell cell3 = sheet.getRow(3).getCell(12); String cell3str = cell3.getStringCellValue(); cell3str = cell3str.replace("XX", list.get(4)); cell3.setCellValue(cell3str); XSSFCell cell4 = sheet.getRow(sheet.getLastRowNum() - 1).getCell(0); String cell4str = cell4.getStringCellValue(); cell4str = cell4str.replace("X", list.get(5)); cell4.setCellValue(cell4str); XSSFCell cell5 = sheet.getRow(sheet.getLastRowNum() - 4).getCell(12); XSSFCell cell6 = sheet.getRow(sheet.getLastRowNum() - 4).getCell(13); String str1 = String.valueOf(list.get(6)); String str2 = String.valueOf(list.get(7)); str1 = str1.substring(0, str1.indexOf(".")); str2 = str2.substring(0, str2.indexOf(".")); cell5.setCellValue(str1); cell6.setCellValue(str2); XSSFCell cell7 = sheet.getRow(sheet.getLastRowNum() - 3).getCell(12); XSSFCell cell8 = sheet.getRow(sheet.getLastRowNum() - 3).getCell(13); cell7.setCellValue(Double.parseDouble(list.get(6)) / 10); cell8.setCellValue(Double.parseDouble(list.get(7)) / 10); // int columnNum =sheet.getRow(3).getLastCellNum(); // int column =0; // for(int i=0;i<columnNum;i++) // { // System.out.println("==="+sheet.getRow(3).getCell(i).getStringCellValue()); // column =i; // } int num = 5; for (int i = 0; i < bodyList.size(); i++) { List<Object> strList = bodyList.get(i); sheet.shiftRows(num, bodyList.size() + num, 1, true, false); sheet.createRow(num); for (int j = 0; j < strList.size(); j++) { Row row = sheet.getRow(num); addCell(row, j, strList.get(j)); // Cell cell = row.createCell(j); // cell.setCellValue(strList.get(j)); } num++; } //?? String tmpName = tmpDir + "tmp_hmd.xlsx"; File dirFile = new File(tmpDir); if (!dirFile.exists()) { dirFile.mkdir(); } File tmpFile = new File(tmpName); FileOutputStream fos = new FileOutputStream(tmpFile); wb.write(fos); XSSFWorkbook wb1 = new XSSFWorkbook(new FileInputStream(tmpName)); response.reset(); response.setContentType("application/octet-stream; charset=utf-8"); response.setHeader("Content-Disposition", "attachment; filename=" + Encodes.urlEncode("?" + list.get(0) + "?.xlsx")); wb1.write(response.getOutputStream()); tmpFile.delete(); }
From source file:com.knsi.PerformanceFrame.java
public void createUI() { JDialog pf = new JDialog(this, "Performance", true); pf.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/resources/logo.png"))); JTabbedPane perpanel = new JTabbedPane(); JPanel addp = new JPanel(); JPanel viewp = new JPanel(); perpanel.addTab(" Add New Test Details ", addp); //perpanel.addTab(" View Student Performance ", viewp); addp.setBackground(colorSecondary);// w w w . j a v a 2s .com viewp.setBackground(colorSecondary); setaddTab(addp); submitBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { System.out.println(t4.getSelectedItem()); hasStudentmarks.setVisible(false); if (t4.getSelectedItem().equals("")) { hasStudents.setText( "<html><div style=\"color: red;\">" + "No batch has been selected" + "</html>"); hasStudents.setVisible(true); } else if (tName.getText().equalsIgnoreCase("")) { hasStudents.setText("<html><div style=\"color: red;\">" + "Invalid or No Test Name Entered" + "</html>"); hasStudents.setVisible(true); } else if (!maxMarks.getText().matches("^[1-9]\\d*$")) { hasStudents.setText("<html><div style=\"color: red;\">" + "Marks should only consist of digits" + "</html>"); hasStudents.setVisible(true); } else if (isValid) { hasStudents.setText("<html><div style=\"color: red;\">" + "Cannot simultaneously create two performances" + "</html>"); hasStudents.setVisible(true); } else if (fileHasValues((String) t4.getSelectedItem())) { hasStudents.setText( "<html><div style=\"color: red;\">" + "No Students in this batch" + "</html>"); hasStudents.setVisible(true); System.out.println(""); } else { isValid = true; hasStudents.setText("<html><div style=\"color: green;\">" + "Performance created successfully" + "</html>"); hasStudents.setVisible(true); outof.setText(maxMarks.getText()); try { WritePerformance(); } catch (Exception ee) { ee.printStackTrace(); } } } catch (IOException ex) { Logger.getLogger(PerformanceFrame.class.getName()).log(Level.SEVERE, null, ex); } } private boolean fileHasValues(String string) throws IOException { XSSFWorkbook details = new XSSFWorkbook(new FileInputStream(new File(string + ".xlsx"))); XSSFSheet spreadsheet1 = details.getSheet("details"); return spreadsheet1.getLastRowNum() == 0; } }); NexttBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("the next student is:::"); if (!isValid) { hasStudentmarks.setText( "<html><div style=\"color: red;\">" + "Please Create a Performance" + "</html>"); hasStudentmarks.setVisible(true); } else if (!studentmarks.getText().matches("^[1-9]\\d*$") || Integer.parseInt(studentmarks.getText()) > Integer.parseInt(maxMarks.getText())) { hasStudentmarks.setText("<html><div style=\"color: red;\">" + "Invalid Entry" + "</html>"); hasStudentmarks.setVisible(true); } else if (itercount == nameList.size()) { hasStudentmarks.setText("<html><div style=\"color: green;\">" + "All Student\'s Performance has been updated" + "</html>"); hasStudentmarks.setVisible(true); isValid = false; itercount = 0; } else { NexttBtn.setText("<html><div style=\"color: white;\">" + "Next Student" + "</html>"); studentname.setText(nameList.get(itercount).getCell(0).getStringCellValue()); studentid.setText(nameList.get(itercount).getCell(1).getStringCellValue()); marksList.add(studentmarks.getText()); itercount++; } /* for (XSSFRow row : nameList) { System.out.println(row.getCell(0).getStringCellValue()+" "+row.getCell(1).getStringCellValue()); System.out.println(nameList.get(itercount).getCell(0).getStringCellValue()+""+nameList.get(itercount).getCell(1).getStringCellValue()); }*/ WritePerformanceDB.WriteTo(marksList); } }); pf.add(perpanel, BorderLayout.CENTER); pf.setSize(960, 680); //pf.setBounds(0,0,1060,720); pf.setLocationRelativeTo(null); pf.setVisible(true); }
From source file:com.knsi.WriteDB.java
public static void writeTo(JTextField labels[], String pof) { try {// ww w.j a va 2 s . c o m File db = new File(labels[4].getText() + ".xlsx"); System.out.println(db.getAbsolutePath()); Date d = new Date(); System.out.println(d.toString()); FileInputStream dbStream = new FileInputStream(db); XSSFWorkbook details = new XSSFWorkbook(dbStream); XSSFSheet spreadsheet1 = details.getSheet("details"); XSSFSheet spreadsheet2 = details.getSheet("Fees"); XSSFSheet spreadsheet3 = details.getSheet("Performance"); XSSFSheet spreadsheet4 = details.getSheet("Attendence"); System.out.println(spreadsheet1.getLastRowNum() + "------------" + spreadsheet2.getLastRowNum()); //Create row object XSSFRow row1, row2, row3, row4; //This data needs to be written (Object[]) String obj1[] = new String[14]; int j = 1; for (int i = 0; i <= 12; i++) { if (i == 4) { continue; } if (labels[i].getText().equalsIgnoreCase("")) { obj1[j] = "N/A"; } else { obj1[j] = labels[i].getText(); } j++; } //obj1[0]=Integer.toString(spreadsheet1.getLastRowNum()+1); obj1[0] = getRegId(obj1[0], Integer.toString(spreadsheet1.getLastRowNum() + 1), labels[4].getText(), pof); obj1[13] = d.toString(); System.out.println("The details for the details sheet is:"); for (int i = 0; i < 14; i++) { System.out.println(obj1[i]); } String obj2[] = new String[4]; obj2[0] = obj1[0]; obj2[1] = labels[13].getText(); obj2[2] = labels[14].getText(); obj2[3] = labels[13].getText(); System.out.println("The details for the fees sheet is:"); for (int i = 0; i < 4; i++) { System.out.println(obj2[i]); } String obj3[] = new String[2]; obj3[0] = obj1[0]; obj3[1] = obj1[1]; int rowid1 = spreadsheet1.getLastRowNum() + 1; int rowid2 = spreadsheet2.getLastRowNum() + 1; int rowid3 = spreadsheet3.getLastRowNum() + 1; int rowid4 = spreadsheet4.getLastRowNum() + 1; row1 = spreadsheet1.createRow(rowid1); row2 = spreadsheet2.createRow(rowid2); row3 = spreadsheet3.createRow(rowid3); row4 = spreadsheet4.createRow(rowid4); int cellid = 0; for (String obj : obj1) { Cell cell = row1.createCell(cellid++); cell.setCellValue(obj); } cellid = 0; for (String obj : obj2) { Cell cell = row2.createCell(cellid++); cell.setCellValue(obj); } cellid = 0; for (String obj : obj3) { Cell cell = row3.createCell(cellid); cell.setCellValue(obj); Cell cell2 = row4.createCell(cellid); cell2.setCellValue(obj); cellid++; } //Write the workbook in file system FileOutputStream out = new FileOutputStream(db); details.write(out); out.close(); System.out.println(db + " written successfully"); s = db.getAbsolutePath(); } catch (Exception ee) { s = ee.getMessage(); System.out.println(s); } }
From source file:com.krawler.spring.importFunctionality.ImportUtil.java
License:Open Source License
/** * Generate the preview of the xls grid//from w w w . ja v a 2s . co m * @param filename * @param sheetNo * @return * @throws FileNotFoundException * @throws IOException * @throws JSONException */ public static JSONObject parseXLSX(String filename, int sheetNo) throws FileNotFoundException, IOException, JSONException { JSONObject jobj = new JSONObject(); FileInputStream fs = new FileInputStream(filename); XSSFWorkbook wb = new XSSFWorkbook(fs); XSSFSheet sheet = wb.getSheetAt(sheetNo); //DateFormat sdf = new SimpleDateFormat(df); int startRow = 0; int maxRow = sheet.getLastRowNum(); int maxCol = 0; int noOfRowsDisplayforSample = 20; if (noOfRowsDisplayforSample > sheet.getLastRowNum()) { noOfRowsDisplayforSample = sheet.getLastRowNum(); } JSONArray jArr = new JSONArray(); try { for (int i = 0; i <= noOfRowsDisplayforSample; i++) { XSSFRow row = sheet.getRow(i); JSONObject obj = new JSONObject(); JSONObject jtemp1 = new JSONObject(); if (row == null) { continue; } if (i == 0) { maxCol = row.getLastCellNum(); } for (int cellcount = 0; cellcount < maxCol; cellcount++) { XSSFCell cell = row.getCell(cellcount); CellReference cref = new CellReference(i, cellcount); String colHeader = cref.getCellRefParts()[2]; String val = null; if (cell != null) { switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { val = Long.toString(cell.getDateCellValue().getTime()); } else { val = dfmt.format(cell.getNumericCellValue()); } break; case XSSFCell.CELL_TYPE_STRING: val = ImportUtil.cleanHTML(cell.getRichStringCellValue().getString()); break; } } if (i == 0) { // List of Headers (Consider first row as Headers) if (val != null) { jtemp1 = new JSONObject(); jtemp1.put("header", val == null ? "" : val); jtemp1.put("index", cellcount); jobj.append("Header", jtemp1); } } obj.put(colHeader, val); } // if(obj.length()>0){ //Don't show blank row in preview grid[SK] jArr.put(obj); // } } } catch (Exception ex) { Logger.getLogger(ImportHandler.class.getName()).log(Level.SEVERE, null, ex); } jobj.put("startrow", startRow); jobj.put("maxrow", maxRow); jobj.put("maxcol", maxCol); jobj.put("index", sheetNo); jobj.put("data", jArr); jobj.put("filename", filename); jobj.put("msg", "XLSX has been successfully uploaded"); jobj.put("lsuccess", true); jobj.put("valid", true); return jobj; }
From source file:com.krawler.spring.importFunctionality.ImportUtil.java
License:Open Source License
/** * @param filename//from w w w .j a va2 s .c om * @param sheetNo * @param startindex * @param importDao * @return * @throws ServiceException */ public static void dumpXLSXFileData(String filename, int sheetNo, int startindex, ImportDAO importDao, HibernateTransactionManager txnManager) throws ServiceException { boolean commitedEx = false; DefaultTransactionDefinition def = new DefaultTransactionDefinition(); def.setName("import_Tx"); def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED); TransactionStatus status = txnManager.getTransaction(def); Session session = txnManager.getSessionFactory().getCurrentSession(); try { String destinationDirectory = storageHandlerImpl.GetDocStorePath() + "xlsfiles"; FileInputStream fs = new FileInputStream(destinationDirectory + "/" + filename); XSSFWorkbook wb = new XSSFWorkbook(fs); XSSFSheet sheet = wb.getSheetAt(sheetNo); //DateFormat sdf = new SimpleDateFormat(df_full); int maxRow = sheet.getLastRowNum(); int maxCol = 0; String tableName = importDao.getTableName(filename); int flushCounter = 0; for (int i = startindex; i <= maxRow; i++) { XSSFRow row = sheet.getRow(i); if (row == null) { continue; } if (i == startindex) { maxCol = row.getLastCellNum(); //Column Count } ArrayList<String> dataArray = new ArrayList<String>(); JSONObject dataObj = new JSONObject(); for (int j = 0; j < maxCol; j++) { XSSFCell cell = row.getCell(j); String val = null; if (cell == null) { dataArray.add(val); continue; } String colHeader = new CellReference(i, j).getCellRefParts()[2]; switch (cell.getCellType()) { case XSSFCell.CELL_TYPE_NUMERIC: if (DateUtil.isCellDateFormatted(cell)) { val = Long.toString(cell.getDateCellValue().getTime()); } else { val = dfmt.format(cell.getNumericCellValue()); } break; case XSSFCell.CELL_TYPE_STRING: val = ImportUtil.cleanHTML(cell.getRichStringCellValue().getString()); break; } dataObj.put(colHeader, val); dataArray.add(val); //Collect row data } //Insert Query if (dataObj.length() > 0) { // Empty row check (if lenght==0 then all columns are empty) importDao.dumpFileRow(tableName, dataArray.toArray()); if (flushCounter % 30 == 0) { session.flush(); session.clear(); } flushCounter++; } } try { txnManager.commit(status); } catch (Exception ex) { commitedEx = true; throw ex; } } catch (IOException ex) { throw ServiceException.FAILURE("dumpXLSXFileData: " + ex.getMessage(), ex); } catch (Exception ex) { if (!commitedEx) { //if exception occurs during commit then dont call rollback txnManager.rollback(status); } throw ServiceException.FAILURE("dumpXLSXFileData: " + ex.getMessage(), ex); } }
From source file:com.mycompany.owl.fxml.FXMLFilterController.java
@FXML public void saveFileTransformed() throws FileNotFoundException, IOException { FileInputStream fileInputStream = new FileInputStream(file); XSSFWorkbook workbookToModify = new XSSFWorkbook(fileInputStream); XSSFSheet sheet = workbookToModify.getSheetAt(0); XSSFRow row;//from www .ja v a2 s.co m String atcMask = getATCMask(); ArrayList<String> firstRowCells = new ArrayList<>(); for (int i = 0; i <= sheet.getLastRowNum(); i++) { row = sheet.getRow(i); for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) { System.out.print(row.getCell(j).getRawValue() + "\t"); if (i == 0) firstRowCells.add(row.getCell(j).getRawValue()); } System.out.println(""); } XSSFWorkbook transformedWB = new XSSFWorkbook(); transformedWB.createSheet(); XSSFSheet transformedS = transformedWB.getSheetAt(0); for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) { transformedS.createRow(i); } /* elkezdnk vgigmenni az alap sheeten ha megvan az index, ahol van match, akkor createrow(0) s bele a tbbit 0. helyre */ ArrayList<Integer> matchingIndexes = matchingIndexes(firstRowCells); for (int i = 0; i <= sheet.getLastRowNum(); i++) { row = sheet.getRow(i); int sum = 0; for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) { if (i != 0 && j != 0) { for (int index : matchingIndexes) { if (index == j) { sum += Integer.valueOf(row.getCell(j).getRawValue()); } } } } System.out.println(sum); if (i > 0) { row = sheet.getRow(i); row.createCell(row.getLastCellNum()).setCellValue(sum); } } for (int index : matchingIndexes) { for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) { row = sheet.getRow(i); row.getCell(index).setCellValue(3.14159); } /*for (int i = 0; i < row.getPhysicalNumberOfCells(); i++) { if(i == index){ for (int j = 0; j < sheet.getPhysicalNumberOfRows(); j++) { row = sheet.getRow(j); transformedS.getRow(j).createCell(transformedColumnCount).setCellValue( row.getCell(i).getRawValue() ); } transformedColumnCount++; } }*/ } int columnsInTransformed = 0; for (int i = 0; i < sheet.getPhysicalNumberOfRows(); i++) { row = sheet.getRow(i); for (int j = 0; j < row.getPhysicalNumberOfCells(); j++) { String cellValue = row.getCell(j).getRawValue(); if (!cellValue.equals("3.14159")) { transformedS.getRow(i).createCell(columnsInTransformed); transformedS.getRow(i).getCell(columnsInTransformed).setCellValue(cellValue); columnsInTransformed++; } } columnsInTransformed = 0; } row = transformedS.getRow(0); row.createCell(row.getLastCellNum()).setCellValue(atcMask); File file = fileChooser.showSaveDialog(new Stage()); if (file != null) { try { FileOutputStream fop = new FileOutputStream(file); transformedWB.write(fop); fop.close(); } catch (Exception e) { System.out.println("Exception: " + e.getMessage()); } } }