List of usage examples for org.apache.poi.ss.usermodel FormulaEvaluator evaluateAll
void evaluateAll();
From source file:opn.greenwebs.FXMLDocumentController.java
@FXML private void handleInjectExcel(ActionEvent event) { XSSFWorkbook wb = createWorkbook();//w w w .j ava2s. c om FormulaEvaluator evaluator; inject(wb, cmbSales.getValue(), 5, 14); Instant instant = Instant.from(dteOrderDate.getValue().atStartOfDay(ZoneId.systemDefault())); inject(wb, Date.from(instant), 3, 14); inject(wb, txtCustomer.getText(), 10, 2); inject(wb, txtAddress.getText(), 11, 2); inject(wb, txtCity.getText(), 12, 2); inject(wb, txtProvince.getText(), 13, 2); inject(wb, txtPhone.getText(), 14, 2); inject(wb, txtContact.getText(), 15, 2); inject(wb, txtFax.getText(), 14, 4); inject(wb, txtEmail.getText(), 16, 2); inject(wb, txtPO.getText(), 15, 4); if (chkGST.isSelected()) { inject(wb, "Y", 36, 8); } else { inject(wb, "N", 36, 8); } if (chkPST.isSelected()) { inject(wb, "Y", 37, 8); } else { inject(wb, "N", 37, 8); } int nRow = 21; for (Object obj : tblItems.getItems()) { if (obj instanceof Item) { Item item = (Item) obj; inject(wb, item.getSdpQty(), nRow, 0); inject(wb, item.getSspMfr(), nRow, 1); inject(wb, item.getSspSKU(), nRow, 2); inject(wb, item.getSspDescrip(), nRow, 3); inject(wb, item.getSspSupplier(), nRow, 5); inject(wb, item.getSspSupPart(), nRow, 6); inject(wb, item.getSspSerial(), nRow, 7); inject(wb, item.getSdpSalePrice(), nRow, 8); inject(wb, item.getSdpEOS(), nRow++, 9); } } evaluator = wb.getCreationHelper().createFormulaEvaluator(); evaluator.evaluateAll(); wb.setForceFormulaRecalculation(true); try { File fTemp = createFilename("Q", txtCustomer.getText()); inject(wb, fTemp.getName().substring(0, 7), 46, 14); try (FileOutputStream fos = new FileOutputStream(fTemp)) { wb.write(fos); } Alert alert = new Alert(AlertType.INFORMATION, "Would you like to open the file? Choose no to print", ButtonType.YES, ButtonType.NO); alert.showAndWait().ifPresent(response -> { CustomerDB cust = new CustomerDB(); cust.setStrCustomer(txtCustomer.getText()); cust.setStrAddress(txtAddress.getText()); cust.setStrCity(txtCity.getText()); cust.setStrProvince(txtProvince.getText()); cust.setStrPhone(txtPhone.getText()); cust.setStrEmail(txtEmail.getText()); cust.setStrFax(txtFax.getText()); cust.setStrContact(txtContact.getText()); cust.setStrPO(txtPO.getText()); cust.setBooGST(chkGST.isSelected()); cust.setBooPST(chkPST.isSelected()); if ((aDataCust.query("txtCustomer", cust.getStrCustomer()).isEmpty()) && (aDataCust.query("txtPhone", cust.getStrPhone()).isEmpty())) { aDataCust.addItem(cust); CustData.add(cust.createCustomer()); } if (response == ButtonType.YES) { try { Desktop.getDesktop().open(fTemp); } catch (IOException ex) { Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex); } } else { try { Desktop.getDesktop().print(fTemp); } catch (IOException ex) { Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex); } } }); } catch (FileNotFoundException ex) { logger.info(ex.getLocalizedMessage()); } catch (IOException ex) { logger.info(ex.getLocalizedMessage()); } }