Bug 52903 - Shifting rows does not shift hyperlink references
Summary: Shifting rows does not shift hyperlink references
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.14-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on: 58557
Blocks: 46742
  Show dependency tree
Reported: 2012-03-13 17:05 UTC by David Cross
Modified: 2015-11-29 14:53 UTC (History)
0 users

Example output file (3.60 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2012-03-13 17:05 UTC, David Cross
patch to fix HSSF shiftrow hyperlink bug (2.07 KB, text/plain)
2015-11-24 22:49 UTC, lyle
test file (3.04 KB, text/x-csrc)
2015-11-24 22:50 UTC, lyle

Note You need to log in before you can comment on or make changes to this bug.
Description David Cross 2012-03-13 17:05:22 UTC
Created attachment 28462 [details]
Example output file

When shifting rows in an HSSF or XSSF worksheet, any hyperlink references are not shifted along with rows. In the example, if shift rows is commented out, the code works as expected placing a cell at 0,0 containing the word Google and a link to Google.  However, if shift-rows is applied, the output file contains the word Google in row 1 and the link in row 0 (see attached output file).

        //create a workbook and add a sheet and row
        XSSFWorkbook wb=new XSSFWorkbook();
        CreationHelper createHelper = wb.getCreationHelper();
        Sheet sh=wb.createSheet();
        //create a cell and add a hyperlink
        Cell c=sh.getRow(0).createCell(0);
        Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
        link.setAddress(new URL("http://www.google.com").toString());
        //shift row by 1
        sh.shiftRows(0, 0, 1);
        //write workbook
        FileOutputStream fos=new FileOutputStream("shiftrowsexample.xlsx");
Comment 1 David Cross 2012-04-05 23:07:30 UTC
Just checked and this bug still exists in POI 3.8 release
Comment 2 Allen Gao 2015-08-27 07:05:53 UTC
I find this issue on 3.12 and 3.13 beta 1.
Who can fix it as soon as possible.
Comment 3 Allen Gao 2015-08-27 07:07:08 UTC
(In reply to Allen Gao from comment #2)
> I find this issue on 3.12 and 3.13 beta 1.
> Who can fix it as soon as possible.

OK, it has been 3 years and nobody can fix it ?
Comment 4 David North 2015-08-27 07:58:16 UTC
Allen - those of us who work on POI are mostly volunteers donating our own time. If you are in a position to provide a patch - or at least a failing JUnit test - that will make it much more likely that one of us is able to look at this.
Comment 5 Dominik Stadler 2015-10-29 08:43:23 UTC
This has been fixed for the XSSF-side via bug 58557, marking this bug as HSSF now because of this.
Comment 6 lyle 2015-11-24 22:49:44 UTC
Created attachment 33293 [details]
patch to fix HSSF shiftrow hyperlink bug
Comment 7 lyle 2015-11-24 22:50:32 UTC
Created attachment 33294 [details]
test file
Comment 8 Javen O'Neal 2015-11-29 14:53:25 UTC
Thanks for the patch, lyle!

I moved the TestXSSFSheetShiftRows testBug46742_shiftHyperlinks test over to BaseTestSheetShiftRows so that the same test could be used on all Sheet implementations. I think this already-existing unit test is a superset of your test (attachment 33294 [details]), but we always appreciate it when contributors include a unit test to so we know exactly what's wrong, and we know when the problem is fixed.

The existing unit test caught one additional problem with HSSFSheet's shiftRows implementation, which is that HSSFHyperlinks weren't removed from rows that get overwritten/deleted.

Added in r1717069. Updated docs in r1717070.