Bug 56114 - setAsActiveCell doesn't (always) work
Summary: setAsActiveCell doesn't (always) work
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.15-FINAL
Hardware: PC Windows Vista
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2014-02-06 17:08 UTC by rjahn
Modified: 2016-12-28 07:14 UTC (History)
2 users (show)

Test files (105.12 KB, application/x-zip-compressed)
2014-10-22 11:17 UTC, rjahn

Note You need to log in before you can comment on or make changes to this bug.
Description rjahn 2014-02-06 17:08:05 UTC
The method setAsActiveCell doesn't set the focus on the cell.

If you open Excel, it shows another cell (e.g. A1).

There's no difference between creating a new workbook and reading an existing xls file. The method doesn't set the cell active or it does but Excel ignores the selection?

Simple Test case with a new workbook:

Workbook wb = new HSSFWorkbook();
Sheet sh = wb.createSheet();


Cell cell = sh.getRow(1).createCell(3);


FileOutputStream fos = new FileOutputStream("C:\\test.xls");



wb = WorkbookFactory.create(new File("C:\\test.xls"));
fos = new FileOutputStream("C:\\test2.xls");



Above code works if you use new XSSFWorkbook() and "xlsx" as extension.
Comment 1 Dominik Stadler 2014-03-15 17:00:45 UTC
I tried this with LibreOffice, it did display the active cell correctly. I did not have a MS Excel available. 

This was with the latest trunk version, 

I have added a unit-test for this at TestHSSFCell.testActiveCellBug56114() with r1577901.

Please retry this with the latest version and re-open if it still does not work for you.
Comment 2 rjahn 2014-03-17 11:39:47 UTC
Did a test with nightly build: poi-3.11-beta1-20140316.jar

The problem still exists. Works with XSSF but not with HSSF.
Comment 3 Nick Burch 2014-06-13 14:56:02 UTC
For someone who this affects, any chance you could:
 * Fire up Excel, and create a simple workbook, with a cell set as active (wb1)
 * Load that in POI, and save without making changes (wb2)
 * Load that in POI, change the active cell, save (wb3)
 * Load that in Excel, change the active cell, save (wb4)

Then, use tools like hssf.dev.BiffViewer to see what record(s) Excel is using for the active cell, and what options / values on those records, and what POI is doing differently.

There will be some small differences between the files normally, which hopefully diffing things like wb1 and wb2 will allow excluding of, it's the parts around the active cell that need narrowing down to fix
Comment 4 rjahn 2014-10-22 11:17:27 UTC
Created attachment 32136 [details]
Test files

wb1.xls (created with Excel)

wb2.xls (read with POI, written with POI)
wb1_wb3.xls (wb1 was the base for wb3) (read with POI, written with POI)
wb2_wb3.xls (wb2 was the base for wb3) (read with POI, written with POI)

wb2_wb3_wb4.xls (wb2_wb3 was the base for wb4) (created with Excel)
Comment 5 rjahn 2014-10-22 11:18:02 UTC
Tests files are attached.
Comment 6 Vadim 2016-12-28 07:14:41 UTC
The poi-3.15 has the same bug.

 If you take the two xls-files created by excel that differ only in activeCell and re-save them by poi, the hssf.dev.BiffViewer shows no differences between files, but excel opens new-created files with the original cell location.