0

我无法使用我的 java 代码更新 Excel 文件 (.xlsx)。你能告诉我我在哪里犯错吗?它抛出一个NullPointerException. 使用 POI Apache jars.Using Office 2016 for Excel

public class test_extra1 {
    public static void main(String[] args) throws Exception {
        //excel code
        File src=new File("C:\\test.xlsx");
        FileInputStream fis=new FileInputStream(src);
        XSSFWorkbook wb=new XSSFWorkbook(fis);
        XSSFSheet sh1= wb.getSheetAt(0);

        String[] field_name = {"field1","field2"};

        String isChecked ="Checked",temp;

        int i;
        for(i=0;i<2;i++){

            System.out.println(i);
            System.out.println("Checkbox not checked--"+isChecked);
            temp = field_name[i];
            System.out.println("temp----"+temp);
            //error comes at below line
            sh1.getRow(i+1).getCell(i+3).setCellValue("No");
            sh1.getRow(i+1).createCell(i+3).setCellValue("No");
            sh1.getRow(i+1).createCell(i+2).setCellValue(temp);

        }
        FileOutputStream fout=new FileOutputStream(new File("C:\\test1.xlsx"));
        wb.write(fout);
        fout.close();

    }
}
4

0 回答 0