diff options
author | PJ Fanning <fanningpj@apache.org> | 2022-02-04 20:16:44 +0000 |
---|---|---|
committer | PJ Fanning <fanningpj@apache.org> | 2022-02-04 20:16:44 +0000 |
commit | e6926f9779cca31c458cb9b01ceb6f816bfe7428 (patch) | |
tree | cc7118d367e8c6a94d743dc29ae55347d184606e /poi | |
parent | b5d5077681c3bb9ded6610945ddead20b99e6ade (diff) | |
download | poi-e6926f9779cca31c458cb9b01ceb6f816bfe7428.tar.gz poi-e6926f9779cca31c458cb9b01ceb6f816bfe7428.zip |
introduce CellReferenceType
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1897779 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi')
4 files changed, 56 insertions, 15 deletions
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 cc457daa12..82473b60ff 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 @@ -96,6 +96,7 @@ import org.apache.poi.ss.formula.SheetNameFormatter; import org.apache.poi.ss.formula.udf.AggregatingUDFFinder; import org.apache.poi.ss.formula.udf.IndexedUDFFinder; import org.apache.poi.ss.formula.udf.UDFFinder; +import org.apache.poi.ss.usermodel.CellReferenceType; import org.apache.poi.ss.usermodel.Name; import org.apache.poi.ss.usermodel.Row.MissingCellPolicy; import org.apache.poi.ss.usermodel.Sheet; @@ -1748,7 +1749,7 @@ public final class HSSFWorkbook extends POIDocument implements Workbook { } @Override - public Boolean usesR1C1CellReferences() { + public CellReferenceType getCellReferenceType() { for (HSSFSheet hssfSheet : _sheets) { InternalSheet internalSheet = hssfSheet.getSheet(); @@ -1759,14 +1760,14 @@ public final class HSSFWorkbook extends POIDocument implements Workbook { if (record instanceof RefModeRecord) refModeRecord = (RefModeRecord)record; } if (refModeRecord == null) { - return null; + continue; } else if (refModeRecord.getMode() == RefModeRecord.USE_R1C1_MODE) { - return Boolean.TRUE; + return CellReferenceType.R1C1; } else if (refModeRecord.getMode() == RefModeRecord.USE_A1_MODE) { - return Boolean.FALSE; + return CellReferenceType.A1; } } - return null; + return CellReferenceType.UNKNOWN; } /** diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/CellReferenceType.java b/poi/src/main/java/org/apache/poi/ss/usermodel/CellReferenceType.java new file mode 100644 index 0000000000..c4f9bc0c38 --- /dev/null +++ b/poi/src/main/java/org/apache/poi/ss/usermodel/CellReferenceType.java @@ -0,0 +1,40 @@ +/* ==================================================================== + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +==================================================================== */ + +package org.apache.poi.ss.usermodel; + +/** + * Types of cell references. + * @since POI 5.2.1 + */ +public enum CellReferenceType { + + /** + * Cells are referenced in the form A1, B4, etc. + */ + A1, + + /** + * Cells are referenced in the form R1C1, R4C2, etc. + */ + R1C1, + + /** + * The cell reference type is not defined explicitly by <code>A1</code> is the default in this case. + */ + UNKNOWN +} 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 3851ed581e..7f59ab17b5 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 @@ -633,11 +633,10 @@ public interface Workbook extends Closeable, Iterable<Sheet> { 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. + * @return the type of cell references used * @since POI 5.2.1 */ - Boolean usesR1C1CellReferences(); + CellReferenceType getCellReferenceType(); /** * @param useR1C1CellReferences set to true if you want to configure workbook to use R1C1 cell references (as opposed to A1 cell references). diff --git a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java index 35caef0690..3851c44a7e 100644 --- a/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java +++ b/poi/src/test/java/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java @@ -61,6 +61,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; import org.apache.poi.ss.formula.ptg.Area3DPtg; import org.apache.poi.ss.usermodel.BaseTestWorkbook; import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellReferenceType; import org.apache.poi.ss.usermodel.ConditionalFormatting; import org.apache.poi.ss.usermodel.ConditionalFormattingRule; import org.apache.poi.ss.usermodel.Name; @@ -1184,12 +1185,12 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); HSSFWorkbook wb = openSampleWorkbook("49423.xls") ) { - assertFalse(wb.usesR1C1CellReferences()); + assertEquals(CellReferenceType.A1, wb.getCellReferenceType()); wb.setUseR1C1CellReferences(true); - assertTrue(wb.usesR1C1CellReferences()); + assertEquals(CellReferenceType.R1C1, wb.getCellReferenceType()); wb.write(bos); try (HSSFWorkbook wb2 = new HSSFWorkbook(bos.toInputStream())) { - assertTrue(wb2.usesR1C1CellReferences()); + assertEquals(CellReferenceType.R1C1, wb2.getCellReferenceType()); } } } @@ -1200,14 +1201,14 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream(); HSSFWorkbook wb = new HSSFWorkbook() ) { - assertNull(wb.usesR1C1CellReferences()); + assertEquals(CellReferenceType.UNKNOWN, wb.getCellReferenceType()); HSSFSheet sheet = wb.createSheet(); - assertFalse(wb.usesR1C1CellReferences()); + assertEquals(CellReferenceType.A1, wb.getCellReferenceType()); wb.setUseR1C1CellReferences(true); - assertTrue(wb.usesR1C1CellReferences()); + assertEquals(CellReferenceType.R1C1, wb.getCellReferenceType()); wb.write(bos); try (HSSFWorkbook wb2 = new HSSFWorkbook(bos.toInputStream())) { - assertTrue(wb2.usesR1C1CellReferences()); + assertEquals(CellReferenceType.R1C1, wb2.getCellReferenceType()); } } } |