Bug 66173 - Active pane constants in XSSF Sheet are wrong
Summary: Active pane constants in XSSF Sheet are wrong
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: SS Common (show other bugs)
Version: 5.2.2-FINAL
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-07-20 09:58 UTC by PJ Fanning
Modified: 2022-07-20 13:16 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description PJ Fanning 2022-07-20 09:58:27 UTC
See answer in https://stackoverflow.com/questions/73043152/is-there-a-way-to-create-a-split-plane-horizontally-using-the-apache-poi-library

The constant fields in Sheet are as follows:

PANE_LOWER_RIGHT  0
PANE_UPPER_RIGHT  1
PANE_LOWER_LEFT   2
PANE_UPPER_LEFT   3

But the corresponding values in org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane are:

INT_BOTTOM_RIGHT 1
INT_TOP_RIGHT    2
INT_BOTTOM_LEFT  3
INT_TOP_LEFT     4

To get PANE_UPPER_LEFT, you need:
   sheet.createSplitPane(0, 100*20, 0, 9, Sheet.PANE_UPPER_LEFT+1);

We probably can't just change the Sheet values because other people might already use the workaround.

So let's deprecate the old values and add new ones.
Comment 1 PJ Fanning 2022-07-20 11:12:26 UTC
https://github.com/apache/poi/pull/362
Comment 2 Axel Richter 2022-07-20 12:03:50 UTC
Your fixes for HSSF might be wrong as the binary PaneTypes *are* 0-based.
See: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-xls/016387b9-9dac-43df-b226-34800b3c2198.

But the pane in SelectionRecord seems always be 3 (PANE_UPPER_LEFT) when split pane is set. Actually InternalSheet.createSplitPane always sets PANE_LOWER_RIGHT. That seems to be wrong.

Code to check:

import java.io.FileInputStream;
import org.apache.poi.hssf.usermodel.*;

class ReadHSSFSplitPane {
    
 public static void main(String[] args) throws Exception {
  try (
       HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream("./Excel.xls")) ) {

   HSSFSheet sheet = workbook.getSheetAt(0);
      
   org.apache.poi.hssf.model.InternalSheet internalSheet = sheet.getSheet();
   org.apache.poi.hssf.record.PaneRecord pane = (org.apache.poi.hssf.record.PaneRecord)internalSheet.findFirstRecordBySid(org.apache.poi.hssf.record.PaneRecord.sid);
   System.out.println(pane);  
   org.apache.poi.hssf.record.SelectionRecord sel =  (org.apache.poi.hssf.record.SelectionRecord)internalSheet.findFirstRecordBySid(org.apache.poi.hssf.record.SelectionRecord.sid);
   System.out.println(sel);
   
  }
 }
}

Pane in sel is always 3, independent of what split panes are set.
Comment 3 PJ Fanning 2022-07-20 12:10:57 UTC
Thanks Axel - I just spotted that the HSSF panel numbers are ok and that the issue with needing the +1 is XSSF only. I have adjusted https://github.com/apache/poi/pull/362
Comment 4 PJ Fanning 2022-07-20 13:16:31 UTC
added r1902876

XSSFSheet createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, int activePane) still has the bug where you need to add 1 to the activePane value (because https://stackoverflow.com/questions/73043152/is-there-a-way-to-create-a-split-plane-horizontally-using-the-apache-poi-library tells users to do that).

XSSFSheet createSplitPane(int xSplitPos, int ySplitPos, int leftmostColumn, int topRow, PaneType activePane) is the new method that works as expected