Note that there are some explanatory texts on larger screens.

plurals
  1. POsave contents of excel file before reading it using poi
    primarykey
    data
    text
    <p>I am making an application that created 2 new spreadsheet files. The idea is for the user to enter data into this excel files and make program read it. However the problem is that, after the data has been entered and saved (pressing the save icon in excel) the program just does not see this data,it remains as if nothing was entered there. What I need is somehow to save it programmicaly using poi. Any suggestions? </p> <p>Here is the code:</p> <p>my gui class:</p> <pre><code>public class GUI extends JFrame{ private Panel buttonHolder; private Button crossReference; private Button generateHPD; private CrossReference ref = null; private XSSFWorkbook log; private XSSFWorkbook sheet; private XSSFSheet logSheet; private XSSFSheet sSheet; public GUI () throws Exception{ this.setTitle("NYWM Cross Reference Application"); this.setSize(400,100); this.setVisible(true); this.setLocationRelativeTo(null); buttonHolder = new Panel (new BorderLayout()); this.add(buttonHolder); crossReference = new Button ("CrossReference"); generateHPD = new Button ("Generate HPD"); buttonHolder.add(crossReference, BorderLayout.NORTH); buttonHolder.add(generateHPD, BorderLayout.SOUTH); logSheet = createExcelSheet ("D:/Log.xlsx", "Log"); sSheet = createExcelSheet("D:/Spreadsheet.xlsx", "Spreadsheet"); crossReference.addActionListener(new crossReferenceButtonListener()); generateHPD.addActionListener(new generateHPDButtonListener()); } public XSSFSheet getLogSheet() { return logSheet; } public XSSFSheet getsSheet() { return sSheet; } private XSSFSheet createExcelSheet (String path, String fileName) throws Exception{ try{ FileOutputStream out = new FileOutputStream (path); XSSFWorkbook wb = new XSSFWorkbook (); XSSFSheet sheet = wb.createSheet(fileName); wb.write(out); Process p = Runtime.getRuntime().exec( "rundll32 url.dll, FileProtocolHandler " + path); return sheet; } catch (Exception e){ throw e; } } private class crossReferenceButtonListener implements ActionListener { public void actionPerformed (ActionEvent event){ try { XSSFSheet sSheet = getsSheet(); XSSFSheet logSheet = getLogSheet(); ref = new CrossReference(); //ref = new CrossReference (log.getSheetAt(0), sheet.getSheetAt(0)); ref.CrossReferenceCont(logSheet, sSheet); ref.CrossRef(); JOptionPane.showMessageDialog(null, "Cross Reference was successful!"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } </code></pre> <p>CrossReferenceCont method</p> <pre><code>public void CrossReferenceCont(XSSFSheet wsLog, XSSFSheet wsSheet) throws Exception { log = new PropertyList(wsLog); sheet = new PropertyList(wsSheet); logArray = log.getPropertyList(); sheetArray = log.getPropertyList(); } </code></pre> <p>property list method:</p> <pre><code>public PropertyList(XSSFSheet ws) throws Exception{ try{ //File excel = new File (excelFilePath); //FileInputStream fis = new FileInputStream (excel); // XSSFWorkbook wb = new XSSFWorkbook(fis); int rowNum = ws.getLastRowNum(); System.out.println ("Number of rows is " + rowNum); propertyList = new ArrayList &lt;Property&gt;(rowNum); for (int i = 0; i &lt;= rowNum; i++){ property = new Property (ws, i); propertyList.add(new Property(property)); } </code></pre> <p>and finaly the property method: here where program crashes</p> <pre><code>public Property(XSSFSheet sheet, int row) throws FileNotFoundException { Cell cell = sheet.getRow(row).getCell(0); //crashes here, nullPointer int type = cell.getCellType(); //setting the address------------------------------------------------- if (type == Cell.CELL_TYPE_STRING) { address = cell.getStringCellValue(); } else if (type == Cell.CELL_TYPE_NUMERIC) { int addressTemp = (int) cell.getNumericCellValue(); address = String.valueOf(addressTemp); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload