|Summary:||setAsActiveCell doesn't (always) work|
|Component:||HSSF||Assignee:||POI Developers List <dev>|
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(); sh.createRow(0); sh.createRow(1); sh.createRow(2); sh.createRow(3); Cell cell = sh.getRow(1).createCell(3); sh.getRow(3).createCell(3); cell.setAsActiveCell(); FileOutputStream fos = new FileOutputStream("C:\\test.xls"); wb.write(fos); fos.close(); //FileViewer.open("C:\\test.xls"); wb = WorkbookFactory.create(new File("C:\\test.xls")); wb.getSheetAt(0).getRow(3).getCell(3).setAsActiveCell(); fos = new FileOutputStream("C:\\test2.xls"); wb.write(fos); fos.close(); //FileViewer.open("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.