From: Javen O'Neal Date: Sat, 16 Jan 2016 22:01:33 +0000 (+0000) Subject: bug 58879: add SpreadsheetVersion to Workbook interface X-Git-Tag: REL_3_14_FINAL~73 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=fca4f0d0cb31f3bc76899f5f8e4352373ff9a0e0;p=poi.git bug 58879: add SpreadsheetVersion to Workbook interface git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1725039 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java index 2c1d90d1fd..ecf681c7f1 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java @@ -76,6 +76,7 @@ import org.apache.poi.poifs.filesystem.FilteringDirectoryNode; import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.Ole10Native; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.formula.FormulaShifter; import org.apache.poi.ss.formula.FormulaType; import org.apache.poi.ss.formula.SheetNameFormatter; @@ -2152,4 +2153,15 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss public InternalWorkbook getInternalWorkbook() { return workbook; } + + /** + * Returns the spreadsheet version (EXCLE97) of this workbook + * + * @return EXCEL97 SpreadsheetVersion enum + * @since 3.14 beta 2 + */ + @Override + public SpreadsheetVersion getSpreadsheetVersion() { + return SpreadsheetVersion.EXCEL97; + } } diff --git a/src/java/org/apache/poi/ss/usermodel/Workbook.java b/src/java/org/apache/poi/ss/usermodel/Workbook.java index 83fea32e0a..6619dd1192 100644 --- a/src/java/org/apache/poi/ss/usermodel/Workbook.java +++ b/src/java/org/apache/poi/ss/usermodel/Workbook.java @@ -23,6 +23,7 @@ import java.io.OutputStream; import java.util.Iterator; import java.util.List; +import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.formula.udf.UDFFinder; import org.apache.poi.ss.usermodel.Row.MissingCellPolicy; import org.apache.poi.ss.util.CellRangeAddress; @@ -623,5 +624,13 @@ public interface Workbook extends Closeable, Iterable { * @since 3.8 */ boolean getForceFormulaRecalculation(); + + /** + * Returns the spreadsheet version of this workbook + * + * @return SpreadsheetVersion enum + * @since 3.14 beta 2 + */ + public SpreadsheetVersion getSpreadsheetVersion(); } diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java index 20ac62e101..57bee980a2 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java @@ -35,6 +35,7 @@ import java.util.zip.ZipOutputStream; import org.apache.poi.openxml4j.opc.OPCPackage; import org.apache.poi.openxml4j.opc.internal.ZipHelper; +import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.formula.udf.UDFFinder; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CreationHelper; @@ -1325,5 +1326,16 @@ public class SXSSFWorkbook implements Workbook { return _wb.getForceFormulaRecalculation(); } + /** + * Returns the spreadsheet version (EXCLE2007) of this workbook + * + * @return EXCEL2007 SpreadsheetVersion enum + * @since 3.14 beta 2 + */ + @Override + public SpreadsheetVersion getSpreadsheetVersion() { + return SpreadsheetVersion.EXCEL2007; + } + //end of interface implementation } diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java index 4f55feeb4f..c02cf52278 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java @@ -54,6 +54,7 @@ import org.apache.poi.openxml4j.opc.PackageRelationshipTypes; import org.apache.poi.openxml4j.opc.PackagingURIHelper; import org.apache.poi.openxml4j.opc.TargetMode; import org.apache.poi.poifs.crypt.HashAlgorithm; +import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.formula.SheetNameFormatter; import org.apache.poi.ss.formula.udf.IndexedUDFFinder; import org.apache.poi.ss.formula.udf.UDFFinder; @@ -2255,4 +2256,15 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook { setVBAProject(vbaProjectStream); } } + + /** + * Returns the spreadsheet version (EXCLE2007) of this workbook + * + * @return EXCEL2007 SpreadsheetVersion enum + * @since 3.14 beta 2 + */ + @Override + public SpreadsheetVersion getSpreadsheetVersion() { + return SpreadsheetVersion.EXCEL2007; + } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java index 117300f2c8..4c46cd1f41 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java @@ -30,6 +30,7 @@ import java.io.FileOutputStream; import java.io.IOException; import org.apache.poi.POITestCase; +import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.usermodel.BaseTestWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; @@ -47,7 +48,7 @@ import org.junit.Ignore; import org.junit.Test; public final class TestSXSSFWorkbook extends BaseTestWorkbook { - public static final SXSSFITestDataProvider _testDataProvider = SXSSFITestDataProvider.instance; + private static final SXSSFITestDataProvider _testDataProvider = SXSSFITestDataProvider.instance; public TestSXSSFWorkbook() { super(_testDataProvider); @@ -435,4 +436,10 @@ public final class TestSXSSFWorkbook extends BaseTestWorkbook { streamingWorkBook.close(); workBook.close(); } + + @Test + @Override + public void getSpreadsheetVersion() throws IOException { + verifySpreadsheetVersion(SpreadsheetVersion.EXCEL2007); + } } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java index 14cc6f5f57..b73593b261 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFWorkbook.java @@ -77,9 +77,10 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbookPr; import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCalcMode; public final class TestXSSFWorkbook extends BaseTestWorkbook { + private static final XSSFITestDataProvider _testDataProvider = XSSFITestDataProvider.instance; public TestXSSFWorkbook() { - super(XSSFITestDataProvider.instance); + super(_testDataProvider); } /** @@ -1078,4 +1079,10 @@ public final class TestXSSFWorkbook extends BaseTestWorkbook { assertTrue(file.delete()); } } + + @Test + @Override + public void getSpreadsheetVersion() throws IOException { + verifySpreadsheetVersion(SpreadsheetVersion.EXCEL2007); + } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java index a8915fe6fe..6fa22bc4d1 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFWorkbook.java @@ -53,6 +53,7 @@ import org.apache.poi.poifs.filesystem.DirectoryEntry; import org.apache.poi.poifs.filesystem.DirectoryNode; import org.apache.poi.poifs.filesystem.NPOIFSFileSystem; import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.formula.ptg.Area3DPtg; import org.apache.poi.ss.usermodel.BaseTestWorkbook; import org.apache.poi.ss.usermodel.Name; @@ -70,8 +71,10 @@ import junit.framework.AssertionFailedError; * Tests for {@link HSSFWorkbook} */ public final class TestHSSFWorkbook extends BaseTestWorkbook { + private static final HSSFITestDataProvider _testDataProvider = HSSFITestDataProvider.instance; + public TestHSSFWorkbook() { - super(HSSFITestDataProvider.instance); + super(_testDataProvider); } /** @@ -1253,4 +1256,10 @@ public final class TestHSSFWorkbook extends BaseTestWorkbook { fileOut.close(); } + + @Test + @Override + public void getSpreadsheetVersion() throws IOException { + verifySpreadsheetVersion(SpreadsheetVersion.EXCEL97); + } } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java index ab14550048..2ca742a4a5 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java @@ -31,6 +31,7 @@ import java.util.ConcurrentModificationException; import java.util.Iterator; import org.apache.poi.ss.ITestDataProvider; +import org.apache.poi.ss.SpreadsheetVersion; import org.apache.poi.ss.util.CellRangeAddress; import org.junit.Test; @@ -822,4 +823,13 @@ public abstract class BaseTestWorkbook { b.close(); } + + @Test + public abstract void getSpreadsheetVersion() throws IOException; + + protected void verifySpreadsheetVersion(SpreadsheetVersion expected) throws IOException { + final Workbook wb = _testDataProvider.createWorkbook(); + assertEquals(expected, wb.getSpreadsheetVersion()); + wb.close(); + } }