用apache poi导入xls

时间:2017-11-27 19:15:41

标签: java excel apache-poi

我已经完成了一个java应用程序,我可以将其导出到应用程序内部的xls数据文件。问题是现在我需要将它们导回并使用某种循环重复将xls文件中已更改的数据更改为应用程序以更改所有数据,使用代码列作为更改的参考在申请中

导出代码

public void importStockToXls() throws IOException // Import XLS files
    {
        // Chooser properties
        chooser = new JFileChooser();
        chooser.setDialogTitle("Importar Arquivos XLS");
        chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        chooser.setFileFilter(null);

        int showOpenDialog = chooser.showOpenDialog(chooser.getParent()); // Stores user choice

        if (showOpenDialog == JFileChooser.APPROVE_OPTION) // Checks the user's choice
        {
            file = chooser.getSelectedFile(); // Get the file way if approved
        }

        fis = new FileInputStream(file); // Points to an instance of the file

        workbook = new HSSFWorkbook(fis); // Passing FIS to workbook representation

        sheet = workbook.getSheetAt(0); // Pick the page to be used

        // TODO
        fis.close(); // Closes instance flow

导入代码的开头,我无法更多地思考我能做什么

public void change(Stock obj) throws Exception
    {
        // Retrieve the code
        int code = obj.getCode();

        // Run to entire list behind the same recovered code
        for (Stock search : stockList)
        {
            // If the code find is the same recovered change data
            if (search.getCode() == code)
            {
                // Retrieve the information on the fields and change data
                search.setProductName(obj.getProductName());
                search.setSalePrice(obj.getSalePrice());
                search.setCostPrice(obj.getCostPrice());
                search.setNetProfit(obj.getNetProfit());

                // Saving changes
                writeFiles();
            }
        }
    }

更改功能

KeyPress

0 个答案:

没有答案