You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2011/02/28 04:46:23 UTC

DO NOT REPLY [Bug 47100] Change Worksheet name, related formula are not updated

https://issues.apache.org/bugzilla/show_bug.cgi?id=47100

Carl Pritchett <ca...@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |carl.pritchett@gmail.com
            Version|3.5-dev                     |3.7

--- Comment #1 from Carl Pritchett <ca...@gmail.com> 2011-02-27 22:46:19 EST ---
Hi,

When I create a HSSFWorkbook with a named range and then set the sheet name
with Workbook.setSheetName() all the named ranges' formulas are renamed also. 

When I do this with a XSSFWorkbook the named ranges' formulas are not renamed
and thus are broken (have the value of #REF!").

Here is a JUnit test that creates a file with such a broken named range.

    @Test
    public void create() throws IOException
    {
        String sname = "TestSheet", cname = "TestName", cvalue = "TestVal";
        // HSSFWorkbook handles rename
        // Workbook wb = new HSSFWorkbook();
        //File file = new File("c:\\test.xls");

        // XSSFWorkbook does not handle the rename
        Workbook wb = new XSSFWorkbook();
        File file = new File("c:\\test.xlsx");

        Sheet sheet = wb.createSheet(sname);
        sheet.createRow(0).createCell((short) 0).setCellValue(cvalue);

        // 1. create named range for a single cell using areareference
        Name namedCell = wb.createName();
        namedCell.setNameName(cname);
        String reference = sname+"!A1:A1"; // area reference
        namedCell.setRefersToFormula(reference);

        // 2. rename the sheet 
        wb.setSheetName(wb.getSheetIndex(sheet), "newName");

        FileOutputStream fout = new FileOutputStream(file); 
        wb.write(fout);
    }

Any workarounds?

Regards,
Carl Pritchett

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org