aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2022-02-01 10:36:34 +0000
committerPJ Fanning <fanningpj@apache.org>2022-02-01 10:36:34 +0000
commit20dfe361ca2933199deb65a6570b40740f86125b (patch)
tree710bc3c82c9bfef2e2a0409bda8858f88b34538c
parent9f4b00861305567cd9cfec73b713b9e770df30cd (diff)
downloadpoi-20dfe361ca2933199deb65a6570b40740f86125b.tar.gz
poi-20dfe361ca2933199deb65a6570b40740f86125b.zip
add excel Workbook.usesR1C1CellReferences()
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1897649 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java6
-rw-r--r--poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java14
-rw-r--r--poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java39
-rw-r--r--poi/src/main/java/org/apache/poi/ss/usermodel/Workbook.java7
4 files changed, 49 insertions, 17 deletions
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
index 189787f96b..584a1f3f23 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
@@ -1350,9 +1350,13 @@ public class SXSSFWorkbook implements Workbook {
return _wb.addOlePackage(oleData, label, fileName, command);
}
-
@Override
public EvaluationWorkbook createEvaluationWorkbook() {
return SXSSFEvaluationWorkbook.create(this);
}
+
+ @Override
+ public Boolean usesR1C1CellReferences() {
+ return getXSSFWorkbook().usesR1C1CellReferences();
+ }
}
diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
index 7988e4e6e0..47e19e2956 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
@@ -20,6 +20,7 @@ package org.apache.poi.xssf.usermodel;
import static org.apache.poi.ooxml.POIXMLTypeLoader.DEFAULT_XML_OPTIONS;
import static org.apache.poi.xssf.usermodel.helpers.XSSFPasswordHelper.setPassword;
import static org.apache.poi.xssf.usermodel.helpers.XSSFPasswordHelper.validatePassword;
+import static org.openxmlformats.schemas.spreadsheetml.x2006.main.STRefMode.*;
import java.io.File;
import java.io.IOException;
@@ -1566,6 +1567,19 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Date1904Su
setPrintArea(sheetIndex, reference);
}
+ @Override
+ public Boolean usesR1C1CellReferences() {
+ final CTCalcPr calcPr = getCTWorkbook().getCalcPr();
+ if (calcPr == null) {
+ return null;
+ } else if (calcPr.getRefMode() == R_1_C_1) {
+ return Boolean.TRUE;
+ } else if (calcPr.getRefMode() == A_1) {
+ return Boolean.FALSE;
+ }
+ return null;
+ }
+
private static String getReferencePrintArea(String sheetName, int startC, int endC, int startR, int endR) {
//windows excel example: Sheet1!$C$3:$E$4
CellReference colRef = new CellReference(sheetName, startR, startC, true, true);
diff --git a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
index e369488d10..86cd7440fd 100644
--- a/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
+++ b/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
@@ -69,22 +69,7 @@ import org.apache.poi.hssf.model.InternalSheet.UnsupportedBOFType;
import org.apache.poi.hssf.model.InternalWorkbook;
import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.model.WorkbookRecordList;
-import org.apache.poi.hssf.record.AbstractEscherHolderRecord;
-import org.apache.poi.hssf.record.BackupRecord;
-import org.apache.poi.hssf.record.BoundSheetRecord;
-import org.apache.poi.hssf.record.DrawingGroupRecord;
-import org.apache.poi.hssf.record.ExtendedFormatRecord;
-import org.apache.poi.hssf.record.FilePassRecord;
-import org.apache.poi.hssf.record.FontRecord;
-import org.apache.poi.hssf.record.FormatRecord;
-import org.apache.poi.hssf.record.LabelRecord;
-import org.apache.poi.hssf.record.LabelSSTRecord;
-import org.apache.poi.hssf.record.NameRecord;
-import org.apache.poi.hssf.record.RecalcIdRecord;
-import org.apache.poi.hssf.record.Record;
-import org.apache.poi.hssf.record.RecordFactory;
-import org.apache.poi.hssf.record.SSTRecord;
-import org.apache.poi.hssf.record.UnknownRecord;
+import org.apache.poi.hssf.record.*;
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
import org.apache.poi.hssf.record.common.UnicodeString;
import org.apache.poi.hssf.record.crypto.Biff8DecryptingStream;
@@ -1762,6 +1747,28 @@ public final class HSSFWorkbook extends POIDocument implements Workbook {
return newName;
}
+ @Override
+ public Boolean usesR1C1CellReferences() {
+ for (HSSFSheet hssfSheet : _sheets) {
+ InternalSheet internalSheet = hssfSheet.getSheet();
+
+ List<RecordBase> records = internalSheet.getRecords();
+
+ RefModeRecord refModeRecord = null;
+ for (RecordBase record : records) {
+ if (record instanceof RefModeRecord) refModeRecord = (RefModeRecord)record;
+ }
+ if (refModeRecord == null) {
+ return null;
+ } else if (refModeRecord.getMode() == RefModeRecord.USE_R1C1_MODE) {
+ return Boolean.TRUE;
+ } else if (refModeRecord.getMode() == RefModeRecord.USE_A1_MODE) {
+ return Boolean.FALSE;
+ }
+ }
+ return null;
+ }
+
int getNameIndex(String name) {
for (int k = 0; k < names.size(); k++) {
diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/Workbook.java b/poi/src/main/java/org/apache/poi/ss/usermodel/Workbook.java
index e76637f5fd..041d7a785f 100644
--- a/poi/src/main/java/org/apache/poi/ss/usermodel/Workbook.java
+++ b/poi/src/main/java/org/apache/poi/ss/usermodel/Workbook.java
@@ -631,4 +631,11 @@ public interface Workbook extends Closeable, Iterable<Sheet> {
* @return an evaluation workbook
*/
EvaluationWorkbook createEvaluationWorkbook();
+
+ /**
+ * @return true if workbook is configured to use R1C1 cell references (as opposed to A1 cell references).
+ * Returns null if the configuration is not explicitly set on the workbook.
+ * @since POI 5.2.1
+ */
+ Boolean usesR1C1CellReferences();
}