I want to rename a Excel Sheet, most of the time is ok, but yesterday I rename a sheet with IFERROR function, throw a NullPointException.
Can you provide details, i.e. a sample file and a piece of self-contained code which reproduces the problem?
Test Excel(xlsx): New one Excel file on windows platform, open it, select Cell D4 and set cell value to "=IFERROR(VLOOKUP(C4,'Country List'!$A$1:$B$251,2,0),"")"(except outside "). 'Country List' is a sheet, contains the conntry name list, col A full contry name, col B abbreviation. Test Code: @Test public void testRenameSheet() throws IOException, InvalidFormatException { String filePath = "D:\\win7temp\\testiferror.xlsx"; Workbook book = WorkbookFactory.create(new File(filePath)); Sheet sheet = book.getSheetAt(0); System.out.printf("origin name:%s \n", sheet.getSheetName()); book.setSheetName(0, "NewSheetName"); System.out.printf("rename over!"); } Output is: origin name:Sheet1 java.lang.NullPointerException at org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils.updatePtg(XSSFFormulaUtils.java:128) at org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils.updateFormula(XSSFFormulaUtils.java:98) at org.apache.poi.xssf.usermodel.helpers.XSSFFormulaUtils.updateSheetName(XSSFFormulaUtils.java:78) at org.apache.poi.xssf.usermodel.XSSFWorkbook.setSheetName(XSSFWorkbook.java:1361) at com.lrm.test.POICopyUtilTest.testRenameSheet(POICopyUtilTest.java:36)
Created attachment 32851 [details] test iferror function on POI 3.11 when set new sheet name.
(In reply to Dominik Stadler from comment #1) > Can you provide details, i.e. a sample file and a piece of self-contained > code which reproduces the problem? I test it on POI 3.12 is ok.