diff --git a/KEYS b/KEYS
index 811af6f512..6767cb00a3 100644
--- a/KEYS
+++ b/KEYS
@@ -1753,10 +1753,11 @@ W45jdvBkYoPdQtS+8Vy+q0997zobctz8i5hfXzxg51/IuSU4uNtgr26XapsoLDur
7PoqJGZ6UdBVwyb0qZqs6KLGQkEyJ8358ivjJsjxUR8diK027wWnW/s=
=/Vu1
-----END PGP PUBLIC KEY BLOCK-----
-pub 2048R/26062CE3 2014-08-17 [expires: 2016-08-16]
-uid Andreas Beeker
-uid Andreas Beeker (kiwiwings)
-sub 2048R/EE864ED6 2014-08-17 [expires: 2016-08-16]
+
+pub rsa2048/26062CE3 2014-08-17 [expires: 2018-08-21]
+uid [ultimate] Andreas Beeker
+uid [ultimate] Andreas Beeker (kiwiwings)
+sub rsa2048/EE864ED6 2014-08-17 [expires: 2018-08-21]
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2
@@ -1767,14 +1768,14 @@ ODjjNQtn+nYmOu7a8Xg3g3vTnikkuHZqWvK0O0VYouW/p1NHelUejQbOPuUKukD1
omzskuYgteTZ9Jn8efJMIymg9dGubuvN4HvUdEO0/u6K2MCZjIqNEPeqWIuZXeMb
+4nGv2r0jSQAU94g3hueooqbUf+Mk2+H5O1d/h2Cii9qVvi6gELdVw9H+5Ir9AFc
ynsmvxrPIxraBMPgrXmvPFOTlqlizyFv2O7pABEBAAG0JUFuZHJlYXMgQmVla2Vy
-IDxraXdpd2luZ3NAYXBhY2hlLm9yZz6JAUEEEwECACsCGwMFCQPCZwAGCwkIBwMC
-BhUIAgkKCwQWAgMBAh4BAheABQJUS6SzAhkBAAoJEKk+HEsmBizjjdYIALH3trht
-6JTfPz2UsltFTcjzqLXG/I8Vq5hkr0s4ex1V7oNDXrBRBb1WC1pcEe1xqvQmoTyP
-dUoX8lCyLOrt3IRpgjnH/4ACyenfOw6yHl6aaXX3HvseL3oHQTMpzkny+xVsrUzJ
-wVCRVACPM49L6nRj4YRYaZqAn42x2peYHNcfFrvKsDtTnt4SbFQBlmuiDtlePM6a
-9wzqXMFkX+9hcHp/SgOwDalpameoRQ/Itf1w2hN9dxYuaUWojo6b0XpChzkCHKix
-uEKtjJXTovRlc6DzxT2Z5JMPhATiN3ZCo88lfd/kK8aMZgV4fruaq/QQRjNK/Hgn
-6fP9jPARncSFHkCJAT4EEwECACgFAlPxECkCGwMFCQPCZwAGCwkIBwMCBhUIAgkK
+IDxraXdpd2luZ3NAYXBhY2hlLm9yZz6JAUEEEwECACsCGwMGCwkIBwMCBhUIAgkK
+CwQWAgMBAh4BAheAAhkBBQJXuYpTBQkHizsfAAoJEKk+HEsmBizjNa0H/AjJPguQ
+WIn9AV/jstRN4OPM6eY7VUMG1DYoABRQSVsksPki5jZii0bI9VB3AUFgfXj0y6qk
+CwQyKCJwZjcP3JuciJ5brQr/7D12hoTkYSCzCaECIpMoB7HWCpdoFusrgU2PUUwJ
+i8xBTC+sLxIn3h5abTU68tnynCYhlA0mJ8zZ8CTvQJyEjidY1UgSohXClG2k/mo7
+z/IyW16x4dlpdkNfiBhL2v/5Ol7Vuz9g1lXvWvMdNQZ2PVK6w5dmCziCkih/qRgK
+SUzn65ASEKiCN7afzUkCTdzrI71r3rOkJtlT1NWn2RAv6xT6AuhCPZzH2I3ImuFI
+mkUKYhKzRN6AdmCJAT4EEwECACgFAlPxECkCGwMFCQPCZwAGCwkIBwMCBhUIAgkK
CwQWAgMBAh4BAheAAAoJEKk+HEsmBizjvfYIALS1vlaqN/f7/YzpnOwlH2Wo4jpI
jBrG7SqcdVQk3NGsXTXzzq5p7uTTzpEJW8ReZLGeYaTzqh1vH97uAPR6wL3GjHMZ
F2jkC0wSHXxvh9Gyrdx3LA8NSO+BAG9ZfD6OGklsl7tFFEplLpfR1EsAKfbi0bAY
@@ -1782,13 +1783,13 @@ F2jkC0wSHXxvh9Gyrdx3LA8NSO+BAG9ZfD6OGklsl7tFFEplLpfR1EsAKfbi0bAY
019qP30afGkvw+ZbIq8qbxJItObMuhn5xdI0YaMm2yudCfm2aGYSCnkrgNfuWzH6
WZ8n1fv45TGBUd2R6zPr13eH73AG1WXpapoD45yf/TFavRfnknU6xb7U3ZK0MkFu
ZHJlYXMgQmVla2VyIChraXdpd2luZ3MpIDxhbmRyZWFzLmJlZWtlckBnbXguZGU+
-iQE+BBMBAgAoBQJT8LY0AhsDBQkDwmcABgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIX
-gAAKCRCpPhxLJgYs4wvFB/9hEV8LzHUpD0X/vM9pfW1ZbTl2GNiZfuMh6/KlqB3C
-4gL3SLLRlk4mEPM3qlZWCqZiWVp5zz1C/j/+BLJW3c+j3rCUEAsobsR6HkxBr7N0
-LUnurbMXyiOvdg4lAS42Vi1JrydFdih1HCI3NiGMHAV/8NEdtmLt7Ue8Opx01R6r
-wXBomX5BHJXnzbZRbCbdor/UnO8ff5K4jwd6yhY0BV+bI2uD+vGq9nMld0JGj7W7
-qB+HzOAxpINtHksQhtTV/PBWjHTCNhOdGh1zyoyvJSshm1NkvwBVZYMs/0ujApcq
-xAXytGXonLiMmZMECOjxAigph8T4PCEKdIqdsVxkC2ybiQIcBBABCgAGBQJV5hIJ
+iQE+BBMBAgAoAhsDBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAUCV7mKXAUJB4s7
+HwAKCRCpPhxLJgYs4zheCACgc3m2FH5kmXtYO44BdYYwdV2dyLMCxvVl7GUWqJF8
+wKmDWlUxBwrpzDBQXpmHyb+rqX/kvfEkH2wb9TZwginLecbZbMKubNUWUqGJBHQo
+CaV8o6L/iEUJa5NXzY2OJCp32CHsmpefYkU+WgAnmTVe8Se7JEmJeu+2OfStV5m6
+zVK5xzlciYSc29LpA3dsv5hxE6YZ8kJBJaFyv2AvVzaouSR7nPNrdw3/jXaOz+Hb
+VpP/CEf5IdvF/o37sv8o7WWcH1AjvMdGQNp6Zr5Te2E35V8PmpqLH4Z8W0/PXij2
+67i565JZc1Kmpqxm59jg1vs2X7rHNn0k+r9BFiCQC1LKiQIcBBABCgAGBQJV5hIJ
AAoJEOGWdUUnufY1qh8P/03uvjuU1V9UZY9t/4J/K0wbU8Re9c/HfgmJrCn+wvDI
OtxpOg3m07ZoIrosYEA2CIm+kLCYuNbzGSz6ZPZlpoq5FvxzO9OAYMO76r3ktxUw
Snbxd9TCkjCCQ8RMxT/JGDBU77nAJPyhCUZF2/SyrXnexloNP9TR/IDQZNOXzlxR
@@ -1805,14 +1806,14 @@ ulDgtZwWSin3Kd40VZDyKi6mqOp5ldz6AsZ2CSx1GfI9iVhfuFqOaiBLqpNpdvf9
nGL9OVoy1SdwTXgnboiIFtbTG3sVwD4x4qTRbmT22Ln/mIAICR2wxFBkzpbIQ7Mf
R/zEgRh2VlRUUrWUsnYdOh0xfxuYgsnPCjpTY8hvEno3H6kzXKmj2GQJtawMVs5b
Ro/GCM9lBBR/PAhB65ACzLmUUSsxjlmjZw0tCcOufg1RyAF/l6YVw1UOJaqXBfSP
-eZkLQBj9p8VNpasX/acIfpEaZLE8QhoO11ajABEBAAGJASUEGAECAA8FAlPwtjQC
-GwwFCQPCZwAACgkQqT4cSyYGLOPzLggAjHrdpMjZrHM5WqnxkJ1Eib1g14aScMGd
-OIw9NOSQ2AGvJjbSy4xyMEUg3S14I73JGYtJu8g9YvCHbuWiyzySBIuGNinMI/Zj
-ET/w1noqoNaSlIY4UfFh30g+OikEzP9WXmo0Scg0XH/fJhX1wCpM/TVlphX0yNGm
-mkNBBqerRXC7Md4XOy001vvXZGM7vy+xOotyBOy/D4WNERSz3GVS3juCQGMWvMdq
-KQa+qoiVaXWfFHwg8u4bSHunrzNja17GyaZHdCEmM9vFzlaqBkoLWCMwIcaKnX9s
-tQJpFZwpzgut7DanaPcCDk7LMBbntaJwRC72M0qcj16SUAdAuGt1yQ==
-=IonN
+eZkLQBj9p8VNpasX/acIfpEaZLE8QhoO11ajABEBAAGJASUEGAECAA8CGwwFAle5
+inIFCQeLOz4ACgkQqT4cSyYGLOMvsAf+J2EyV9+GNqT8UmEU6OFnw/sdR1oE+vZ9
+fe4mifAfjQ+SKYf+MS0lU3lTuwcQKwFklePoYsvJEO7jNEgjTQ+zKiDSlV5yufSn
+Idy8+sCYygPn5fSjGdRaMpCCfs5xrljLUPK5U8+vjeteRJW0o2/wmsYdHRz6A74B
+kRq8kYu1M8VgZ6JD1YI/mp0mHTTB+H69/DNo6cA+7W/CibeTrffbJ35+OXGsJxqJ
+b/QH/4lqsceNJtJThkHPQeM18R7/4t7Vhb5htOk2eB7coKzdYRKpHMzkm7elm8bI
+uwsky9+6hIUMKD5hhc8G7g9lWOLSXCeNRUdqWTOfZaU5KOK70kKUeQ==
+=PCbZ
-----END PGP PUBLIC KEY BLOCK-----
pub 4096R/B4812553 2014-02-26 [expires: 2019-02-25]
diff --git a/build.xml b/build.xml
index f40ff4c774..d3623395d9 100644
--- a/build.xml
+++ b/build.xml
@@ -40,7 +40,7 @@ under the License.
The Apache POI project Ant build.
-
+
@@ -1092,7 +1092,7 @@ under the License.
-
+
+
-
+
+
-
+
@@ -2430,12 +2432,13 @@ under the License.
-
+
+
diff --git a/sonar/examples/pom.xml b/sonar/examples/pom.xml
index cac1dc446c..ea53c05970 100644
--- a/sonar/examples/pom.xml
+++ b/sonar/examples/pom.xml
@@ -6,7 +6,7 @@
org.apache.poipoi-parent
- 3.15-beta4-SNAPSHOT
+ 3.16-beta1-SNAPSHOTpoi-examplesjar
diff --git a/sonar/excelant/pom.xml b/sonar/excelant/pom.xml
index 2cbeec7280..a7b9408dc4 100644
--- a/sonar/excelant/pom.xml
+++ b/sonar/excelant/pom.xml
@@ -6,7 +6,7 @@
org.apache.poipoi-parent
- 3.15-beta4-SNAPSHOT
+ 3.16-beta1-SNAPSHOTpoi-excelantjar
diff --git a/sonar/main/pom.xml b/sonar/main/pom.xml
index 26a8f2ba40..36422a83c8 100644
--- a/sonar/main/pom.xml
+++ b/sonar/main/pom.xml
@@ -6,7 +6,7 @@
org.apache.poipoi-parent
- 3.15-beta4-SNAPSHOT
+ 3.16-beta1-SNAPSHOTpoi-mainjar
diff --git a/sonar/ooxml-schema-encryption/pom.xml b/sonar/ooxml-schema-encryption/pom.xml
index d704a6525d..cbb2eff7d3 100644
--- a/sonar/ooxml-schema-encryption/pom.xml
+++ b/sonar/ooxml-schema-encryption/pom.xml
@@ -6,7 +6,7 @@
org.apache.poipoi-parent
- 3.15-beta4-SNAPSHOT
+ 3.16-beta1-SNAPSHOT..poi-ooxml-schema-encryption
diff --git a/sonar/ooxml-schema-security/pom.xml b/sonar/ooxml-schema-security/pom.xml
index 7aae600f41..a822c73435 100644
--- a/sonar/ooxml-schema-security/pom.xml
+++ b/sonar/ooxml-schema-security/pom.xml
@@ -6,7 +6,7 @@
org.apache.poipoi-parent
- 3.15-beta4-SNAPSHOT
+ 3.16-beta1-SNAPSHOT..poi-ooxml-schema-security
diff --git a/sonar/ooxml-schema/pom.xml b/sonar/ooxml-schema/pom.xml
index e1d6526da9..5e2b9fef56 100644
--- a/sonar/ooxml-schema/pom.xml
+++ b/sonar/ooxml-schema/pom.xml
@@ -6,7 +6,7 @@
org.apache.poipoi-parent
- 3.15-beta4-SNAPSHOT
+ 3.16-beta1-SNAPSHOT..poi-ooxml-schema
diff --git a/sonar/ooxml/pom.xml b/sonar/ooxml/pom.xml
index 305695ff1a..27636cdfa1 100644
--- a/sonar/ooxml/pom.xml
+++ b/sonar/ooxml/pom.xml
@@ -6,7 +6,7 @@
org.apache.poipoi-parent
- 3.15-beta4-SNAPSHOT
+ 3.16-beta1-SNAPSHOTpoi-ooxmljar
diff --git a/sonar/pom.xml b/sonar/pom.xml
index 5acb3a5da2..8e2a9fc42f 100644
--- a/sonar/pom.xml
+++ b/sonar/pom.xml
@@ -3,7 +3,7 @@
org.apache.poipoi-parentpom
- 3.15-beta4-SNAPSHOT
+ 3.16-beta1-SNAPSHOTApache POI - the Java API for Microsoft DocumentsMaven build of Apache POI for Sonar checkshttp://poi.apache.org/
diff --git a/sonar/scratchpad/pom.xml b/sonar/scratchpad/pom.xml
index 91ede69a1c..6760762d67 100644
--- a/sonar/scratchpad/pom.xml
+++ b/sonar/scratchpad/pom.xml
@@ -6,7 +6,7 @@
org.apache.poipoi-parent
- 3.15-beta4-SNAPSHOT
+ 3.16-beta1-SNAPSHOTpoi-scratchpadjar
diff --git a/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java b/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java
index ac0075b16b..8a59b8306f 100644
--- a/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java
+++ b/src/examples/src/org/apache/poi/hssf/view/SVTableCellRenderer.java
@@ -160,8 +160,8 @@ public class SVTableCellRenderer extends JLabel
SVTableUtils.getAWTColor(s.getRightBorderColor(), SVTableUtils.black),
SVTableUtils.getAWTColor(s.getBottomBorderColor(), SVTableUtils.black),
SVTableUtils.getAWTColor(s.getLeftBorderColor(), SVTableUtils.black),
- s.getBorderTop(), s.getBorderRight(),
- s.getBorderBottom(), s.getBorderLeft(),
+ s.getBorderTopEnum(), s.getBorderRightEnum(),
+ s.getBorderBottomEnum(), s.getBorderLeftEnum(),
hasFocus);
setBorder(cellBorder);
isBorderSet=true;
diff --git a/src/examples/src/org/apache/poi/ss/examples/ExcelComparator.java b/src/examples/src/org/apache/poi/ss/examples/ExcelComparator.java
index dce4b0196e..d6f846a6bb 100644
--- a/src/examples/src/org/apache/poi/ss/examples/ExcelComparator.java
+++ b/src/examples/src/org/apache/poi/ss/examples/ExcelComparator.java
@@ -367,23 +367,23 @@ public class ExcelComparator {
String borderName;
switch (borderSide) {
case 't': default:
- b1 = style1.getBorderTop() == BorderStyle.THIN;
- b2 = style2.getBorderTop() == BorderStyle.THIN;
+ b1 = style1.getBorderTopEnum() == BorderStyle.THIN;
+ b2 = style2.getBorderTopEnum() == BorderStyle.THIN;
borderName = "TOP";
break;
case 'b':
- b1 = style1.getBorderBottom() == BorderStyle.THIN;
- b2 = style2.getBorderBottom() == BorderStyle.THIN;
+ b1 = style1.getBorderBottomEnum() == BorderStyle.THIN;
+ b2 = style2.getBorderBottomEnum() == BorderStyle.THIN;
borderName = "BOTTOM";
break;
case 'l':
- b1 = style1.getBorderLeft() == BorderStyle.THIN;
- b2 = style2.getBorderLeft() == BorderStyle.THIN;
+ b1 = style1.getBorderLeftEnum() == BorderStyle.THIN;
+ b2 = style2.getBorderLeftEnum() == BorderStyle.THIN;
borderName = "LEFT";
break;
case 'r':
- b1 = style1.getBorderRight() == BorderStyle.THIN;
- b2 = style2.getBorderRight() == BorderStyle.THIN;
+ b1 = style1.getBorderRightEnum() == BorderStyle.THIN;
+ b2 = style2.getBorderRightEnum() == BorderStyle.THIN;
borderName = "RIGHT";
break;
}
diff --git a/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java b/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java
index c5fdc1da9a..f5d2ecba8d 100644
--- a/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java
+++ b/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java
@@ -298,10 +298,10 @@ public class ToHtml {
}
private void borderStyles(CellStyle style) {
- styleOut("border-left", style.getBorderLeft(), BORDER);
- styleOut("border-right", style.getBorderRight(), BORDER);
- styleOut("border-top", style.getBorderTop(), BORDER);
- styleOut("border-bottom", style.getBorderBottom(), BORDER);
+ styleOut("border-left", style.getBorderLeftEnum(), BORDER);
+ styleOut("border-right", style.getBorderRightEnum(), BORDER);
+ styleOut("border-top", style.getBorderTopEnum(), BORDER);
+ styleOut("border-bottom", style.getBorderBottomEnum(), BORDER);
}
private void fontStyle(CellStyle style) {
diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreatePivotTable.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreatePivotTable.java
index 518ec37f48..a855feedae 100644
--- a/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreatePivotTable.java
+++ b/src/examples/src/org/apache/poi/xssf/usermodel/examples/CreatePivotTable.java
@@ -21,6 +21,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.DataConsolidateFunction;
import org.apache.poi.ss.usermodel.Row;
@@ -39,7 +40,11 @@ public class CreatePivotTable {
//Create some data to build the pivot table on
setCellData(sheet);
- XSSFPivotTable pivotTable = sheet.createPivotTable(new AreaReference("A1:D4"), new CellReference("H5"));
+ AreaReference source = new AreaReference("A1:D4", SpreadsheetVersion.EXCEL2007);
+ CellReference position = new CellReference("H5");
+ // Create a pivot table on this sheet, with H5 as the top-left cell..
+ // The pivot table's data source is on the same sheet in A1:D4
+ XSSFPivotTable pivotTable = sheet.createPivotTable(source, position);
//Configure the pivot table
//Use first column as row label
pivotTable.addRowLabel(0);
@@ -98,4 +103,4 @@ public class CreatePivotTable {
Cell cell44 = row4.createCell(3);
cell44.setCellValue("No");
}
-}
\ No newline at end of file
+}
diff --git a/src/examples/src/org/apache/poi/xssf/usermodel/examples/FillsAndColors.java b/src/examples/src/org/apache/poi/xssf/usermodel/examples/FillsAndColors.java
index 019e14d1ce..f5edd4a8ea 100644
--- a/src/examples/src/org/apache/poi/xssf/usermodel/examples/FillsAndColors.java
+++ b/src/examples/src/org/apache/poi/xssf/usermodel/examples/FillsAndColors.java
@@ -32,13 +32,13 @@ public class FillsAndColors {
Sheet sheet = wb.createSheet("new sheet");
// Create a row and put some cells in it. Rows are 0 based.
- Row row = sheet.createRow((short) 1);
+ Row row = sheet.createRow(1);
// Aqua background
CellStyle style = wb.createCellStyle();
style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
style.setFillPattern(CellStyle.BIG_SPOTS);
- Cell cell = row.createCell((short) 1);
+ Cell cell = row.createCell(1);
cell.setCellValue(new XSSFRichTextString("X"));
cell.setCellStyle(style);
@@ -46,7 +46,7 @@ public class FillsAndColors {
style = wb.createCellStyle();
style.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
- cell = row.createCell((short) 2);
+ cell = row.createCell(2);
cell.setCellValue(new XSSFRichTextString("X"));
cell.setCellStyle(style);
diff --git a/src/integrationtest/org/apache/poi/TestAllFiles.java b/src/integrationtest/org/apache/poi/TestAllFiles.java
index 6183c185c6..e364c9f28a 100644
--- a/src/integrationtest/org/apache/poi/TestAllFiles.java
+++ b/src/integrationtest/org/apache/poi/TestAllFiles.java
@@ -240,6 +240,7 @@ public class TestAllFiles {
EXPECTED_FAILURES.add("openxml4j/OPCCompliance_CoreProperties_OnlyOneCorePropertiesPartFAIL.docx");
EXPECTED_FAILURES.add("openxml4j/OPCCompliance_CoreProperties_UnauthorizedXMLLangAttributeFAIL.docx");
EXPECTED_FAILURES.add("openxml4j/OPCCompliance_DerivedPartNameFAIL.docx");
+ EXPECTED_FAILURES.add("openxml4j/invalid.xlsx");
EXPECTED_FAILURES.add("spreadsheet/54764-2.xlsx"); // see TestXSSFBugs.bug54764()
EXPECTED_FAILURES.add("spreadsheet/54764.xlsx"); // see TestXSSFBugs.bug54764()
EXPECTED_FAILURES.add("spreadsheet/Simple.xlsb");
@@ -297,7 +298,10 @@ public class TestAllFiles {
List
* @deprecated since POI 3.14beta1 (circa 2015-11-24). Use {@link AnchorType#MOVE_AND_RESIZE} instead.
*/
+ @Removal(version="3.17")
public static final AnchorType MOVE_AND_RESIZE = AnchorType.MOVE_AND_RESIZE;
/**
@@ -50,6 +52,7 @@ public interface ClientAnchor {
*
* @deprecated since POI 3.14beta1 (circa 2015-11-24). Use {@link AnchorType#MOVE_DONT_RESIZE} instead.
*/
+ @Removal(version="3.17")
public static final AnchorType MOVE_DONT_RESIZE = AnchorType.MOVE_DONT_RESIZE;
/**
@@ -66,6 +69,7 @@ public interface ClientAnchor {
*
* @deprecated since POI 3.14beta1 (circa 2015-11-24). Use {@link AnchorType#DONT_MOVE_AND_RESIZE} instead.
*/
+ @Removal(version="3.17")
public static final AnchorType DONT_MOVE_AND_RESIZE = AnchorType.DONT_MOVE_AND_RESIZE;
/**
@@ -288,11 +292,20 @@ public interface ClientAnchor {
/**
* Sets the anchor type
* @param anchorType the anchor type to set
+ * @since POI 3.14
*/
public void setAnchorType( AnchorType anchorType );
+ /**
+ * Sets the anchor type
+ * @param anchorType the anchor type to set
+ * @deprecated POI 3.15. Use {@link #setAnchorType(AnchorType)} instead.
+ */
+ @Removal(version="3.17")
+ public void setAnchorType( int anchorType );
/**
* Gets the anchor type
+ * Changed from returning an int to an enum in POI 3.14 beta 1.
* @return the anchor type
*/
public AnchorType getAnchorType();
diff --git a/src/java/org/apache/poi/ss/usermodel/CreationHelper.java b/src/java/org/apache/poi/ss/usermodel/CreationHelper.java
index 25e1cdaae8..53462c1d4e 100644
--- a/src/java/org/apache/poi/ss/usermodel/CreationHelper.java
+++ b/src/java/org/apache/poi/ss/usermodel/CreationHelper.java
@@ -17,18 +17,18 @@
package org.apache.poi.ss.usermodel;
import org.apache.poi.common.usermodel.HyperlinkType;
+import org.apache.poi.util.Removal;
/**
* An object that handles instantiating concrete
* classes of the various instances one needs for
* HSSF and XSSF.
- * Works around a major shortcoming in Java, where we
- * can't have static methods on interfaces or abstract
+ * Works around a limitation in Java where we
+ * cannot have static methods on interfaces or abstract
* classes.
* This allows you to get the appropriate class for
* a given interface, without you having to worry
- * about if you're dealing with HSSF or XSSF, despite
- * Java being quite rubbish.
+ * about if you're dealing with HSSF or XSSF.
*/
public interface CreationHelper {
/**
@@ -46,6 +46,7 @@ public interface CreationHelper {
* Creates a new Hyperlink, of the given type
* @deprecated POI 3.15 beta 3. Use {@link #createHyperlink(HyperlinkType)} instead.
*/
+ @Removal(version="3.17")
@Deprecated
Hyperlink createHyperlink(int type);
diff --git a/src/java/org/apache/poi/ss/usermodel/DataConsolidateFunction.java b/src/java/org/apache/poi/ss/usermodel/DataConsolidateFunction.java
index f54fb4f7b4..d40a8d11c5 100644
--- a/src/java/org/apache/poi/ss/usermodel/DataConsolidateFunction.java
+++ b/src/java/org/apache/poi/ss/usermodel/DataConsolidateFunction.java
@@ -38,8 +38,8 @@ public enum DataConsolidateFunction {
VAR(10, "Var"),
VARP(11, "Varp");
- private int value;
- private String name;
+ private final int value;
+ private final String name;
DataConsolidateFunction(int value, String name) {
this.value = value;
diff --git a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
index ee6583937b..61a5092f22 100644
--- a/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
+++ b/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
@@ -895,7 +895,7 @@ public class DataFormatter implements Observer {
return cell.getRichStringCellValue().getString();
case BOOLEAN :
- return String.valueOf(cell.getBooleanCellValue());
+ return cell.getBooleanCellValue() ? "TRUE" : "FALSE";
case BLANK :
return "";
case ERROR:
diff --git a/src/java/org/apache/poi/ss/usermodel/FormulaError.java b/src/java/org/apache/poi/ss/usermodel/FormulaError.java
index 583ca06d9c..fa102299e8 100644
--- a/src/java/org/apache/poi/ss/usermodel/FormulaError.java
+++ b/src/java/org/apache/poi/ss/usermodel/FormulaError.java
@@ -166,19 +166,19 @@ public enum FormulaError {
return false;
}
- public static FormulaError forInt(byte type){
+ public static FormulaError forInt(byte type) throws IllegalArgumentException {
FormulaError err = bmap.get(type);
if(err == null) throw new IllegalArgumentException("Unknown error type: " + type);
return err;
}
- public static FormulaError forInt(int type){
+ public static FormulaError forInt(int type) throws IllegalArgumentException {
FormulaError err = imap.get(type);
if(err == null) err = bmap.get((byte)type);
if(err == null) throw new IllegalArgumentException("Unknown error type: " + type);
return err;
}
- public static FormulaError forString(String code){
+ public static FormulaError forString(String code) throws IllegalArgumentException {
FormulaError err = smap.get(code);
if(err == null) throw new IllegalArgumentException("Unknown error code: " + code);
return err;
diff --git a/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java b/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java
index be75ff9d55..357bd073a6 100644
--- a/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java
+++ b/src/java/org/apache/poi/ss/usermodel/FormulaEvaluator.java
@@ -101,6 +101,7 @@ public interface FormulaEvaluator {
* or one of {@link CellType#NUMERIC}, {@link CellType#STRING},
* {@link CellType#BOOLEAN}, {@link CellType#ERROR}
* Note: the cell's type remains as CellType.FORMULA however.
+ * @deprecated 3.15. Will return a {@link CellType} enum in the future
*/
int evaluateFormulaCell(Cell cell);
diff --git a/src/java/org/apache/poi/ss/usermodel/Row.java b/src/java/org/apache/poi/ss/usermodel/Row.java
index b17edcd303..f58775704c 100644
--- a/src/java/org/apache/poi/ss/usermodel/Row.java
+++ b/src/java/org/apache/poi/ss/usermodel/Row.java
@@ -19,6 +19,8 @@ package org.apache.poi.ss.usermodel;
import java.util.Iterator;
+import org.apache.poi.util.Removal;
+
/**
* High level representation of a row of a spreadsheet.
*/
@@ -240,8 +242,10 @@ public interface Row extends Iterable {
CREATE_NULL_AS_BLANK(3);
/**
- * @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - the id has no function and will be removed
+ * @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - the id has no function and will be removed.
+ * The {@code id} is only kept only for backwards compatibility with applications that hard-coded the number
*/
+ @Removal(version="3.17")
@Deprecated
public final int id;
private MissingCellPolicy(int id) {
@@ -254,6 +258,7 @@ public interface Row extends Iterable {
*
* @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - use the MissingCellPolicy enum
**/
+ @Removal(version="3.17")
@Deprecated
public static final MissingCellPolicy RETURN_NULL_AND_BLANK = MissingCellPolicy.RETURN_NULL_AND_BLANK;
/**
@@ -261,6 +266,7 @@ public interface Row extends Iterable {
*
* @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - use the MissingCellPolicy enum
**/
+ @Removal(version="3.17")
@Deprecated
public static final MissingCellPolicy RETURN_BLANK_AS_NULL = MissingCellPolicy.RETURN_BLANK_AS_NULL;
/**
@@ -268,6 +274,7 @@ public interface Row extends Iterable {
*
* @deprecated as of POI 3.15-beta2, scheduled for removal in 3.17 - use the MissingCellPolicy enum
**/
+ @Removal(version="3.17")
@Deprecated
public static final MissingCellPolicy CREATE_NULL_AS_BLANK = MissingCellPolicy.CREATE_NULL_AS_BLANK;
diff --git a/src/java/org/apache/poi/ss/usermodel/charts/DataSources.java b/src/java/org/apache/poi/ss/usermodel/charts/DataSources.java
index 3bf891e0a9..75e7fd9a81 100644
--- a/src/java/org/apache/poi/ss/usermodel/charts/DataSources.java
+++ b/src/java/org/apache/poi/ss/usermodel/charts/DataSources.java
@@ -42,7 +42,7 @@ public class DataSources {
return new AbstractCellRangeDataSource(sheet, cellRangeAddress) {
public Number getPointAt(int index) {
CellValue cellValue = getCellValueAt(index);
- if (cellValue != null && cellValue.getCellType() == CellType.NUMERIC) {
+ if (cellValue != null && cellValue.getCellTypeEnum() == CellType.NUMERIC) {
return Double.valueOf(cellValue.getNumberValue());
} else {
return null;
@@ -59,7 +59,7 @@ public class DataSources {
return new AbstractCellRangeDataSource(sheet, cellRangeAddress) {
public String getPointAt(int index) {
CellValue cellValue = getCellValueAt(index);
- if (cellValue != null && cellValue.getCellType() == CellType.STRING) {
+ if (cellValue != null && cellValue.getCellTypeEnum() == CellType.STRING) {
return cellValue.getStringValue();
} else {
return null;
diff --git a/src/java/org/apache/poi/ss/util/CellUtil.java b/src/java/org/apache/poi/ss/util/CellUtil.java
index 4f446c10dc..3dad83aab6 100644
--- a/src/java/org/apache/poi/ss/util/CellUtil.java
+++ b/src/java/org/apache/poi/ss/util/CellUtil.java
@@ -405,10 +405,10 @@ public final class CellUtil {
Map properties = new HashMap();
put(properties, ALIGNMENT, style.getAlignmentEnum());
put(properties, VERTICAL_ALIGNMENT, style.getVerticalAlignmentEnum());
- put(properties, BORDER_BOTTOM, style.getBorderBottom());
- put(properties, BORDER_LEFT, style.getBorderLeft());
- put(properties, BORDER_RIGHT, style.getBorderRight());
- put(properties, BORDER_TOP, style.getBorderTop());
+ put(properties, BORDER_BOTTOM, style.getBorderBottomEnum());
+ put(properties, BORDER_LEFT, style.getBorderLeftEnum());
+ put(properties, BORDER_RIGHT, style.getBorderRightEnum());
+ put(properties, BORDER_TOP, style.getBorderTopEnum());
put(properties, BOTTOM_BORDER_COLOR, style.getBottomBorderColor());
put(properties, DATA_FORMAT, style.getDataFormat());
put(properties, FILL_PATTERN, style.getFillPatternEnum());
diff --git a/src/ooxml/java/org/apache/poi/POIXMLDocument.java b/src/ooxml/java/org/apache/poi/POIXMLDocument.java
index 4ec3d442ed..93afa6163f 100644
--- a/src/ooxml/java/org/apache/poi/POIXMLDocument.java
+++ b/src/ooxml/java/org/apache/poi/POIXMLDocument.java
@@ -40,6 +40,7 @@ import org.apache.xmlbeans.impl.common.SystemCache;
/**
* This holds the common functionality for all POI OOXML Document classes.
*/
+// TODO: implements AutoCloseable in Java 7+ when POI drops support for Java 6.
public abstract class POIXMLDocument extends POIXMLDocumentPart implements Closeable {
public static final String DOCUMENT_CREATOR = "Apache POI";
@@ -230,6 +231,11 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart implements Close
*/
@SuppressWarnings("resource")
public final void write(OutputStream stream) throws IOException {
+ OPCPackage p = getPackage();
+ if(p == null) {
+ throw new IOException("Cannot write data, document seems to have been closed already");
+ }
+
//force all children to commit their changes into the underlying OOXML Package
// TODO Shouldn't they be committing to the new one instead?
Set context = new HashSet();
@@ -239,10 +245,6 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart implements Close
//save extended and custom properties
getProperties().commit();
- OPCPackage p = getPackage();
- if(p == null) {
- throw new IOException("Cannot write data, document seems to have been closed already");
- }
p.save(stream);
}
}
diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
index e029d7dece..b7720ee42a 100644
--- a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
+++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java
@@ -248,9 +248,10 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
* @throws InvalidFormatException
* If the specified file doesn't exist, and a parsing error
* occur.
+ * @throws InvalidOperationException
*/
public static OPCPackage open(String path, PackageAccess access)
- throws InvalidFormatException {
+ throws InvalidFormatException, InvalidOperationException {
if (path == null || "".equals(path.trim())) {
throw new IllegalArgumentException("'path' must be given");
}
@@ -261,8 +262,20 @@ public abstract class OPCPackage implements RelationshipSource, Closeable {
}
OPCPackage pack = new ZipPackage(path, access);
+ boolean success = false;
if (pack.partList == null && access != PackageAccess.WRITE) {
- pack.getParts();
+ try {
+ pack.getParts();
+ success = true;
+ } finally {
+ if (! success) {
+ try {
+ pack.close();
+ } catch (final IOException e) {
+ throw new InvalidOperationException("Could not close OPCPackage while cleaning up", e);
+ }
+ }
+ }
}
pack.originalPackagePath = new File(path).getAbsolutePath();
return pack;
diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
index fe4d6f1ed8..33333c3c51 100644
--- a/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
+++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/ZipPackage.java
@@ -19,6 +19,7 @@ package org.apache.poi.openxml4j.opc;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -52,7 +53,10 @@ import org.apache.poi.util.TempFile;
* Physical zip package.
*/
public final class ZipPackage extends OPCPackage {
- private static POILogger logger = POILogFactory.getLogger(ZipPackage.class);
+ private static final String MIMETYPE = "mimetype";
+ private static final String SETTINGS_XML = "settings.xml";
+
+ private static final POILogger logger = POILogFactory.getLogger(ZipPackage.class);
/**
* Zip archive, as either a file on disk,
@@ -85,12 +89,22 @@ public final class ZipPackage extends OPCPackage {
* @throws IllegalArgumentException
* If the specified input stream not an instance of
* ZipInputStream.
+ * @throws IOException
+ * if input stream cannot be opened, read, or closed
*/
ZipPackage(InputStream in, PackageAccess access) throws IOException {
super(access);
- @SuppressWarnings("resource")
ThresholdInputStream zis = ZipHelper.openZipStream(in);
- this.zipArchive = new ZipInputStreamZipEntrySource(zis);
+ try {
+ this.zipArchive = new ZipInputStreamZipEntrySource(zis);
+ } catch (final IOException e) {
+ try {
+ zis.close();
+ } catch (final IOException e2) {
+ throw new IOException("Failed to close zip input stream while cleaning up. " + e.getMessage(), e2);
+ }
+ throw new IOException("Failed to read zip entry source", e);
+ }
}
/**
@@ -100,8 +114,9 @@ public final class ZipPackage extends OPCPackage {
* The path of the file to open or create.
* @param access
* The package access mode.
+ * @throws InvalidOperationException
*/
- ZipPackage(String path, PackageAccess access) {
+ ZipPackage(String path, PackageAccess access) throws InvalidOperationException {
this(new File(path), access);
}
@@ -112,9 +127,9 @@ public final class ZipPackage extends OPCPackage {
* The file to open or create.
* @param access
* The package access mode.
+ * @throws InvalidOperationException
*/
- @SuppressWarnings("resource")
- ZipPackage(File file, PackageAccess access) {
+ ZipPackage(File file, PackageAccess access) throws InvalidOperationException {
super(access);
ZipEntrySource ze;
@@ -127,36 +142,72 @@ public final class ZipPackage extends OPCPackage {
throw new InvalidOperationException("Can't open the specified file: '" + file + "'", e);
}
logger.log(POILogger.ERROR, "Error in zip file "+file+" - falling back to stream processing (i.e. ignoring zip central directory)");
- // some zips can't be opened via ZipFile in JDK6, as the central directory
- // contains either non-latin entries or the compression type can't be handled
- // the workaround is to iterate over the stream and not the directory
- FileInputStream fis = null;
- ThresholdInputStream zis = null;
- try {
- fis = new FileInputStream(file);
- zis = ZipHelper.openZipStream(fis);
- ze = new ZipInputStreamZipEntrySource(zis);
- } catch (IOException e2) {
- if (zis != null) {
- try {
- zis.close();
- } catch (IOException e3) {
- throw new InvalidOperationException("Can't open the specified file: '" + file + "'"+
- " and couldn't close the file input stream", e);
- }
- } else if (fis != null) {
- try {
- fis.close();
- } catch (IOException e3) {
- throw new InvalidOperationException("Can't open the specified file: '" + file + "'"+
- " and couldn't close the file input stream", e);
- }
- }
- throw new InvalidOperationException("Can't open the specified file: '" + file + "'", e);
- }
+ ze = openZipEntrySourceStream(file);
}
this.zipArchive = ze;
}
+
+ private static ZipEntrySource openZipEntrySourceStream(File file) throws InvalidOperationException {
+ final FileInputStream fis;
+ // Acquire a resource that is needed to read the next level of openZipEntrySourceStream
+ try {
+ // open the file input stream
+ fis = new FileInputStream(file);
+ } catch (final FileNotFoundException e) {
+ // If the source cannot be acquired, abort (no resources to free at this level)
+ throw new InvalidOperationException("Can't open the specified file input stream from file: '" + file + "'", e);
+ }
+
+ // If an error occurs while reading the next level of openZipEntrySourceStream, free the acquired resource
+ try {
+ // read from the file input stream
+ return openZipEntrySourceStream(fis);
+ } catch (final Exception e) {
+ try {
+ // abort: close the file input stream
+ fis.close();
+ } catch (final IOException e2) {
+ throw new InvalidOperationException("Could not close the specified file input stream from file: '" + file + "'", e2);
+ }
+ throw new InvalidOperationException("Failed to read the file input stream from file: '" + file + "'", e);
+ }
+ }
+
+ private static ZipEntrySource openZipEntrySourceStream(FileInputStream fis) throws InvalidOperationException {
+ final ThresholdInputStream zis;
+ // Acquire a resource that is needed to read the next level of openZipEntrySourceStream
+ try {
+ // open the zip input stream
+ zis = ZipHelper.openZipStream(fis);
+ } catch (final IOException e) {
+ // If the source cannot be acquired, abort (no resources to free at this level)
+ throw new InvalidOperationException("Could not open the file input stream", e);
+ }
+
+ // If an error occurs while reading the next level of openZipEntrySourceStream, free the acquired resource
+ try {
+ // read from the zip input stream
+ return openZipEntrySourceStream(zis);
+ } catch (final Exception e) {
+ try {
+ // abort: close the zip input stream
+ zis.close();
+ } catch (final IOException e2) {
+ throw new InvalidOperationException("Failed to read the zip entry source stream and could not close the zip input stream", e2);
+ }
+ throw new InvalidOperationException("Failed to read the zip entry source stream", e);
+ }
+ }
+
+ private static ZipEntrySource openZipEntrySourceStream(ThresholdInputStream zis) throws InvalidOperationException {
+ // Acquire the final level resource. If this is acquired successfully, the zip package was read successfully from the input stream
+ try {
+ // open the zip entry source stream
+ return new ZipInputStreamZipEntrySource(zis);
+ } catch (IOException e) {
+ throw new InvalidOperationException("Could not open the specified zip entry source stream", e);
+ }
+ }
/**
* Constructor. Opens a Zip based Open XML document from
@@ -206,7 +257,7 @@ public final class ZipPackage extends OPCPackage {
this.contentTypeManager = new ZipContentTypeManager(
getZipArchive().getInputStream(entry), this);
} catch (IOException e) {
- throw new InvalidFormatException(e.getMessage());
+ throw new InvalidFormatException(e.getMessage(), e);
}
break;
}
@@ -220,11 +271,12 @@ public final class ZipPackage extends OPCPackage {
boolean hasSettingsXML = false;
entries = this.zipArchive.getEntries();
while (entries.hasMoreElements()) {
- ZipEntry entry = entries.nextElement();
- if (entry.getName().equals("mimetype")) {
+ final ZipEntry entry = entries.nextElement();
+ final String name = entry.getName();
+ if (MIMETYPE.equals(name)) {
hasMimetype = true;
}
- if (entry.getName().equals("settings.xml")) {
+ if (SETTINGS_XML.equals(name)) {
hasSettingsXML = true;
}
numEntries++;
@@ -259,10 +311,10 @@ public final class ZipPackage extends OPCPackage {
String contentType = contentTypeManager.getContentType(partName);
if (contentType != null && contentType.equals(ContentTypes.RELATIONSHIPS_PART)) {
try {
- partList.put(partName, new ZipPackagePart(this, entry,
- partName, contentType));
+ PackagePart part = new ZipPackagePart(this, entry, partName, contentType);
+ partList.put(partName, part);
} catch (InvalidOperationException e) {
- throw new InvalidFormatException(e.getMessage());
+ throw new InvalidFormatException(e.getMessage(), e);
}
}
}
@@ -274,17 +326,16 @@ public final class ZipPackage extends OPCPackage {
PackagePartName partName = buildPartName(entry);
if(partName == null) continue;
- String contentType = contentTypeManager
- .getContentType(partName);
+ String contentType = contentTypeManager.getContentType(partName);
if (contentType != null && contentType.equals(ContentTypes.RELATIONSHIPS_PART)) {
// Already handled
}
else if (contentType != null) {
try {
- partList.put(partName, new ZipPackagePart(this, entry,
- partName, contentType));
+ PackagePart part = new ZipPackagePart(this, entry, partName, contentType);
+ partList.put(partName, part);
} catch (InvalidOperationException e) {
- throw new InvalidFormatException(e.getMessage());
+ throw new InvalidFormatException(e.getMessage(), e);
}
} else {
throw new InvalidFormatException(
@@ -392,20 +443,22 @@ public final class ZipPackage extends OPCPackage {
// Save the final package to a temporary file
try {
save(tempFile);
-
- // Close the current zip file, so we can
- // overwrite it on all platforms
- this.zipArchive.close();
- // Copy the new file over the old one
- FileHelper.copyFile(tempFile, targetFile);
} finally {
- // Either the save operation succeed or not, we delete the
- // temporary file
- if (!tempFile.delete()) {
- logger
- .log(POILogger.WARN,"The temporary file: '"
- + targetFile.getAbsolutePath()
- + "' cannot be deleted ! Make sure that no other application use it.");
+ try {
+ // Close the current zip file, so we can
+ // overwrite it on all platforms
+ this.zipArchive.close();
+ // Copy the new file over the old one
+ FileHelper.copyFile(tempFile, targetFile);
+ } finally {
+ // Either the save operation succeed or not, we delete the
+ // temporary file
+ if (!tempFile.delete()) {
+ logger
+ .log(POILogger.WARN,"The temporary file: '"
+ + targetFile.getAbsolutePath()
+ + "' cannot be deleted ! Make sure that no other application use it.");
+ }
}
}
} else {
diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
index 632d2af262..b674b3ad2f 100644
--- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
+++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/ZipHelper.java
@@ -19,6 +19,7 @@ package org.apache.poi.openxml4j.opc.internal;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PushbackInputStream;
@@ -239,10 +240,15 @@ public final class ZipHelper {
* @param file
* The file to open.
* @return The zip archive freshly open.
+ * @throws IOException if the zip file cannot be opened or closed to read the header signature
+ * @throws NotOfficeXmlFileException if stream does not start with zip header signature
*/
- public static ZipFile openZipFile(File file) throws IOException {
+ public static ZipFile openZipFile(File file) throws IOException, NotOfficeXmlFileException {
if (!file.exists()) {
- return null;
+ throw new FileNotFoundException("File does not exist");
+ }
+ if (file.isDirectory()) {
+ throw new IOException("File is a directory");
}
// Peek at the first few bytes to sanity check
diff --git a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipEntrySource.java b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipEntrySource.java
index 1d64ffe4ea..51ad32ce65 100644
--- a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipEntrySource.java
+++ b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipEntrySource.java
@@ -45,4 +45,9 @@ public interface ZipEntrySource {
* resources may be freed
*/
public void close() throws IOException;
+
+ /**
+ * Has close been called already?
+ */
+ public boolean isClosed();
}
diff --git a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java
index f4117f44bf..09317d361e 100644
--- a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java
+++ b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipFileZipEntrySource.java
@@ -39,6 +39,9 @@ public class ZipFileZipEntrySource implements ZipEntrySource {
}
zipArchive = null;
}
+ public boolean isClosed() {
+ return (zipArchive == null);
+ }
public Enumeration extends ZipEntry> getEntries() {
if (zipArchive == null)
diff --git a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
index 36b69ac25b..4c2b9df3e7 100644
--- a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
+++ b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipInputStreamZipEntrySource.java
@@ -76,6 +76,9 @@ public class ZipInputStreamZipEntrySource implements ZipEntrySource {
// Free the memory
zipEntries = null;
}
+ public boolean isClosed() {
+ return (zipEntries == null);
+ }
/**
* Why oh why oh why are Iterator and Enumeration
diff --git a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipSecureFile.java b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipSecureFile.java
index 13369a5ed1..9000656e57 100644
--- a/src/ooxml/java/org/apache/poi/openxml4j/util/ZipSecureFile.java
+++ b/src/ooxml/java/org/apache/poi/openxml4j/util/ZipSecureFile.java
@@ -134,15 +134,15 @@ public class ZipSecureFile extends ZipFile {
return MAX_TEXT_SIZE;
}
- public ZipSecureFile(File file, int mode) throws IOException {
+ public ZipSecureFile(File file, int mode) throws ZipException, IOException {
super(file, mode);
}
- public ZipSecureFile(File file) throws IOException {
+ public ZipSecureFile(File file) throws ZipException, IOException {
super(file);
}
- public ZipSecureFile(String name) throws IOException {
+ public ZipSecureFile(String name) throws ZipException, IOException {
super(name);
}
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
index fe969d36b5..14b656b53e 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XMLSlideShow.java
@@ -471,6 +471,7 @@ implements SlideShow {
* @param format The format of the picture
*
* @return the picture data
+ * @since 3.15 beta 2
*/
@Override
public XSLFPictureData addPicture(InputStream is, PictureType format) throws IOException
@@ -486,6 +487,7 @@ implements SlideShow {
* @param format The format of the picture.
*
* @return the picture data
+ * @since 3.15 beta 2
*/
@Override
public XSLFPictureData addPicture(File pict, PictureType format) throws IOException
@@ -507,6 +509,7 @@ implements SlideShow {
*
* @param pictureData The picture data to find in the SlideShow
* @return {@code null} if picture data is not found in this slideshow
+ * @since 3.15 beta 2
*/
@Override
public XSLFPictureData findPictureData(byte[] pictureData) {
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFHyperlink.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFHyperlink.java
index 09b883c00f..2f300623fb 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFHyperlink.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFHyperlink.java
@@ -69,6 +69,10 @@ public class XSLFHyperlink implements Hyperlink {
_link.setTooltip(label);
}
+ /* (non-Javadoc)
+ * @deprecated POI 3.15. Use {@link #getTypeEnum()} instead.
+ * Will return a HyperlinkType enum in the future
+ */
@Override
public int getType() {
return getTypeEnum().getCode();
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableRow.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableRow.java
index 5326d9e784..c4529c4aa7 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableRow.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFTableRow.java
@@ -32,9 +32,9 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
* Represents a table in a .pptx presentation
*/
public class XSLFTableRow implements Iterable {
- private CTTableRow _row;
- private List _cells;
- private XSLFTable _table;
+ private final CTTableRow _row;
+ private final List _cells;
+ private final XSLFTable _table;
/*package*/ XSLFTableRow(CTTableRow row, XSLFTable table){
_row = row;
@@ -78,6 +78,29 @@ public class XSLFTableRow implements Iterable {
_table.updateRowColIndexes();
return cell;
}
+
+ /**
+ * Merge cells of a table row, inclusive.
+ * Indices are 0-based.
+ *
+ * @param firstCol 0-based index of first column to merge, inclusive
+ * @param lastCol 0-based index of last column to merge, inclusive
+ */
+ public void mergeCells(int firstCol, int lastCol)
+ {
+ if (firstCol >= lastCol) {
+ throw new IllegalArgumentException(
+ "Cannot merge, first column >= last column : "
+ + firstCol + " >= " + lastCol
+ );
+ }
+ final int colSpan = (lastCol - firstCol) + 1;
+
+ _cells.get(firstCol).setGridSpan(colSpan);
+ for (final XSLFTableCell cell : _cells.subList(firstCol+1, lastCol+1)) {
+ cell.setHMerge(true);
+ }
+ }
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
index 6174af54ba..99a4648a7c 100644
--- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCell.java
@@ -43,6 +43,7 @@ import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.NotImplemented;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Removal;
import org.apache.poi.xssf.usermodel.XSSFHyperlink;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
@@ -61,6 +62,8 @@ public class SXSSFCell implements Cell {
* @deprecated POI 3.15 beta 3.
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/
+ @Removal(version="3.17")
+ @Deprecated
public SXSSFCell(SXSSFRow row, int cellType)
{
this(row, CellType.forInt((cellType)));
diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java
index 201879702f..f2687ff1d4 100644
--- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java
+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFCreationHelper.java
@@ -26,6 +26,7 @@ import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.util.Internal;
import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
+import org.apache.poi.util.Removal;
import org.apache.poi.xssf.usermodel.XSSFCreationHelper;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
@@ -72,6 +73,7 @@ public class SXSSFCreationHelper implements CreationHelper {
* @deprecated POI 3.15 beta 3. Use {@link #createHyperlink(HyperlinkType)} instead.
*/
@Deprecated
+ @Removal(version="3.17")
@Override
public Hyperlink createHyperlink(int type) {
return helper.createHyperlink(type);
diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFFormulaEvaluator.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFFormulaEvaluator.java
index ac72bc7f38..0ac776ffca 100644
--- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFFormulaEvaluator.java
+++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFFormulaEvaluator.java
@@ -72,24 +72,9 @@ public final class SXSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator {
return new SXSSFEvaluationCell((SXSSFCell)cell);
}
- /**
- * If cell contains formula, it evaluates the formula, and
- * puts the formula result back into the cell, in place
- * of the old formula.
- * Else if cell does not contain formula, this method leaves
- * the cell unchanged.
- * Note that the same instance of SXSSFCell is returned to
- * allow chained calls like:
- *
- * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
- *
- * Be aware that your cell value will be changed to hold the
- * result of the formula. If you simply want the formula
- * value computed for you, use {@link #evaluateFormulaCellEnum(org.apache.poi.ss.usermodel.Cell)} }
- */
+ @Override
public SXSSFCell evaluateInCell(Cell cell) {
- doEvaluateInCell(cell);
- return (SXSSFCell)cell;
+ return (SXSSFCell) super.evaluateInCell(cell);
}
/**
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java
index c6c030b957..780126c3d5 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/BaseXSSFFormulaEvaluator.java
@@ -28,7 +28,7 @@ import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.CellValue;
-import org.apache.poi.util.Internal;
+import org.apache.poi.ss.usermodel.RichTextString;
/**
* Internal POI use only - parent of XSSF and SXSSF formula evaluators
@@ -37,6 +37,10 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator {
protected BaseXSSFFormulaEvaluator(WorkbookEvaluator bookEvaluator) {
super(bookEvaluator);
}
+ @Override
+ protected RichTextString createRichTextString(String str) {
+ return new XSSFRichTextString(str);
+ }
public void notifySetFormula(Cell cell) {
_bookEvaluator.notifyUpdateCell(new XSSFEvaluationCell((XSSFCell)cell));
@@ -48,78 +52,6 @@ public abstract class BaseXSSFFormulaEvaluator extends BaseFormulaEvaluator {
_bookEvaluator.notifyUpdateCell(new XSSFEvaluationCell((XSSFCell)cell));
}
- /**
- * If cell contains formula, it evaluates the formula,
- * and saves the result of the formula. The cell
- * remains as a formula cell.
- * Else if cell does not contain formula, this method leaves
- * the cell unchanged.
- * Note that the type of the formula result is returned,
- * so you know what kind of value is also stored with
- * the formula.
- *
- * Be aware that your cell will hold both the formula,
- * and the result. If you want the cell replaced with
- * the result of the formula, use {@link #evaluate(org.apache.poi.ss.usermodel.Cell)} }
- * @param cell The cell to evaluate
- * @return The type of the formula result (the cell's type remains as CellType.FORMULA however)
- * If cell is not a formula cell, returns {@link CellType#_NONE} rather than throwing an exception.
- * @since POI 3.15 beta 3
- * @deprecated POI 3.15 beta 3. Will be deleted when we make the CellType enum transition. See bug 59791.
- */
- @Internal(since="POI 3.15 beta 3")
- public CellType evaluateFormulaCellEnum(Cell cell) {
- if (cell == null || cell.getCellTypeEnum() != CellType.FORMULA) {
- return CellType._NONE;
- }
- CellValue cv = evaluateFormulaCellValue(cell);
- // cell remains a formula cell, but the cached value is changed
- setCellValue(cell, cv);
- return cv.getCellType();
- }
-
- /**
- * If cell contains formula, it evaluates the formula, and
- * puts the formula result back into the cell, in place
- * of the old formula.
- * Else if cell does not contain formula, this method leaves
- * the cell unchanged.
- */
- protected void doEvaluateInCell(Cell cell) {
- if (cell == null) return;
- if (cell.getCellTypeEnum() == CellType.FORMULA) {
- CellValue cv = evaluateFormulaCellValue(cell);
- setCellType(cell, cv); // cell will no longer be a formula cell
- setCellValue(cell, cv);
- }
- }
-
- private static void setCellValue(Cell cell, CellValue cv) {
- CellType cellType = cv.getCellType();
- switch (cellType) {
- case BOOLEAN:
- cell.setCellValue(cv.getBooleanValue());
- break;
- case ERROR:
- cell.setCellErrorValue(cv.getErrorValue());
- break;
- case NUMERIC:
- cell.setCellValue(cv.getNumberValue());
- break;
- case STRING:
- cell.setCellValue(new XSSFRichTextString(cv.getStringValue()));
- break;
- case BLANK:
- // never happens - blanks eventually get translated to zero
- case FORMULA:
- // this will never happen, we have already evaluated the formula
- default:
- throw new IllegalStateException("Unexpected cell value type (" + cellType + ")");
- }
- }
-
/**
* Turns a XSSFCell / SXSSFCell into a XSSFEvaluationCell
*/
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java
index e48fe948e9..edea8cda9d 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFBorderFormatting.java
@@ -35,32 +35,87 @@ public class XSSFBorderFormatting implements BorderFormatting {
_border = border;
}
+ /**
+ * @deprecated POI 3.15. Use {@link #getBorderBottomEnum()}.
+ * This method will return an BorderStyle enum in the future.
+ */
@Override
- public BorderStyle getBorderBottom() {
+ public short getBorderBottom() {
+ return getBorderBottomEnum().getCode();
+ }
+ /**
+ * @since POI 3.15
+ */
+ @Override
+ public BorderStyle getBorderBottomEnum() {
STBorderStyle.Enum ptrn = _border.isSetBottom() ? _border.getBottom().getStyle() : null;
return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
}
+ /**
+ * @deprecated POI 3.15. Use {@link #getBorderDiagonalEnum()}.
+ * This method will return an BorderStyle enum in the future.
+ */
@Override
- public BorderStyle getBorderDiagonal() {
+ public short getBorderDiagonal() {
+ return getBorderDiagonalEnum().getCode();
+ }
+ /**
+ * @since POI 3.15
+ */
+ @Override
+ public BorderStyle getBorderDiagonalEnum() {
STBorderStyle.Enum ptrn = _border.isSetDiagonal() ? _border.getDiagonal().getStyle() : null;
return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
}
+ /**
+ * @deprecated POI 3.15. Use {@link #getBorderLeftEnum()}.
+ * This method will return an BorderStyle enum in the future.
+ */
@Override
- public BorderStyle getBorderLeft() {
+ public short getBorderLeft() {
+ return getBorderLeftEnum().getCode();
+ }
+ /**
+ * @since POI 3.15
+ */
+ @Override
+ public BorderStyle getBorderLeftEnum() {
STBorderStyle.Enum ptrn = _border.isSetLeft() ? _border.getLeft().getStyle() : null;
return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
}
+ /**
+ * @deprecated POI 3.15. Use {@link #getBorderRightEnum()}.
+ * This method will return an BorderStyle enum in the future.
+ */
@Override
- public BorderStyle getBorderRight() {
+ public short getBorderRight() {
+ return getBorderRightEnum().getCode();
+ }
+ /**
+ * @since POI 3.15
+ */
+ @Override
+ public BorderStyle getBorderRightEnum() {
STBorderStyle.Enum ptrn = _border.isSetRight() ? _border.getRight().getStyle() : null;
return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
}
+ /**
+ * @deprecated POI 3.15. Use {@link #getBorderTopEnum()}.
+ * This method will return an BorderStyle enum in the future.
+ */
@Override
- public BorderStyle getBorderTop() {
+ public short getBorderTop() {
+ return getBorderTopEnum().getCode();
+ }
+ /**
+ * @since POI 3.15
+ */
+ @Override
+ public BorderStyle getBorderTopEnum() {
STBorderStyle.Enum ptrn = _border.isSetTop() ? _border.getTop().getStyle() : null;
return ptrn == null ? BorderStyle.NONE : BorderStyle.valueOf((short)(ptrn.intValue() - 1));
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
index 4aa2f037e7..c7932d167b 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
@@ -668,6 +668,7 @@ public final class XSSFCell implements Cell {
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return the cell type
+ * @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override
public int getCellType() {
@@ -699,6 +700,7 @@ public final class XSSFCell implements Cell {
* @return one of ({@link CellType#NUMERIC}, {@link CellType#STRING},
* {@link CellType#BOOLEAN}, {@link CellType#ERROR}) depending
* on the cached value of the formula
+ * @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override
public int getCachedFormulaResultType() {
@@ -714,7 +716,6 @@ public final class XSSFCell implements Cell {
* @deprecated POI 3.15 beta 3
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/
- @Internal(since="POI 3.15 beta 3")
@Override
public CellType getCachedFormulaResultTypeEnum() {
if (! isFormulaCell()) {
@@ -826,7 +827,7 @@ public final class XSSFCell implements Cell {
* @throws IllegalStateException if the cell type returned by {@link #getCellTypeEnum()} isn't {@link CellType#ERROR}
* @see FormulaError
*/
- public String getErrorCellString() {
+ public String getErrorCellString() throws IllegalStateException {
CellType cellType = getBaseCellType(true);
if(cellType != CellType.ERROR) throw typeMismatch(CellType.ERROR, cellType, false);
@@ -844,13 +845,16 @@ public final class XSSFCell implements Cell {
* @see FormulaError
*/
@Override
- public byte getErrorCellValue() {
+ public byte getErrorCellValue() throws IllegalStateException {
String code = getErrorCellString();
if (code == null) {
return 0;
}
-
- return FormulaError.forString(code).getCode();
+ try {
+ return FormulaError.forString(code).getCode();
+ } catch (final IllegalArgumentException e) {
+ throw new IllegalStateException("Unexpected error code", e);
+ }
}
/**
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
index 760c215378..9eec21ec6f 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java
@@ -28,6 +28,7 @@ import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.Removal;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.model.ThemesTable;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellAlignment;
@@ -251,11 +252,13 @@ public class XSSFCellStyle implements CellStyle {
/**
* Get the type of border to use for the bottom border of the cell
+ * Will be removed when {@link #getBorderBottom()} returns a BorderStyle enum
*
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
+ * @since POI 3.15
*/
@Override
- public BorderStyle getBorderBottom() {
+ public BorderStyle getBorderBottomEnum() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
@@ -266,24 +269,26 @@ public class XSSFCellStyle implements CellStyle {
}
return BorderStyle.valueOf((short)(ptrn.intValue() - 1));
}
-
/**
* Get the type of border to use for the bottom border of the cell
+ * This will return a BorderStyle enum in the future.
*
- * @return border type as Java enum
- * @deprecated 3.15 beta 2. Use {@link #getBorderBottom}
+ * @return border type code
+ * @deprecated 3.15 beta 2. Use {@link #getBorderBottomEnum()}
*/
- public BorderStyle getBorderBottomEnum() {
- return getBorderBottom();
+ public short getBorderBottom() {
+ return getBorderBottomEnum().getCode();
}
/**
* Get the type of border to use for the left border of the cell
+ * Will be removed when {@link #getBorderLeft()} returns a BorderStyle enum
*
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
+ * @since POI 3.15
*/
@Override
- public BorderStyle getBorderLeft() {
+ public BorderStyle getBorderLeftEnum() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
@@ -297,21 +302,24 @@ public class XSSFCellStyle implements CellStyle {
/**
* Get the type of border to use for the left border of the cell
+ * This will return a BorderStyle enum in the future.
*
- * @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
- * @deprecated 3.15 beta 2. Use {@link #getBorderLeft}
+ * @return border type code
+ * @deprecated 3.15 beta 2. Use {@link #getBorderLeftEnum()}
*/
- public BorderStyle getBorderLeftEnum() {
- return getBorderLeft();
+ public short getBorderLeft() {
+ return getBorderLeftEnum().getCode();
}
/**
* Get the type of border to use for the right border of the cell
+ * Will be removed when {@link #getBorderRight()} returns a BorderStyle enum
*
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
+ * @since POI 3.15
*/
@Override
- public BorderStyle getBorderRight() {
+ public BorderStyle getBorderRightEnum() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
@@ -322,24 +330,26 @@ public class XSSFCellStyle implements CellStyle {
}
return BorderStyle.valueOf((short)(ptrn.intValue() - 1));
}
-
/**
* Get the type of border to use for the right border of the cell
+ * This will return a BorderStyle enum in the future.
*
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
- * @deprecated 3.15 beta 2. Use {@link #getBorderRight}
+ * @deprecated 3.15 beta 2. Use {@link #getBorderRightEnum()} instead
*/
- public BorderStyle getBorderRightEnum() {
- return getBorderRight();
+ public short getBorderRight() {
+ return getBorderRightEnum().getCode();
}
/**
* Get the type of border to use for the top border of the cell
+ * Will be removed when {@link #getBorderTop()} returns a BorderStyle enum
*
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
+ * @since POI 3.15
*/
@Override
- public BorderStyle getBorderTop() {
+ public BorderStyle getBorderTopEnum() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
@@ -350,15 +360,15 @@ public class XSSFCellStyle implements CellStyle {
}
return BorderStyle.valueOf((short) (ptrn.intValue() - 1));
}
-
/**
* Get the type of border to use for the top border of the cell
+ * This will return a BorderStyle enum in the future.
*
* @return border type, default value is {@link org.apache.poi.ss.usermodel.BorderStyle#NONE}
- * @deprecated 3.15 beta 2. Use {@link #getBorderTop}
+ * @deprecated 3.15 beta 2. Use {@link #getBorderTopEnum()} instead.
*/
- public BorderStyle getBorderTopEnum() {
- return getBorderTop();
+ public short getBorderTop() {
+ return getBorderTopEnum().getCode();
}
/**
@@ -775,6 +785,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.CellStyle#ALIGN_CENTER_SELECTION
* @deprecated POI 3.15 beta 3. Use {@link #setAlignment(HorizontalAlignment)} instead.
*/
+ @Removal(version="3.17")
@Override
public void setAlignment(short align) {
setAlignment(HorizontalAlignment.forInt(align));
@@ -796,6 +807,7 @@ public class XSSFCellStyle implements CellStyle {
* @param border the type of border to use
* @deprecated 3.15 beta 2. Use {@link #setBorderBottom(BorderStyle)}
*/
+ @Removal(version="3.17")
@Override
public void setBorderBottom(short border) {
setBorderBottom(BorderStyle.valueOf(border));
@@ -806,6 +818,7 @@ public class XSSFCellStyle implements CellStyle {
*
* @param border - type of border to use
* @see org.apache.poi.ss.usermodel.BorderStyle
+ * @since POI 3.15
*/
@Override
public void setBorderBottom(BorderStyle border) {
@@ -825,6 +838,7 @@ public class XSSFCellStyle implements CellStyle {
* @param border the type of border to use
* @deprecated 3.15 beta 2. Use {@link #setBorderLeft(BorderStyle)}
*/
+ @Removal(version="3.17")
@Override
public void setBorderLeft(short border) {
setBorderLeft(BorderStyle.valueOf(border));
@@ -834,6 +848,7 @@ public class XSSFCellStyle implements CellStyle {
* Set the type of border to use for the left border of the cell
*
* @param border the type of border to use
+ * @since POI 3.15
*/
@Override
public void setBorderLeft(BorderStyle border) {
@@ -854,6 +869,7 @@ public class XSSFCellStyle implements CellStyle {
* @param border the type of border to use
* @deprecated 3.15 beta 2. Use {@link #setBorderRight(BorderStyle)}
*/
+ @Removal(version="3.17")
@Override
public void setBorderRight(short border) {
setBorderRight(BorderStyle.valueOf(border));
@@ -863,6 +879,7 @@ public class XSSFCellStyle implements CellStyle {
* Set the type of border to use for the right border of the cell
*
* @param border the type of border to use
+ * @since POI 3.15
*/
@Override
public void setBorderRight(BorderStyle border) {
@@ -883,6 +900,7 @@ public class XSSFCellStyle implements CellStyle {
* @param border the type of border to use
* @deprecated 3.15 beta 2. Use {@link #setBorderTop(BorderStyle)}
*/
+ @Removal(version="3.17")
@Override
public void setBorderTop(short border) {
setBorderTop(BorderStyle.valueOf(border));
@@ -892,6 +910,7 @@ public class XSSFCellStyle implements CellStyle {
* Set the type of border to use for the top border of the cell
*
* @param border the type of border to use
+ * @since POI 3.15
*/
@Override
public void setBorderTop(BorderStyle border) {
@@ -1121,7 +1140,9 @@ public class XSSFCellStyle implements CellStyle {
* @see #setFillBackgroundColor(short)
* @see #setFillForegroundColor(short)
* @param fp fill pattern (set to {@link org.apache.poi.ss.usermodel.CellStyle#SOLID_FOREGROUND} to fill w/foreground color)
+ * @deprecated POI 3.15. Use {@link #setFillPattern(FillPatternType)} instead.
*/
+ @Removal(version="3.17")
@Override
public void setFillPattern(short fp) {
setFillPattern(FillPatternType.forInt(fp));
@@ -1335,6 +1356,7 @@ public class XSSFCellStyle implements CellStyle {
* @see org.apache.poi.ss.usermodel.VerticalAlignment
* @deprecated POI 3.15 beta 3. Use {@link #setVerticalAlignment(VerticalAlignment)} instead.
*/
+ @Removal(version="3.17")
@Override
public void setVerticalAlignment(short align) {
setVerticalAlignment(VerticalAlignment.forInt(align));
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java
index 8045912abf..df47fc227b 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFClientAnchor.java
@@ -19,6 +19,7 @@ package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.Removal;
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTMarker;
/**
@@ -218,15 +219,28 @@ public final class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
/**
* Sets the anchor type
* @param anchorType the anchor type to set
+ * @since POI 3.14
*/
@Override
public void setAnchorType( AnchorType anchorType )
{
this.anchorType = anchorType;
}
+ /**
+ * Sets the anchor type
+ * @param anchorType the anchor type to set
+ * @deprecated POI 3.15. Use {@link #setAnchorType(AnchorType)} instead
+ */
+ @Removal(version="3.17")
+ @Override
+ public void setAnchorType( int anchorType )
+ {
+ this.anchorType = AnchorType.byId(anchorType);
+ }
/**
* Gets the anchor type
+ * Changed from returning an int to an enum in POI 3.14 beta 1.
* @return the anchor type
*/
@Override
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java
index 63dc780699..cb11a73b28 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCreationHelper.java
@@ -20,6 +20,7 @@ import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.Hyperlink;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.Removal;
public class XSSFCreationHelper implements CreationHelper {
private final XSSFWorkbook workbook;
@@ -61,6 +62,7 @@ public class XSSFCreationHelper implements CreationHelper {
* @deprecated POI 3.15 beta 3. Use {@link #createHyperlink(HyperlinkType)} instead.
*/
@Deprecated
+ @Removal(version="3.17")
@Override
public XSSFHyperlink createHyperlink(int type) {
return new XSSFHyperlink(type);
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java
index e85b58017c..129052e79c 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationCell.java
@@ -58,6 +58,7 @@ final class XSSFEvaluationCell implements EvaluationCell {
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type
+ * @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override
public int getCellType() {
@@ -68,7 +69,6 @@ final class XSSFEvaluationCell implements EvaluationCell {
* @deprecated POI 3.15 beta 3.
* Will be deleted when we make the CellType enum transition. See bug 59791.
*/
- @Internal(since="POI 3.15 beta 3")
@Override
public CellType getCellTypeEnum() {
return _cell.getCellTypeEnum();
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java
index c25dfb5d6c..7d9d0286f3 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFEvaluationSheet.java
@@ -67,7 +67,28 @@ final class XSSFEvaluationSheet implements EvaluationSheet {
}
}
- return _cellCache.get(new CellKey(rowIndex, columnIndex));
+ final CellKey key = new CellKey(rowIndex, columnIndex);
+ EvaluationCell evalcell = _cellCache.get(key);
+
+ // If cache is stale, update cache with this one cell
+ // This is a compromise between rebuilding the entire cache
+ // (which would quickly defeat the benefit of the cache)
+ // and not caching at all.
+ // See bug 59958: Add cells on the fly to the evaluation sheet cache on cache miss
+ if (evalcell == null) {
+ XSSFRow row = _xs.getRow(rowIndex);
+ if (row == null) {
+ return null;
+ }
+ XSSFCell cell = row.getCell(columnIndex);
+ if (cell == null) {
+ return null;
+ }
+ evalcell = new XSSFEvaluationCell(cell, this);
+ _cellCache.put(key, evalcell);
+ }
+
+ return evalcell;
}
private static class CellKey {
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java
index fc456b7e58..e63f47b468 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFormulaEvaluator.java
@@ -23,6 +23,8 @@ import org.apache.poi.ss.formula.IStabilityClassifier;
import org.apache.poi.ss.formula.WorkbookEvaluator;
import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.CellValue;
/**
* Evaluates formula cells.
@@ -55,27 +57,6 @@ public final class XSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator {
return new XSSFFormulaEvaluator(workbook, stabilityClassifier, udfFinder);
}
- /**
- * If cell contains formula, it evaluates the formula, and
- * puts the formula result back into the cell, in place
- * of the old formula.
- * Else if cell does not contain formula, this method leaves
- * the cell unchanged.
- * Note that the same instance of XSSFCell is returned to
- * allow chained calls like:
- *
- * int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
- *
- * Be aware that your cell value will be changed to hold the
- * result of the formula. If you simply want the formula
- * value computed for you, use {@link #evaluateFormulaCellEnum(org.apache.poi.ss.usermodel.Cell)} }
- * @param cell
- */
- public XSSFCell evaluateInCell(Cell cell) {
- doEvaluateInCell(cell);
- return (XSSFCell)cell;
- }
-
/**
* Loops over all cells in all sheets of the supplied
* workbook.
@@ -90,6 +71,12 @@ public final class XSSFFormulaEvaluator extends BaseXSSFFormulaEvaluator {
public static void evaluateAllFormulaCells(XSSFWorkbook wb) {
BaseFormulaEvaluator.evaluateAllFormulaCells(wb);
}
+
+ @Override
+ public XSSFCell evaluateInCell(Cell cell) {
+ return (XSSFCell) super.evaluateInCell(cell);
+ }
+
/**
* Loops over all cells in all sheets of the supplied
* workbook.
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java
index 1f1c8421fd..9d26a6658b 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFHyperlink.java
@@ -168,6 +168,7 @@ public class XSSFHyperlink implements Hyperlink {
* @return the type of this hyperlink
* @see HyperlinkType#forInt
* @deprecated POI 3.15 beta 3. Use {@link #getTypeEnum()} instead.
+ * getType will return a HyperlinkType enum in the future.
*/
@Override
public int getType() {
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java
index 9f68649199..bf85f65de1 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPivotTable.java
@@ -30,6 +30,7 @@ import javax.xml.namespace.QName;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationship;
+import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataConsolidateFunction;
@@ -213,24 +214,43 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
}
protected AreaReference getPivotArea() {
- AreaReference pivotArea = new AreaReference(getPivotCacheDefinition().
- getCTPivotCacheDefinition().getCacheSource().getWorksheetSource().getRef());
+ AreaReference pivotArea = new AreaReference(
+ getPivotCacheDefinition()
+ .getCTPivotCacheDefinition()
+ .getCacheSource()
+ .getWorksheetSource()
+ .getRef(),
+ SpreadsheetVersion.EXCEL2007);
return pivotArea;
}
+
+ /**
+ * Verify column index (relative to first column in pivot area) is within the
+ * pivot area
+ *
+ * @param columnIndex
+ * @throws IndexOutOfBoundsException
+ */
+ private void checkColumnIndex(int columnIndex) throws IndexOutOfBoundsException {
+ AreaReference pivotArea = getPivotArea();
+ int size = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol() + 1;
+
+ if (columnIndex < 0 || columnIndex >= size) {
+ throw new IndexOutOfBoundsException("Column Index: " + columnIndex + ", Size: " + size);
+ }
+ }
/**
* Add a row label using data from the given column.
- * @param columnIndex the index of the column to be used as row label.
+ * @param columnIndex the index of the source column to be used as row label.
+ * {@code columnIndex} is 0-based indexed and relative to the first column in the source.
*/
@Beta
public void addRowLabel(int columnIndex) {
+ checkColumnIndex(columnIndex);
+
AreaReference pivotArea = getPivotArea();
- int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow();
- int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol();
-
- if(columnIndex > lastColIndex) {
- throw new IndexOutOfBoundsException();
- }
+ final int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow();
CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
CTPivotField pivotField = CTPivotField.Factory.newInstance();
@@ -238,7 +258,7 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
pivotField.setAxis(STAxis.AXIS_ROW);
pivotField.setShowAll(false);
- for(int i = 0; i <= lastRowIndex; i++) {
+ for (int i = 0; i <= lastRowIndex; i++) {
items.addNewItem().setT(STItemType.DEFAULT);
}
items.setCount(items.sizeOfItemArray());
@@ -270,7 +290,8 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
/**
* Add a column label using data from the given column and specified function
- * @param columnIndex the index of the column to be used as column label.
+ * @param columnIndex the index of the source column to be used as column label.
+ * {@code columnIndex} is 0-based indexed and relative to the first column in the source.
* @param function the function to be used on the data
* The following functions exists:
* Sum, Count, Average, Max, Min, Product, Count numbers, StdDev, StdDevp, Var, Varp
@@ -278,12 +299,7 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
*/
@Beta
public void addColumnLabel(DataConsolidateFunction function, int columnIndex, String valueFieldName) {
- AreaReference pivotArea = getPivotArea();
- int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol();
-
- if(columnIndex > lastColIndex && columnIndex < 0) {
- throw new IndexOutOfBoundsException();
- }
+ checkColumnIndex(columnIndex);
addDataColumn(columnIndex, true);
addDataField(function, columnIndex, valueFieldName);
@@ -303,7 +319,8 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
/**
* Add a column label using data from the given column and specified function
- * @param columnIndex the index of the column to be used as column label.
+ * @param columnIndex the index of the source column to be used as column label
+ * {@code columnIndex} is 0-based indexed and relative to the first column in the source..
* @param function the function to be used on the data
* The following functions exists:
* Sum, Count, Average, Max, Min, Product, Count numbers, StdDev, StdDevp, Var, Varp
@@ -323,12 +340,10 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
*/
@Beta
private void addDataField(DataConsolidateFunction function, int columnIndex, String valueFieldName) {
+ checkColumnIndex(columnIndex);
+
AreaReference pivotArea = getPivotArea();
- int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol();
-
- if(columnIndex > lastColIndex && columnIndex < 0) {
- throw new IndexOutOfBoundsException();
- }
+
CTDataFields dataFields;
if(pivotTableDefinition.getDataFields() != null) {
dataFields = pivotTableDefinition.getDataFields();
@@ -352,11 +367,8 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
*/
@Beta
public void addDataColumn(int columnIndex, boolean isDataField) {
- AreaReference pivotArea = getPivotArea();
- int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol();
- if(columnIndex > lastColIndex && columnIndex < 0) {
- throw new IndexOutOfBoundsException();
- }
+ checkColumnIndex(columnIndex);
+
CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
CTPivotField pivotField = CTPivotField.Factory.newInstance();
@@ -371,13 +383,11 @@ public class XSSFPivotTable extends POIXMLDocumentPart {
*/
@Beta
public void addReportFilter(int columnIndex) {
+ checkColumnIndex(columnIndex);
+
AreaReference pivotArea = getPivotArea();
- int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol();
int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow();
- if(columnIndex > lastColIndex && columnIndex < 0) {
- throw new IndexOutOfBoundsException();
- }
CTPivotFields pivotFields = pivotTableDefinition.getPivotFields();
CTPivotField pivotField = CTPivotField.Factory.newInstance();
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
index 5f1da12ecc..d72dca445e 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
@@ -591,20 +591,21 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
}
} else {
//search the referenced drawing in the list of the sheet's relations
+ final String id = ctDrawing.getId();
for (RelationPart rp : getRelationParts()){
POIXMLDocumentPart p = rp.getDocumentPart();
if(p instanceof XSSFVMLDrawing) {
XSSFVMLDrawing dr = (XSSFVMLDrawing)p;
String drId = rp.getRelationship().getId();
- if(drId.equals(ctDrawing.getId())){
+ if (drId.equals(id)) {
drawing = dr;
break;
}
- break;
+ // do not break here since drawing has not been found yet (see bug 52425)
}
}
if(drawing == null){
- logger.log(POILogger.ERROR, "Can't find VML drawing with id=" + ctDrawing.getId() + " in the list of the sheet's relationships");
+ logger.log(POILogger.ERROR, "Can't find VML drawing with id=" + id + " in the list of the sheet's relationships");
}
}
return drawing;
@@ -4164,9 +4165,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
* @return The pivot table
*/
@Beta
- public XSSFPivotTable createPivotTable(AreaReference source, CellReference position, Sheet sourceSheet){
-
- if(source.getFirstCell().getSheetName() != null && !source.getFirstCell().getSheetName().equals(sourceSheet.getSheetName())) {
+ public XSSFPivotTable createPivotTable(AreaReference source, CellReference position, Sheet sourceSheet) {
+ final String sourceSheetName = source.getFirstCell().getSheetName();
+ if(sourceSheetName != null && !sourceSheetName.equalsIgnoreCase(sourceSheet.getSheetName())) {
throw new IllegalArgumentException("The area is referenced in another sheet than the "
+ "defined source sheet " + sourceSheet.getSheetName() + ".");
}
@@ -4192,8 +4193,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/
@Beta
public XSSFPivotTable createPivotTable(AreaReference source, CellReference position){
- if(source.getFirstCell().getSheetName() != null && !source.getFirstCell().getSheetName().equals(this.getSheetName())) {
- return createPivotTable(source, position, getWorkbook().getSheet(source.getFirstCell().getSheetName()));
+ final String sourceSheetName = source.getFirstCell().getSheetName();
+ if(sourceSheetName != null && !sourceSheetName.equalsIgnoreCase(this.getSheetName())) {
+ final XSSFSheet sourceSheet = getWorkbook().getSheet(sourceSheetName);
+ return createPivotTable(source, position, sourceSheet);
}
return createPivotTable(source, position, this);
}
diff --git a/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java b/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java
index 9d25d8e054..16b28a4507 100644
--- a/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java
+++ b/src/ooxml/testcases/org/apache/poi/TestPOIXMLDocument.java
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
import java.io.File;
import java.io.FileOutputStream;
@@ -33,9 +34,11 @@ import java.util.HashSet;
import java.util.List;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.exceptions.OpenXML4JRuntimeException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.openxml4j.opc.PackagePart;
import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
+import org.apache.poi.util.NullOutputStream;
import org.apache.poi.util.PackageHelper;
import org.apache.poi.util.TempFile;
import org.junit.Test;
@@ -120,12 +123,43 @@ public final class TestPOIXMLDocument {
FileOutputStream out = new FileOutputStream(tmp);
doc.write(out);
out.close();
+
+ // Should not be able to write to an output stream that has been closed
+ try {
+ doc.write(out);
+ fail("Should not be able to write to an output stream that has been closed.");
+ } catch (final OpenXML4JRuntimeException e) {
+ // FIXME: A better exception class (IOException?) and message should be raised
+ // indicating that the document could not be written because the output stream is closed.
+ // see {@link org.apache.poi.openxml4j.opc.ZipPackage#saveImpl(java.io.OutputStream)}
+ if (e.getMessage().matches("Fail to save: an error occurs while saving the package : The part .+ fail to be saved in the stream with marshaller .+")) {
+ // expected
+ } else {
+ throw e;
+ }
+ }
+
+ // Should not be able to write a document that has been closed
doc.close();
+ try {
+ doc.write(new NullOutputStream());
+ fail("Should not be able to write a document that has been closed.");
+ } catch (final IOException e) {
+ if (e.getMessage().equals("Cannot write data, document seems to have been closed already")) {
+ // expected
+ } else {
+ throw e;
+ }
+ }
+
+ // Should be able to close a document multiple times, though subsequent closes will have no effect.
+ doc.close();
+
@SuppressWarnings("resource")
OPCPackage pkg2 = OPCPackage.open(tmp.getAbsolutePath());
+ doc = new OPCParser(pkg1);
try {
- doc = new OPCParser(pkg1);
doc.parse(new TestFactory());
context = new HashMap();
traverse(doc, context);
@@ -150,6 +184,7 @@ public final class TestPOIXMLDocument {
}
} finally {
doc.close();
+ pkg1.close();
pkg2.close();
}
}
diff --git a/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java b/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java
index 0aa022332e..9d206f7197 100644
--- a/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java
+++ b/src/ooxml/testcases/org/apache/poi/extractor/TestExtractorFactory.java
@@ -682,9 +682,12 @@ public class TestExtractorFactory {
// Text
try {
ExtractorFactory.createExtractor(OPCPackage.open(txt.toString()));
- fail();
+ fail("TestExtractorFactory.testPackage() failed on " + txt.toString());
} catch(UnsupportedFileFormatException e) {
// Good
+ } catch (Exception e) {
+ System.out.println("TestExtractorFactory.testPackage() failed on " + txt.toString());
+ throw e;
}
}
@@ -942,6 +945,7 @@ public class TestExtractorFactory {
"openxml4j/OPCCompliance_CoreProperties_OnlyOneCorePropertiesPartFAIL.docx",
"openxml4j/OPCCompliance_CoreProperties_UnauthorizedXMLLangAttributeFAIL.docx",
"openxml4j/OPCCompliance_DerivedPartNameFAIL.docx",
+ "openxml4j/invalid.xlsx",
"spreadsheet/54764-2.xlsx", // see TestXSSFBugs.bug54764()
"spreadsheet/54764.xlsx", // see TestXSSFBugs.bug54764()
"spreadsheet/Simple.xlsb",
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
index d84ecab81b..5f83bc52d0 100644
--- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
+++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestPackage.java
@@ -943,4 +943,22 @@ public final class TestPackage {
ZipSecureFile.setMaxTextSize(before);
}
}
+
+ // bug 60128
+ @Test
+ public void testCorruptFile() throws IOException {
+ OPCPackage pkg = null;
+ File file = OpenXML4JTestDataSamples.getSampleFile("invalid.xlsx");
+ try {
+ pkg = OPCPackage.open(file, PackageAccess.READ);
+ } catch (Exception e) {
+ System.out.println(e.getClass().getName());
+ System.out.println(e.getMessage());
+ e.printStackTrace();
+ } finally {
+ if (pkg != null) {
+ pkg.close();
+ }
+ }
+ }
}
diff --git a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestZipPackage.java b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestZipPackage.java
index 7f174e07af..0989d10cb2 100644
--- a/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestZipPackage.java
+++ b/src/ooxml/testcases/org/apache/poi/openxml4j/opc/TestZipPackage.java
@@ -33,11 +33,14 @@ import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
+import org.apache.poi.POIDataSamples;
import org.apache.poi.POITextExtractor;
import org.apache.poi.POIXMLException;
import org.apache.poi.extractor.ExtractorFactory;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.openxml4j.OpenXML4JTestDataSamples;
+import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException;
+import org.apache.poi.openxml4j.exceptions.ODFNotOfficeXmlFileException;
import org.apache.poi.sl.usermodel.SlideShow;
import org.apache.poi.sl.usermodel.SlideShowFactory;
import org.apache.poi.ss.usermodel.Workbook;
@@ -181,6 +184,7 @@ public class TestZipPackage {
public void testClosingStreamOnException() throws IOException {
InputStream is = OpenXML4JTestDataSamples.openSampleStream("dcterms_bug_56479.zip");
File tmp = File.createTempFile("poi-test-truncated-zip", "");
+ // create a corrupted zip file by truncating a valid zip file to the first 100 bytes
OutputStream os = new FileOutputStream(tmp);
for (int i = 0; i < 100; i++) {
os.write(is.read());
@@ -189,11 +193,63 @@ public class TestZipPackage {
os.close();
is.close();
+ // feed the corrupted zip file to OPCPackage
try {
OPCPackage.open(tmp, PackageAccess.READ);
} catch (Exception e) {
+ // expected: the zip file is invalid
+ // this test does not care if open() throws an exception or not.
}
+ // If the stream is not closed on exception, it will keep a file descriptor to tmp,
+ // and requests to the OS to delete the file will fail.
assertTrue("Can't delete tmp file", tmp.delete());
+ }
+
+ /**
+ * If ZipPackage is passed an invalid file, a call to close
+ * (eg from the OPCPackage open method) should tidy up the
+ * stream / file the broken file is being read from.
+ * See bug #60128 for more
+ */
+ @Test
+ public void testTidyStreamOnInvalidFile() throws Exception {
+ // Spreadsheet has a good mix of alternate file types
+ POIDataSamples files = POIDataSamples.getSpreadSheetInstance();
+
+ File[] notValidF = new File[] {
+ files.getFile("SampleSS.ods"), files.getFile("SampleSS.txt")
+ };
+ InputStream[] notValidS = new InputStream[] {
+ files.openResourceAsStream("SampleSS.ods"), files.openResourceAsStream("SampleSS.txt")
+ };
+ for (File notValid : notValidF) {
+ ZipPackage pkg = new ZipPackage(notValid, PackageAccess.READ);
+ assertNotNull(pkg.getZipArchive());
+ assertFalse(pkg.getZipArchive().isClosed());
+ try {
+ pkg.getParts();
+ fail("Shouldn't work");
+ } catch (ODFNotOfficeXmlFileException e) {
+ } catch (NotOfficeXmlFileException ne) {}
+ pkg.close();
+
+ assertNotNull(pkg.getZipArchive());
+ assertTrue(pkg.getZipArchive().isClosed());
+ }
+ for (InputStream notValid : notValidS) {
+ ZipPackage pkg = new ZipPackage(notValid, PackageAccess.READ);
+ assertNotNull(pkg.getZipArchive());
+ assertFalse(pkg.getZipArchive().isClosed());
+ try {
+ pkg.getParts();
+ fail("Shouldn't work");
+ } catch (ODFNotOfficeXmlFileException e) {
+ } catch (NotOfficeXmlFileException ne) {}
+ pkg.close();
+
+ assertNotNull(pkg.getZipArchive());
+ assertTrue(pkg.getZipArchive().isClosed());
+ }
}
}
diff --git a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSecureTempZip.java b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSecureTempZip.java
index 4d4c5df345..868a382279 100644
--- a/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSecureTempZip.java
+++ b/src/ooxml/testcases/org/apache/poi/poifs/crypt/TestSecureTempZip.java
@@ -149,10 +149,12 @@ public class TestSecureTempZip {
static class AesZipFileZipEntrySource implements ZipEntrySource {
final ZipFile zipFile;
final Cipher ci;
+ boolean closed;
AesZipFileZipEntrySource(ZipFile zipFile, Cipher ci) {
this.zipFile = zipFile;
this.ci = ci;
+ this.closed = false;
}
/**
@@ -172,6 +174,12 @@ public class TestSecureTempZip {
@Override
public void close() throws IOException {
zipFile.close();
+ closed = true;
+ }
+
+ @Override
+ public boolean isClosed() {
+ return closed;
}
}
}
diff --git a/src/ooxml/testcases/org/apache/poi/ss/formula/TestStructuredReferences.java b/src/ooxml/testcases/org/apache/poi/ss/formula/TestStructuredReferences.java
index 4e176257f6..b60664ad02 100644
--- a/src/ooxml/testcases/org/apache/poi/ss/formula/TestStructuredReferences.java
+++ b/src/ooxml/testcases/org/apache/poi/ss/formula/TestStructuredReferences.java
@@ -110,7 +110,7 @@ public class TestStructuredReferences {
private static void confirm(FormulaEvaluator fe, Cell cell, double expectedResult) {
fe.clearAllCachedResultValues();
CellValue cv = fe.evaluate(cell);
- if (cv.getCellType() != CellType.NUMERIC) {
+ if (cv.getCellTypeEnum() != CellType.NUMERIC) {
fail("expected numeric cell type but got " + cv.formatAsString());
}
assertEquals(expectedResult, cv.getNumberValue(), 0.0);
@@ -119,7 +119,7 @@ public class TestStructuredReferences {
private static void confirm(FormulaEvaluator fe, Cell cell, String expectedResult) {
fe.clearAllCachedResultValues();
CellValue cv = fe.evaluate(cell);
- if (cv.getCellType() != CellType.STRING) {
+ if (cv.getCellTypeEnum() != CellType.STRING) {
fail("expected String cell type but got " + cv.formatAsString());
}
assertEquals(expectedResult, cv.getStringValue());
diff --git a/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java b/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java
index d86079eca5..a24fd88795 100644
--- a/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java
+++ b/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java
@@ -96,7 +96,7 @@ public final class TestProper {
cell11.setCellFormula(formulaText);
evaluator.clearAllCachedResultValues();
CellValue cv = evaluator.evaluate(cell11);
- if (cv.getCellType() != CellType.STRING) {
+ if (cv.getCellTypeEnum() != CellType.STRING) {
throw new AssertionFailedError("Wrong result type: " + cv.formatAsString());
}
String actualValue = cv.getStringValue();
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableRow.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableRow.java
new file mode 100644
index 0000000000..8a08928193
--- /dev/null
+++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableRow.java
@@ -0,0 +1,131 @@
+/* ====================================================================
+ 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.xslf.usermodel;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.apache.poi.xslf.XSLFTestDataSamples;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTableCell;
+import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
+
+public class TestXSLFTableRow {
+
+ private static XMLSlideShow ppt;
+ private static XSLFTable tbl;
+ private static XSLFTableRow row;
+
+ /** Copied from {@link TestXSLFTable#testRead()} */
+ @Before
+ public void setUp() throws IOException {
+ ppt = XSLFTestDataSamples.openSampleDocument("shapes.pptx");
+
+ XSLFSlide slide = ppt.getSlides().get(3);
+ List shapes = slide.getShapes();
+ tbl = (XSLFTable)shapes.get(0);
+ List rows = tbl.getRows();
+ row = rows.get(0);
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ ppt.getPackage().revert();
+ ppt.close();
+ }
+
+
+ @Test
+ public void constructor() {
+ XSLFTableRow row2 = new XSLFTableRow(row.getXmlObject(), tbl);
+ assertSame(row.getXmlObject(), row2.getXmlObject());
+ assertEquals(row.getHeight(), row2.getHeight(), 1e-16);
+ }
+
+ @Test
+ public void testHeight() {
+ final double h = 10.0;
+ row.setHeight(h);
+ assertEquals(h, row.getHeight(), 1e-16);
+ }
+
+ /** copied from {@link TestXSLFTable#testCreate()} */
+ @Test
+ public void getCells() {
+ List cells = row.getCells();
+ assertNotNull(cells);
+ assertEquals(3, cells.size());
+ }
+
+ @Test
+ public void testIterator() {
+ int i = 0;
+ for (XSLFTableCell cell : row) {
+ i++;
+ assertEquals("header"+i, cell.getText());
+ }
+ assertEquals(3, i);
+ }
+
+ /** copied from {@link TestXSLFTable#testCreate()} */
+ @Test
+ public void addCell() {
+ XSLFTableCell cell = row.addCell();
+ assertNotNull(cell);
+
+ assertNotNull(cell.getXmlObject());
+ // by default table cell has no borders
+ CTTableCell tc = (CTTableCell)cell.getXmlObject();
+ assertTrue(tc.getTcPr().getLnB().isSetNoFill());
+ assertTrue(tc.getTcPr().getLnT().isSetNoFill());
+ assertTrue(tc.getTcPr().getLnL().isSetNoFill());
+ assertTrue(tc.getTcPr().getLnR().isSetNoFill());
+ }
+
+ @Test
+ public void mergeCells() {
+ try {
+ row.mergeCells(0, 0);
+ fail("expected IllegalArgumentException when merging fewer than 2 columns");
+ } catch (final IllegalArgumentException e) {
+ // expected
+ }
+
+ row.mergeCells(0, 1);
+ List cells = row.getCells();
+ //the top-left cell of a merged region is not regarded as merged
+ assertFalse("top-left cell of merged region", cells.get(0).isMerged());
+ assertTrue("inside merged region", cells.get(1).isMerged());
+ assertFalse("outside merged region", cells.get(2).isMerged());
+ }
+
+ @Test
+ public void getXmlObject() {
+ CTTableRow ctrow = row.getXmlObject();
+ assertNotNull(ctrow);
+ }
+
+}
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 67ebe1ef00..7b5a67de58 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/streaming/TestSXSSFWorkbook.java
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -35,6 +36,8 @@ import java.util.Arrays;
import org.apache.poi.POIDataSamples;
import org.apache.poi.POITestCase;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.openxml4j.opc.PackageAccess;
import org.apache.poi.ss.usermodel.BaseTestXWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
@@ -43,6 +46,7 @@ import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.util.NullOutputStream;
import org.apache.poi.xssf.SXSSFITestDataProvider;
import org.apache.poi.xssf.XSSFTestDataSamples;
import org.apache.poi.xssf.model.SharedStringsTable;
@@ -535,4 +539,40 @@ public final class TestSXSSFWorkbook extends BaseTestXWorkbook {
swb.dispose();
swb.close();
}
+
+ /**
+ * To avoid accident changes to the template, you should be able
+ * to create a SXSSFWorkbook from a read-only XSSF one, then
+ * change + save that (only). See bug #60010
+ * TODO Fix this to work!
+ */
+ @Test
+ @Ignore
+ public void createFromReadOnlyWorkbook() throws Exception {
+ File input = XSSFTestDataSamples.getSampleFile("sample.xlsx");
+ OPCPackage pkg = OPCPackage.open(input, PackageAccess.READ);
+ XSSFWorkbook xssf = new XSSFWorkbook(pkg);
+ SXSSFWorkbook wb = new SXSSFWorkbook(xssf, 2);
+
+ String sheetName = "Test SXSSF";
+ Sheet s = wb.createSheet(sheetName);
+ for (int i=0; i<10; i++) {
+ Row r = s.createRow(i);
+ r.createCell(0).setCellValue(true);
+ r.createCell(1).setCellValue(2.4);
+ r.createCell(2).setCellValue("Test Row " + i);
+ }
+ assertEquals(10, s.getLastRowNum());
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ wb.write(bos);
+ wb.dispose();
+ wb.close();
+
+ xssf = new XSSFWorkbook(new ByteArrayInputStream(bos.toByteArray()));
+ s = xssf.getSheet(sheetName);
+ assertEquals(10, s.getLastRowNum());
+ assertEquals(true, s.getRow(0).getCell(0).getBooleanCellValue());
+ assertEquals("Test Row 9", s.getRow(9).getCell(2).getStringCellValue());
+ }
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/AllXSSFUsermodelTests.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/AllXSSFUsermodelTests.java
index 96b363283b..6ecad0a74f 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/AllXSSFUsermodelTests.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/AllXSSFUsermodelTests.java
@@ -59,7 +59,7 @@ import org.junit.runners.Suite;
TestXSSFSheetComments.class,
TestColumnHelper.class,
TestHeaderFooterHelper.class,
- TestXSSFPivotTable.class,
+ //TestXSSFPivotTable.class, //converted to junit4
TestForkedEvaluator.class
})
public final class AllXSSFUsermodelTests {
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java
index 4cbc7c4e61..ad8b49028d 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestFormulaEvaluatorOnXSSF.java
@@ -205,14 +205,14 @@ public final class TestFormulaEvaluatorOnXSSF {
final CellType expectedCellType = expValue.getCellTypeEnum();
switch (expectedCellType) {
case BLANK:
- assertEquals(msg, CellType.BLANK, actValue.getCellType());
+ assertEquals(msg, CellType.BLANK, actValue.getCellTypeEnum());
break;
case BOOLEAN:
- assertEquals(msg, CellType.BOOLEAN, actValue.getCellType());
+ assertEquals(msg, CellType.BOOLEAN, actValue.getCellTypeEnum());
assertEquals(msg, expValue.getBooleanCellValue(), actValue.getBooleanValue());
break;
case ERROR:
- assertEquals(msg, CellType.ERROR, actValue.getCellType());
+ assertEquals(msg, CellType.ERROR, actValue.getCellTypeEnum());
// if(false) { // TODO: fix ~45 functions which are currently returning incorrect error values
// assertEquals(msg, expValue.getErrorCellValue(), actValue.getErrorValue());
// }
@@ -220,14 +220,14 @@ public final class TestFormulaEvaluatorOnXSSF {
case FORMULA: // will never be used, since we will call method after formula evaluation
fail("Cannot expect formula as result of formula evaluation: " + msg);
case NUMERIC:
- assertEquals(msg, CellType.NUMERIC, actValue.getCellType());
+ assertEquals(msg, CellType.NUMERIC, actValue.getCellTypeEnum());
TestMathX.assertEquals(msg, expValue.getNumericCellValue(), actValue.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR);
// double delta = Math.abs(expValue.getNumericCellValue()-actValue.getNumberValue());
// double pctExpValue = Math.abs(0.00001*expValue.getNumericCellValue());
// assertTrue(msg, delta <= pctExpValue);
break;
case STRING:
- assertEquals(msg, CellType.STRING, actValue.getCellType());
+ assertEquals(msg, CellType.STRING, actValue.getCellTypeEnum());
assertEquals(msg, expValue.getRichStringCellValue().getString(), actValue.getStringValue());
break;
default:
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java
index f33d96e637..b8926a3cf5 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultiSheetFormulaEvaluatorOnXSSF.java
@@ -188,14 +188,14 @@ public final class TestMultiSheetFormulaEvaluatorOnXSSF {
final CellType expectedCellType = expValue.getCellTypeEnum();
switch (expectedCellType) {
case BLANK:
- assertEquals(msg, CellType.BLANK, actValue.getCellType());
+ assertEquals(msg, CellType.BLANK, actValue.getCellTypeEnum());
break;
case BOOLEAN:
- assertEquals(msg, CellType.BOOLEAN, actValue.getCellType());
+ assertEquals(msg, CellType.BOOLEAN, actValue.getCellTypeEnum());
assertEquals(msg, expValue.getBooleanCellValue(), actValue.getBooleanValue());
break;
case ERROR:
- assertEquals(msg, CellType.ERROR, actValue.getCellType());
+ assertEquals(msg, CellType.ERROR, actValue.getCellTypeEnum());
// if(false) { // TODO: fix ~45 functions which are currently returning incorrect error values
// assertEquals(msg, expected.getErrorCellValue(), actual.getErrorValue());
// }
@@ -203,14 +203,14 @@ public final class TestMultiSheetFormulaEvaluatorOnXSSF {
case FORMULA: // will never be used, since we will call method after formula evaluation
fail("Cannot expect formula as result of formula evaluation: " + msg);
case NUMERIC:
- assertEquals(msg, CellType.NUMERIC, actValue.getCellType());
+ assertEquals(msg, CellType.NUMERIC, actValue.getCellTypeEnum());
TestMathX.assertEquals(msg, expValue.getNumericCellValue(), actValue.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR);
// double delta = Math.abs(expected.getNumericCellValue()-actual.getNumberValue());
// double pctExpected = Math.abs(0.00001*expected.getNumericCellValue());
// assertTrue(msg, delta <= pctExpected);
break;
case STRING:
- assertEquals(msg, CellType.STRING, actValue.getCellType());
+ assertEquals(msg, CellType.STRING, actValue.getCellTypeEnum());
assertEquals(msg, expValue.getRichStringCellValue().getString(), actValue.getStringValue());
break;
default:
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
index 2be21e830c..e695f385f9 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java
@@ -304,7 +304,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
if(c.getCellTypeEnum() == CellType.FORMULA) {
CellValue cv = eval.evaluate(c);
- if(cv.getCellType() == CellType.NUMERIC) {
+ if(cv.getCellTypeEnum() == CellType.NUMERIC) {
// assert that the calculated value agrees with
// the cached formula result calculated by Excel
String formula = c.getCellFormula();
@@ -2187,7 +2187,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
assertEquals("E4+E5", cell.getCellFormula());
CellValue value = evaluator.evaluate(cell);
- assertEquals(CellType.ERROR, value.getCellType());
+ assertEquals(CellType.ERROR, value.getCellTypeEnum());
assertEquals(-60, value.getErrorValue());
assertEquals("~CIRCULAR~REF~", FormulaError.forInt(value.getErrorValue()).getString());
assertEquals("CIRCULAR_REF", FormulaError.forInt(value.getErrorValue()).toString());
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
index 94e40a3a72..c907d40db3 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java
@@ -104,11 +104,11 @@ public class TestXSSFCellStyle {
@Test
public void testGetSetBorderBottom() {
//default values
- assertEquals(BorderStyle.NONE, cellStyle.getBorderBottom());
+ assertEquals(BorderStyle.NONE, cellStyle.getBorderBottomEnum());
int num = stylesTable.getBorders().size();
cellStyle.setBorderBottom(BorderStyle.MEDIUM);
- assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottom());
+ assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottomEnum());
//a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
@@ -122,7 +122,7 @@ public class TestXSSFCellStyle {
//setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) {
cellStyle.setBorderBottom(BorderStyle.MEDIUM);
- assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottom());
+ assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderBottomEnum());
}
assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size());
@@ -139,11 +139,11 @@ public class TestXSSFCellStyle {
@Test
public void testGetSetBorderRight() {
//default values
- assertEquals(BorderStyle.NONE, cellStyle.getBorderRight());
+ assertEquals(BorderStyle.NONE, cellStyle.getBorderRightEnum());
int num = stylesTable.getBorders().size();
cellStyle.setBorderRight(BorderStyle.MEDIUM);
- assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRight());
+ assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRightEnum());
//a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
@@ -157,7 +157,7 @@ public class TestXSSFCellStyle {
//setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) {
cellStyle.setBorderRight(BorderStyle.MEDIUM);
- assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRight());
+ assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderRightEnum());
}
assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size());
@@ -174,11 +174,11 @@ public class TestXSSFCellStyle {
@Test
public void testGetSetBorderLeft() {
//default values
- assertEquals(BorderStyle.NONE, cellStyle.getBorderLeft());
+ assertEquals(BorderStyle.NONE, cellStyle.getBorderLeftEnum());
int num = stylesTable.getBorders().size();
cellStyle.setBorderLeft(BorderStyle.MEDIUM);
- assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeft());
+ assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeftEnum());
//a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
@@ -192,7 +192,7 @@ public class TestXSSFCellStyle {
//setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) {
cellStyle.setBorderLeft(BorderStyle.MEDIUM);
- assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeft());
+ assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderLeftEnum());
}
assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size());
@@ -209,11 +209,11 @@ public class TestXSSFCellStyle {
@Test
public void testGetSetBorderTop() {
//default values
- assertEquals(BorderStyle.NONE, cellStyle.getBorderTop());
+ assertEquals(BorderStyle.NONE, cellStyle.getBorderTopEnum());
int num = stylesTable.getBorders().size();
cellStyle.setBorderTop(BorderStyle.MEDIUM);
- assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTop());
+ assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTopEnum());
//a new border has been added
assertEquals(num + 1, stylesTable.getBorders().size());
//id of the created border
@@ -227,7 +227,7 @@ public class TestXSSFCellStyle {
//setting the same border multiple times should not change borderId
for (int i = 0; i < 3; i++) {
cellStyle.setBorderTop(BorderStyle.MEDIUM);
- assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTop());
+ assertEquals(BorderStyle.MEDIUM, cellStyle.getBorderTopEnum());
}
assertEquals(borderId, cellStyle.getCoreXf().getBorderId());
assertEquals(num, stylesTable.getBorders().size());
@@ -243,7 +243,7 @@ public class TestXSSFCellStyle {
private void testGetSetBorderXMLBean(BorderStyle border, STBorderStyle.Enum expected) {
cellStyle.setBorderTop(border);
- assertEquals(border, cellStyle.getBorderTop());
+ assertEquals(border, cellStyle.getBorderTopEnum());
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
@@ -256,7 +256,7 @@ public class TestXSSFCellStyle {
@Test
public void testGetSetBorderNone() {
cellStyle.setBorderTop(BorderStyle.NONE);
- assertEquals(BorderStyle.NONE, cellStyle.getBorderTop());
+ assertEquals(BorderStyle.NONE, cellStyle.getBorderTopEnum());
int borderId = (int)cellStyle.getCoreXf().getBorderId();
assertTrue(borderId > 0);
//check changes in the underlying xml bean
@@ -562,10 +562,10 @@ public class TestXSSFCellStyle {
assertEquals(style2.getRightBorderColor(), style1.getRightBorderColor());
assertEquals(style2.getBottomBorderColor(), style1.getBottomBorderColor());
- assertEquals(style2.getBorderBottom(), style1.getBorderBottom());
- assertEquals(style2.getBorderLeft(), style1.getBorderLeft());
- assertEquals(style2.getBorderRight(), style1.getBorderRight());
- assertEquals(style2.getBorderTop(), style1.getBorderTop());
+ assertEquals(style2.getBorderBottomEnum(), style1.getBorderBottomEnum());
+ assertEquals(style2.getBorderLeftEnum(), style1.getBorderLeftEnum());
+ assertEquals(style2.getBorderRightEnum(), style1.getBorderRightEnum());
+ assertEquals(style2.getBorderTopEnum(), style1.getBorderTopEnum());
wb2.close();
}
@@ -999,7 +999,7 @@ public class TestXSSFCellStyle {
Workbook copy = XSSFTestDataSamples.writeOutAndReadBack(target);
// previously this failed because the border-element was not copied over
- copy.getCellStyleAt((short)1).getBorderBottom();
+ copy.getCellStyleAt((short)1).getBorderBottomEnum();
copy.close();
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java
index 6dcaef9603..84a4aa6800 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFFormulaEvaluation.java
@@ -682,4 +682,15 @@ public final class TestXSSFFormulaEvaluation extends BaseTestFormulaEvaluator {
value = evaluator.evaluate(cell);
assertEquals(1, value.getNumberValue(), 0.001);
}
+
+ @Test
+ public void evaluateInCellReturnsSameDataType() throws IOException {
+ XSSFWorkbook wb = new XSSFWorkbook();
+ wb.createSheet().createRow(0).createCell(0);
+ XSSFFormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
+ XSSFCell cell = wb.getSheetAt(0).getRow(0).getCell(0);
+ XSSFCell same = evaluator.evaluateInCell(cell);
+ assertSame(cell, same);
+ wb.close();
+ }
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java
index 55fe4a4fa5..851ca33d62 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFPivotTable.java
@@ -16,30 +16,39 @@
==================================================================== */
package org.apache.poi.xssf.usermodel;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DataConsolidateFunction;
import org.apache.poi.ss.usermodel.Row;
-import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.AreaReference;
import org.apache.poi.ss.util.CellReference;
+import org.apache.poi.xssf.XSSFITestDataProvider;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageField;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageFields;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotFields;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPivotTableDefinition;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STDataConsolidateFunction;
-import junit.framework.TestCase;
-
-public class TestXSSFPivotTable extends TestCase {
+public class TestXSSFPivotTable {
+ private static final XSSFITestDataProvider _testDataProvider = XSSFITestDataProvider.instance;
+ private XSSFWorkbook wb;
private XSSFPivotTable pivotTable;
private XSSFPivotTable offsetPivotTable;
private Cell offsetOuterCell;
- @Override
+ @Before
public void setUp(){
- Workbook wb = new XSSFWorkbook();
- XSSFSheet sheet = (XSSFSheet) wb.createSheet();
+ wb = new XSSFWorkbook();
+ XSSFSheet sheet = wb.createSheet();
Row row1 = sheet.createRow(0);
// Create a cell and put a value in it.
@@ -72,10 +81,10 @@ public class TestXSSFPivotTable extends TestCase {
Cell cell12 = row1.createCell(3);
cell12.setCellValue(12.12);
- AreaReference source = new AreaReference("A1:C2");
+ AreaReference source = new AreaReference("A1:C2", _testDataProvider.getSpreadsheetVersion());
pivotTable = sheet.createPivotTable(source, new CellReference("H5"));
- XSSFSheet offsetSheet = (XSSFSheet) wb.createSheet();
+ XSSFSheet offsetSheet = wb.createSheet();
Row tableRow_1 = offsetSheet.createRow(1);
offsetOuterCell = tableRow_1.createCell(1);
@@ -114,11 +123,19 @@ public class TestXSSFPivotTable extends TestCase {
AreaReference offsetSource = new AreaReference(new CellReference("C2"), new CellReference("E4"));
offsetPivotTable = offsetSheet.createPivotTable(offsetSource, new CellReference("C6"));
}
+
+ @After
+ public void tearDown() throws IOException {
+ XSSFWorkbook wb2 = _testDataProvider.writeOutAndReadBack(wb);
+ wb.close();
+ wb2.close();
+ }
/**
* Verify that when creating a row label it's created on the correct row
* and the count is increased by one.
*/
+ @Test
public void testAddRowLabelToPivotTable() {
int columnIndex = 0;
@@ -141,6 +158,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that it's not possible to create a row label outside of the referenced area.
*/
+ @Test
public void testAddRowLabelOutOfRangeThrowsException() {
int columnIndex = 5;
@@ -155,6 +173,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that when creating one column label, no col fields are being created.
*/
+ @Test
public void testAddOneColumnLabelToPivotTableDoesNotCreateColField() {
int columnIndex = 0;
@@ -167,6 +186,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that it's possible to create three column labels with different DataConsolidateFunction
*/
+ @Test
public void testAddThreeDifferentColumnLabelsToPivotTable() {
int columnOne = 0;
int columnTwo = 1;
@@ -184,6 +204,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that it's possible to create three column labels with the same DataConsolidateFunction
*/
+ @Test
public void testAddThreeSametColumnLabelsToPivotTable() {
int columnOne = 0;
int columnTwo = 1;
@@ -200,6 +221,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that when creating two column labels, a col field is being created and X is set to -2.
*/
+ @Test
public void testAddTwoColumnLabelsToPivotTable() {
int columnOne = 0;
int columnTwo = 1;
@@ -214,6 +236,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that a data field is created when creating a data column
*/
+ @Test
public void testColumnLabelCreatesDataField() {
int columnIndex = 0;
@@ -229,6 +252,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that it's possible to set a custom name when creating a data column
*/
+ @Test
public void testColumnLabelSetCustomName() {
int columnIndex = 0;
@@ -245,6 +269,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that it's not possible to create a column label outside of the referenced area.
*/
+ @Test
public void testAddColumnLabelOutOfRangeThrowsException() {
int columnIndex = 5;
@@ -260,6 +285,7 @@ public class TestXSSFPivotTable extends TestCase {
* Verify when creating a data column set to a data field, the data field with the corresponding
* column index will be set to true.
*/
+ @Test
public void testAddDataColumn() {
int columnIndex = 0;
boolean isDataField = true;
@@ -272,6 +298,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that it's not possible to create a data column outside of the referenced area.
*/
+ @Test
public void testAddDataColumnOutOfRangeThrowsException() {
int columnIndex = 5;
boolean isDataField = true;
@@ -301,6 +328,7 @@ public class TestXSSFPivotTable extends TestCase {
/**
* Verify that it's not possible to create a new filter outside of the referenced area.
*/
+ @Test
public void testAddReportFilterOutOfRangeThrowsException() {
int columnIndex = 5;
try {
@@ -315,10 +343,28 @@ public class TestXSSFPivotTable extends TestCase {
* Verify that the Pivot Table operates only within the referenced area, even when the
* first column of the referenced area is not index 0.
*/
+ @Test
public void testAddDataColumnWithOffsetData() {
offsetPivotTable.addColumnLabel(DataConsolidateFunction.SUM, 1);
assertEquals(CellType.NUMERIC, offsetOuterCell.getCellTypeEnum());
offsetPivotTable.addColumnLabel(DataConsolidateFunction.SUM, 0);
}
+
+ @Test
+ public void testPivotTableSheetNamesAreCaseInsensitive() {
+ wb.setSheetName(0, "original");
+ wb.setSheetName(1, "offset");
+ XSSFSheet original = wb.getSheet("OriginaL");
+ XSSFSheet offset = wb.getSheet("OffseT");
+ // assume sheets are accessible via case-insensitive name
+ assertNotNull(original);
+ assertNotNull(offset);
+
+ AreaReference source = new AreaReference("ORIGinal!A1:C2", _testDataProvider.getSpreadsheetVersion());
+ // create a pivot table on the same sheet, case insensitive
+ original.createPivotTable(source, new CellReference("W1"));
+ // create a pivot table on a different sheet, case insensitive
+ offset.createPivotTable(source, new CellReference("W1"));
+ }
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
index 689e999bcb..3f7be066d1 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
@@ -47,6 +47,9 @@ import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellCopyPolicy;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.ClientAnchor;
+import org.apache.poi.ss.usermodel.Comment;
+import org.apache.poi.ss.usermodel.CreationHelper;
+import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.FormulaError;
import org.apache.poi.ss.usermodel.IgnoredErrorType;
import org.apache.poi.ss.usermodel.IndexedColors;
@@ -1975,4 +1978,46 @@ public final class TestXSSFSheet extends BaseTestXSheet {
wb.close();
}
}
+
+ /**
+ * See bug #52425
+ */
+ @Test
+ public void testInsertCommentsToClonedSheet() {
+ Workbook wb = XSSFTestDataSamples.openSampleWorkbook("52425.xlsx");
+ CreationHelper helper = wb.getCreationHelper();
+ Sheet sheet2 = wb.createSheet("Sheet 2");
+ Sheet sheet3 = wb.cloneSheet(0);
+ wb.setSheetName(2, "Sheet 3");
+
+ // Adding Comment to new created Sheet 2
+ addComments(helper, sheet2);
+ // Adding Comment to cloned Sheet 3
+ addComments(helper, sheet3);
+ }
+
+ private void addComments(CreationHelper helper, Sheet sheet) {
+ Drawing drawing = sheet.createDrawingPatriarch();
+
+ for (int i = 0; i < 2; i++) {
+ ClientAnchor anchor = helper.createClientAnchor();
+ anchor.setCol1(0);
+ anchor.setRow1(0 + i);
+ anchor.setCol2(2);
+ anchor.setRow2(3 + i);
+
+ Comment comment = drawing.createCellComment(anchor);
+ comment.setString(helper.createRichTextString("BugTesting"));
+
+ Row row = sheet.getRow(0 + i);
+ if (row == null)
+ row = sheet.createRow(0 + i);
+ Cell cell = row.getCell(0);
+ if (cell == null)
+ cell = row.createCell(0);
+
+ cell.setCellComment(comment);
+ }
+
+ }
}
diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java
index 0287353234..3e2cd54030 100644
--- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java
+++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheetShiftRows.java
@@ -51,6 +51,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
// TODO - support shifting of page breaks
}
+ /** Error occurred at FormulaShifter#rowMoveAreaPtg while shift rows upward. */
@Test
public void testBug54524() throws IOException {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("54524.xlsx");
@@ -66,6 +67,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
workbook.close();
}
+ /** negative row shift causes corrupted data or throws exception */
@Test
public void testBug53798() throws IOException {
// NOTE that for HSSF (.xls) negative shifts combined with positive ones do work as expected
@@ -124,6 +126,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
}
}
+ /** negative row shift causes corrupted data or throws exception */
@Test
public void testBug53798a() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("53798.xlsx");
@@ -152,6 +155,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
read.close();
}
+ /** Shifting rows with comment result - Unreadable content error and comment deletion */
@Test
public void testBug56017() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("56017.xlsx");
@@ -193,6 +197,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
wbBack.close();
}
+ /** Moving the active sheet and deleting the others results in a corrupted file */
@Test
public void test57171() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
@@ -210,6 +215,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
wbRead.close();
}
+ /** Cannot delete an arbitrary sheet in an XLS workbook (only the last one) */
@Test
public void test57163() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
@@ -314,6 +320,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
wb.close();
}
+ /** Failed to clone a sheet from an Excel 2010 */
@Test
public void test57165() throws IOException {
Workbook wb = XSSFTestDataSamples.openSampleWorkbook("57171_57163_57165.xlsx");
@@ -341,6 +348,7 @@ public final class TestXSSFSheetShiftRows extends BaseTestSheetShiftRows {
}
}
+ /** Shifting rows with cell comments only shifts comments from first such cell. Other cell comments not shifted */
@Test
public void testBug57828_OnlyOneCommentShiftedInRow() throws IOException {
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("57828.xlsx");
diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
index ad0e5aa9a3..a17c61143b 100644
--- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
+++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShow.java
@@ -804,6 +804,7 @@ public final class HSLFSlideShow implements SlideShow CellType.*
+ cell.setCellValue(5.0);
+ assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
+ assertEquals(0, cell.getCellType()); //make sure that hard-coded int literals still work, even though users should be using the named constants
+ assertEquals(CellType.NUMERIC, cell.getCellTypeEnum()); // make sure old way and new way are compatible
+
+ // make sure switch(int|Enum) still works. Cases must be statically resolvable in Java 6 ("constant expression required")
+ switch(cell.getCellType()) {
+ case Cell.CELL_TYPE_NUMERIC:
+ // expected
+ break;
+ case Cell.CELL_TYPE_STRING:
+ case Cell.CELL_TYPE_BOOLEAN:
+ case Cell.CELL_TYPE_ERROR:
+ case Cell.CELL_TYPE_FORMULA:
+ case Cell.CELL_TYPE_BLANK:
+ default:
+ fail("unexpected cell type: " + cell.getCellType());
+ }
+ }
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
index 5509cbf71a..28cfb2cf7b 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestConditionalFormatting.java
@@ -363,10 +363,10 @@ public abstract class BaseTestConditionalFormatting {
BorderFormatting r1bf = rule1.getBorderFormatting();
assertNotNull(r1bf);
- assertEquals(BorderStyle.THIN, r1bf.getBorderBottom());
- assertEquals(BorderStyle.THICK,r1bf.getBorderTop());
- assertEquals(BorderStyle.DASHED,r1bf.getBorderLeft());
- assertEquals(BorderStyle.DOTTED,r1bf.getBorderRight());
+ assertEquals(BorderStyle.THIN, r1bf.getBorderBottomEnum());
+ assertEquals(BorderStyle.THICK,r1bf.getBorderTopEnum());
+ assertEquals(BorderStyle.DASHED,r1bf.getBorderLeftEnum());
+ assertEquals(BorderStyle.DOTTED,r1bf.getBorderRightEnum());
PatternFormatting r1pf = rule1.getPatternFormatting();
assertNotNull(r1pf);
@@ -1021,19 +1021,19 @@ public abstract class BaseTestConditionalFormatting {
for (BorderStyle border : BorderStyle.values()) {
borderFmt.setBorderTop(border);
- assertEquals(border, borderFmt.getBorderTop());
+ assertEquals(border, borderFmt.getBorderTopEnum());
borderFmt.setBorderBottom(border);
- assertEquals(border, borderFmt.getBorderBottom());
+ assertEquals(border, borderFmt.getBorderBottomEnum());
borderFmt.setBorderLeft(border);
- assertEquals(border, borderFmt.getBorderLeft());
+ assertEquals(border, borderFmt.getBorderLeftEnum());
borderFmt.setBorderRight(border);
- assertEquals(border, borderFmt.getBorderRight());
+ assertEquals(border, borderFmt.getBorderRightEnum());
borderFmt.setBorderDiagonal(border);
- assertEquals(border, borderFmt.getBorderDiagonal());
+ assertEquals(border, borderFmt.getBorderDiagonalEnum());
}
workbook.close();
@@ -1049,37 +1049,37 @@ public abstract class BaseTestConditionalFormatting {
ConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(ComparisonOperator.EQUAL, "7");
BorderFormatting borderFmt = rule1.createBorderFormatting();
- assertEquals(BorderStyle.NONE, borderFmt.getBorderBottom());
+ assertEquals(BorderStyle.NONE, borderFmt.getBorderBottomEnum());
borderFmt.setBorderBottom(BorderStyle.DOTTED);
- assertEquals(BorderStyle.DOTTED, borderFmt.getBorderBottom());
+ assertEquals(BorderStyle.DOTTED, borderFmt.getBorderBottomEnum());
borderFmt.setBorderBottom(BorderStyle.NONE);
- assertEquals(BorderStyle.NONE, borderFmt.getBorderBottom());
+ assertEquals(BorderStyle.NONE, borderFmt.getBorderBottomEnum());
borderFmt.setBorderBottom(BorderStyle.THICK);
- assertEquals(BorderStyle.THICK, borderFmt.getBorderBottom());
+ assertEquals(BorderStyle.THICK, borderFmt.getBorderBottomEnum());
- assertEquals(BorderStyle.NONE, borderFmt.getBorderTop());
+ assertEquals(BorderStyle.NONE, borderFmt.getBorderTopEnum());
borderFmt.setBorderTop(BorderStyle.DOTTED);
- assertEquals(BorderStyle.DOTTED, borderFmt.getBorderTop());
+ assertEquals(BorderStyle.DOTTED, borderFmt.getBorderTopEnum());
borderFmt.setBorderTop(BorderStyle.NONE);
- assertEquals(BorderStyle.NONE, borderFmt.getBorderTop());
+ assertEquals(BorderStyle.NONE, borderFmt.getBorderTopEnum());
borderFmt.setBorderTop(BorderStyle.THICK);
- assertEquals(BorderStyle.THICK, borderFmt.getBorderTop());
+ assertEquals(BorderStyle.THICK, borderFmt.getBorderTopEnum());
- assertEquals(BorderStyle.NONE, borderFmt.getBorderLeft());
+ assertEquals(BorderStyle.NONE, borderFmt.getBorderLeftEnum());
borderFmt.setBorderLeft(BorderStyle.DOTTED);
- assertEquals(BorderStyle.DOTTED, borderFmt.getBorderLeft());
+ assertEquals(BorderStyle.DOTTED, borderFmt.getBorderLeftEnum());
borderFmt.setBorderLeft(BorderStyle.NONE);
- assertEquals(BorderStyle.NONE, borderFmt.getBorderLeft());
+ assertEquals(BorderStyle.NONE, borderFmt.getBorderLeftEnum());
borderFmt.setBorderLeft(BorderStyle.THIN);
- assertEquals(BorderStyle.THIN, borderFmt.getBorderLeft());
+ assertEquals(BorderStyle.THIN, borderFmt.getBorderLeftEnum());
- assertEquals(BorderStyle.NONE, borderFmt.getBorderRight());
+ assertEquals(BorderStyle.NONE, borderFmt.getBorderRightEnum());
borderFmt.setBorderRight(BorderStyle.DOTTED);
- assertEquals(BorderStyle.DOTTED, borderFmt.getBorderRight());
+ assertEquals(BorderStyle.DOTTED, borderFmt.getBorderRightEnum());
borderFmt.setBorderRight(BorderStyle.NONE);
- assertEquals(BorderStyle.NONE, borderFmt.getBorderRight());
+ assertEquals(BorderStyle.NONE, borderFmt.getBorderRightEnum());
borderFmt.setBorderRight(BorderStyle.HAIR);
- assertEquals(BorderStyle.HAIR, borderFmt.getBorderRight());
+ assertEquals(BorderStyle.HAIR, borderFmt.getBorderRightEnum());
ConditionalFormattingRule [] cfRules = { rule1 };
@@ -1095,10 +1095,10 @@ public abstract class BaseTestConditionalFormatting {
BorderFormatting r1fp = cf.getRule(0).getBorderFormatting();
assertNotNull(r1fp);
- assertEquals(BorderStyle.THICK, r1fp.getBorderBottom());
- assertEquals(BorderStyle.THICK, r1fp.getBorderTop());
- assertEquals(BorderStyle.THIN, r1fp.getBorderLeft());
- assertEquals(BorderStyle.HAIR, r1fp.getBorderRight());
+ assertEquals(BorderStyle.THICK, r1fp.getBorderBottomEnum());
+ assertEquals(BorderStyle.THICK, r1fp.getBorderTopEnum());
+ assertEquals(BorderStyle.THIN, r1fp.getBorderLeftEnum());
+ assertEquals(BorderStyle.HAIR, r1fp.getBorderRightEnum());
workbook.close();
}
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java
index 8a16d3a644..c4922a7c84 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestFormulaEvaluator.java
@@ -19,6 +19,7 @@ package org.apache.poi.ss.usermodel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import java.io.IOException;
@@ -326,4 +327,15 @@ public abstract class BaseTestFormulaEvaluator {
wb.close();
}
+
+ @Test
+ public void evaluateInCellReturnsSameCell() throws IOException {
+ Workbook wb = _testDataProvider.createWorkbook();
+ wb.createSheet().createRow(0).createCell(0);
+ FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
+ Cell cell = wb.getSheetAt(0).getRow(0).getCell(0);
+ Cell same = evaluator.evaluateInCell(cell);
+ assertSame(cell, same);
+ wb.close();
+ }
}
\ No newline at end of file
diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
index 6290119f51..52f542281a 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
@@ -34,6 +34,7 @@ import java.util.Iterator;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.util.NullOutputStream;
import org.junit.Test;
public abstract class BaseTestWorkbook {
@@ -781,15 +782,6 @@ public abstract class BaseTestWorkbook {
}
}
- protected static class NullOutputStream extends OutputStream {
- public NullOutputStream() {
- }
-
- @Override
- public void write(int b) throws IOException {
- }
- }
-
@Test
public void test58499() throws IOException {
Workbook workbook = _testDataProvider.createWorkbook();
diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
index 649bddf9b4..50276ae281 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
@@ -597,6 +597,27 @@ public class TestDataFormatter {
}
}
+ @Test
+ public void testBoolean() throws IOException {
+ DataFormatter formatter = new DataFormatter();
+
+ // Create a spreadsheet with some TRUE/FALSE boolean values in it
+ Workbook wb = new HSSFWorkbook();
+ try {
+ Sheet s = wb.createSheet();
+ Row r = s.createRow(0);
+ Cell c = r.createCell(0);
+
+ c.setCellValue(true);
+ assertEquals("TRUE", formatter.formatCellValue(c));
+
+ c.setCellValue(false);
+ assertEquals("FALSE", formatter.formatCellValue(c));
+ } finally {
+ wb.close();
+ }
+ }
+
/**
* While we don't currently support using a locale code at
* the start of a format string to format it differently, we
diff --git a/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java b/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java
index a63ce5a605..91c204da32 100644
--- a/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java
+++ b/src/testcases/org/apache/poi/ss/util/BaseTestCellUtil.java
@@ -99,11 +99,11 @@ public class BaseTestCellUtil {
// A valid BorderStyle constant, as a Short
CellUtil.setCellStyleProperty(c, CellUtil.BORDER_BOTTOM, BorderStyle.DASH_DOT.getCode());
- assertEquals(BorderStyle.DASH_DOT, c.getCellStyle().getBorderBottom());
+ assertEquals(BorderStyle.DASH_DOT, c.getCellStyle().getBorderBottomEnum());
// A valid BorderStyle constant, as an Enum
CellUtil.setCellStyleProperty(c, CellUtil.BORDER_TOP, BorderStyle.MEDIUM_DASH_DOT);
- assertEquals(BorderStyle.MEDIUM_DASH_DOT, c.getCellStyle().getBorderTop());
+ assertEquals(BorderStyle.MEDIUM_DASH_DOT, c.getCellStyle().getBorderTopEnum());
wb.close();
}
diff --git a/src/testcases/org/apache/poi/util/NullOutputStream.java b/src/testcases/org/apache/poi/util/NullOutputStream.java
new file mode 100644
index 0000000000..ac76123a3c
--- /dev/null
+++ b/src/testcases/org/apache/poi/util/NullOutputStream.java
@@ -0,0 +1,41 @@
+/* ====================================================================
+ 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.util;
+
+import java.io.OutputStream;
+
+/**
+ * Implementation of an OutputStream which does nothing, used
+ * to redirect stdout to avoid spamming the console with output
+ */
+public final class NullOutputStream extends OutputStream {
+ public NullOutputStream() {
+ }
+
+ @Override
+ public void write(byte[] b, int off, int len) {
+ }
+
+ @Override
+ public void write(int b) {
+ }
+
+ @Override
+ public void write(byte[] b) {
+ }
+}
diff --git a/test-data/openxml4j/invalid.xlsx b/test-data/openxml4j/invalid.xlsx
new file mode 100644
index 0000000000..15cb0ecb3e
Binary files /dev/null and b/test-data/openxml4j/invalid.xlsx differ
diff --git a/test-data/slideshow/60003.ppt b/test-data/slideshow/60003.ppt
new file mode 100644
index 0000000000..1a4cd2f48a
Binary files /dev/null and b/test-data/slideshow/60003.ppt differ
diff --git a/test-data/spreadsheet/52425.xlsx b/test-data/spreadsheet/52425.xlsx
new file mode 100644
index 0000000000..0659822f64
Binary files /dev/null and b/test-data/spreadsheet/52425.xlsx differ
diff --git a/test-data/spreadsheet/DGet.xls b/test-data/spreadsheet/DGet.xls
index 5d254febeb..729e974e4d 100644
Binary files a/test-data/spreadsheet/DGet.xls and b/test-data/spreadsheet/DGet.xls differ