merge trunk to branch

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/hssf_cryptoapi@1761376 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2016-09-19 00:20:44 +00:00
parent fdddabe430
commit 2e50133e88
139 changed files with 1760 additions and 801 deletions

55
KEYS
View File

@ -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 <kiwiwings@apache.org>
uid Andreas Beeker (kiwiwings) <andreas.beeker@gmx.de>
sub 2048R/EE864ED6 2014-08-17 [expires: 2016-08-16]
pub rsa2048/26062CE3 2014-08-17 [expires: 2018-08-21]
uid [ultimate] Andreas Beeker <kiwiwings@apache.org>
uid [ultimate] Andreas Beeker (kiwiwings) <andreas.beeker@gmx.de>
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]

View File

@ -40,7 +40,7 @@ under the License.
<description>The Apache POI project Ant build.</description>
<property name="version.id" value="3.15-beta4"/>
<property name="version.id" value="3.16-beta1"/>
<property name="release.rc" value="RC1"/>
<property environment="env"/>
@ -1092,7 +1092,7 @@ under the License.
</copy>
</target>
<target name="compile-integration" depends="compile-scratchpad, compile-main, compile-ooxml">
<target name="compile-integration" depends="compile-scratchpad, compile-main, compile-ooxml, compile-examples">
<javac target="${jdk.version.class}"
source="${jdk.version.source}"
destdir="${integration.output.test.dir}"
@ -2390,17 +2390,19 @@ under the License.
<!-- can't combine updating and pinning of the documentation ... so we need two commits -->
<!-- (revision)properties can't be set and read within one svn block -->
<echo message="updating build.xml and status.xml"/>
<exec command="svn ci --username ${settings.apache-id.username} --password ${settings.apache-id.password} -m 'release prepare for ${version.id} - updating build.xml and status.xml' build.xml src/documentation/content/xdocs/status.xml"/>
<svn refid="svn.settings">
<commit message="release prepare for ${version.id} - updating build.xml and status.xml" recurse="false">
<!--<commit message="release prepare for ${version.id} - updating build.xml and status.xml" recurse="false">
<fileset dir="." includes="build.xml,src/documentation/content/xdocs/status.xml"/>
</commit>
</commit>-->
<update dir="." recurse="true"/>
<status path="." revisionProperty="svn_version1"/>
</svn>
<echo message="pin documentation - release ${svn_version1}"/>
<exec command="svn ci --username ${settings.apache-id.username} --password ${settings.apache-id.password} -m 'release prepare for ${version.id} - pin documentation' src"/>
<svn refid="svn.settings">
<propset path="src" name="svn:externals" value="documentation -r${svn_version1} https://svn.apache.org/repos/asf/poi/site/src/documentation"/>
<commit message="release prepare for ${version.id} - pin documentation" dir="src" recurse="false"/>
<!-- <commit message="release prepare for ${version.id} - pin documentation" dir="src" recurse="false"/>-->
<update dir="." recurse="true"/>
<status path="." revisionProperty="svn_version2"/>
</svn>
@ -2430,12 +2432,13 @@ under the License.
<svn refid="svn.settings">
<update dir="." recurse="true"/>
<propset path="src" name="svn:externals" value="documentation https://svn.apache.org/repos/asf/poi/site/src/documentation"/>
<commit message="prepare for ${rel_next}" recurse="false">
<!--<commit message="prepare for ${rel_next}" recurse="false">
<fileset dir="." includes="build.xml"/>
<fileset dir="sonar" includes="**/pom.xml"/>
<dirset dir="src"/>
</commit>
</commit>-->
</svn>
<exec command="svn ci --username ${settings.apache-id.username} --password ${settings.apache-id.password} -m 'prepare for ${rel_next}' build.xml sonar src"/>
<mkdir dir="build/release"/>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId>
<version>3.15-beta4-SNAPSHOT</version>
<version>3.16-beta1-SNAPSHOT</version>
</parent>
<artifactId>poi-examples</artifactId>
<packaging>jar</packaging>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId>
<version>3.15-beta4-SNAPSHOT</version>
<version>3.16-beta1-SNAPSHOT</version>
</parent>
<artifactId>poi-excelant</artifactId>
<packaging>jar</packaging>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId>
<version>3.15-beta4-SNAPSHOT</version>
<version>3.16-beta1-SNAPSHOT</version>
</parent>
<artifactId>poi-main</artifactId>
<packaging>jar</packaging>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId>
<version>3.15-beta4-SNAPSHOT</version>
<version>3.16-beta1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>poi-ooxml-schema-encryption</artifactId>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId>
<version>3.15-beta4-SNAPSHOT</version>
<version>3.16-beta1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>poi-ooxml-schema-security</artifactId>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId>
<version>3.15-beta4-SNAPSHOT</version>
<version>3.16-beta1-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>poi-ooxml-schema</artifactId>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId>
<version>3.15-beta4-SNAPSHOT</version>
<version>3.16-beta1-SNAPSHOT</version>
</parent>
<artifactId>poi-ooxml</artifactId>
<packaging>jar</packaging>

View File

@ -3,7 +3,7 @@
<groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId>
<packaging>pom</packaging>
<version>3.15-beta4-SNAPSHOT</version>
<version>3.16-beta1-SNAPSHOT</version>
<name>Apache POI - the Java API for Microsoft Documents</name>
<description>Maven build of Apache POI for Sonar checks</description>
<url>http://poi.apache.org/</url>

View File

@ -6,7 +6,7 @@
<parent>
<groupId>org.apache.poi</groupId>
<artifactId>poi-parent</artifactId>
<version>3.15-beta4-SNAPSHOT</version>
<version>3.16-beta1-SNAPSHOT</version>
</parent>
<artifactId>poi-scratchpad</artifactId>
<packaging>jar</packaging>

View File

@ -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;

View File

@ -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;
}

View File

@ -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) {

View File

@ -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);

View File

@ -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);

View File

@ -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<Object[]> files = new ArrayList<Object[]>();
for(String file : scanner.getIncludedFiles()) {
file = file.replace('\\', '/'); // ... failures/handlers lookup doesn't work on windows otherwise
if (IGNORED.contains(file)) continue;
if (IGNORED.contains(file)) {
System.out.println("Ignoring " + file);
continue;
}
FileHandler handler = HANDLERS.get(getExtension(file));
files.add(new Object[] { file, handler });

View File

@ -30,6 +30,7 @@ import javax.xml.transform.TransformerException;
import org.apache.poi.POIXMLException;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.exceptions.NotOfficeXmlFileException;
import org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException;
import org.apache.poi.openxml4j.exceptions.OpenXML4JException;
import org.apache.poi.openxml4j.opc.OPCPackage;
@ -134,6 +135,9 @@ public class XSSFFileHandler extends SpreadsheetHandler {
EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/Simple.xlsb");
// TODO: good to ignore?
EXPECTED_ADDITIONAL_FAILURES.add("spreadsheet/sample-beta.xlsx");
// corrupt/invalid
EXPECTED_ADDITIONAL_FAILURES.add("openxml4j/invalid.xlsx");
}
@SuppressWarnings("resource")

View File

@ -16,6 +16,8 @@
==================================================================== */
package org.apache.poi.common.usermodel;
import org.apache.poi.util.Removal;
/**
* Represents a hyperlink.
*/
@ -25,6 +27,7 @@ public interface Hyperlink {
*
* @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#URL} instead.
*/
@Removal(version="3.17")
public static final int LINK_URL = 1; // HyperlinkType.URL.getCode()
/**
@ -32,6 +35,7 @@ public interface Hyperlink {
*
* @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#DOCUMENT} instead.
*/
@Removal(version="3.17")
public static final int LINK_DOCUMENT = 2; // HyperlinkType.DOCUMENT.getCode()
/**
@ -39,6 +43,7 @@ public interface Hyperlink {
*
* @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#EMAIL} instead.
*/
@Removal(version="3.17")
public static final int LINK_EMAIL = 3; // HyperlinkType.EMAIL.getCode()
/**
@ -46,6 +51,7 @@ public interface Hyperlink {
*
* @deprecated POI 3.15 beta 3. Use {@link HyperlinkType#FILE} instead.
*/
@Removal(version="3.17")
public static final int LINK_FILE = 4; // HyperlinkType.FILE.getCode()
@ -83,6 +89,7 @@ public interface Hyperlink {
* @return the type of this hyperlink
* @see HyperlinkType#forInt(int)
* @deprecated POI 3.15 beta 3. Use {@link #getTypeEnum()}
* getType will return a HyperlinkType enum in the future.
*/
public int getType();

View File

@ -17,8 +17,6 @@
package org.apache.poi.hssf.model;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.util.Internal;
import org.apache.poi.hssf.usermodel.HSSFEvaluationWorkbook;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.formula.FormulaParseException;
@ -26,6 +24,9 @@ import org.apache.poi.ss.formula.FormulaParser;
import org.apache.poi.ss.formula.FormulaParsingWorkbook;
import org.apache.poi.ss.formula.FormulaRenderer;
import org.apache.poi.ss.formula.FormulaType;
import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
/**
* HSSF wrapper for the {@link FormulaParser} and {@link FormulaRenderer}
@ -61,6 +62,7 @@ public final class HSSFFormulaParser {
*
* @deprecated POI 3.15 beta 3. Use {@link #parse(String, HSSFWorkbook, FormulaType)} instead.
*/
@Removal(version="3.17")
public static Ptg[] parse(String formula, HSSFWorkbook workbook, int formulaType) throws FormulaParseException {
return parse(formula, workbook, FormulaType.forInt(formulaType));
}
@ -87,6 +89,7 @@ public final class HSSFFormulaParser {
* @throws FormulaParseException if the formula has incorrect syntax or is otherwise invalid
* @deprecated POI 3.15 beta 3. Use {@link #parse(String, HSSFWorkbook, FormulaType, int)} instead.
*/
@Removal(version="3.17")
public static Ptg[] parse(String formula, HSSFWorkbook workbook, int formulaType, int sheetIndex) throws FormulaParseException {
return parse(formula, workbook, FormulaType.forInt(formulaType), sheetIndex);
}

View File

@ -42,28 +42,83 @@ public final class HSSFBorderFormatting implements org.apache.poi.ss.usermodel.B
return borderFormatting;
}
/**
* @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 (short)borderFormatting.getBorderBottom();
}
/**
* @since POI 3.15
*/
@Override
public BorderStyle getBorderBottomEnum() {
return BorderStyle.valueOf((short)borderFormatting.getBorderBottom());
}
/**
* @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 (short)borderFormatting.getBorderDiagonal();
}
/**
* @since POI 3.15
*/
@Override
public BorderStyle getBorderDiagonalEnum() {
return BorderStyle.valueOf((short)borderFormatting.getBorderDiagonal());
}
/**
* @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 (short)borderFormatting.getBorderLeft();
}
/**
* @since POI 3.15
*/
@Override
public BorderStyle getBorderLeftEnum() {
return BorderStyle.valueOf((short)borderFormatting.getBorderLeft());
}
/**
* @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 (short)borderFormatting.getBorderRight();
}
/**
* @since POI 3.15
*/
@Override
public BorderStyle getBorderRightEnum() {
return BorderStyle.valueOf((short)borderFormatting.getBorderRight());
}
/**
* @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 (short)borderFormatting.getBorderTop();
}
/**
* @since POI 3.15
*/
@Override
public BorderStyle getBorderTopEnum() {
return BorderStyle.valueOf((short)borderFormatting.getBorderTop());
}

View File

@ -446,6 +446,7 @@ public class HSSFCell implements Cell {
*
* Will return {@link CellType} in a future version of POI.
* For forwards compatibility, do not hard-code cell type literals in your code.
* @deprecated 3.15. Will be return a {@link CellType} enum in the future.
*/
@Override
public int getCellType()
@ -459,7 +460,6 @@ public class HSSFCell 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 getCellTypeEnum()
{
@ -1154,6 +1154,7 @@ public class HSSFCell 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() {
@ -1169,7 +1170,6 @@ public class HSSFCell 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 (_cellType != CellType.FORMULA) {

View File

@ -32,6 +32,7 @@ import org.apache.poi.ss.usermodel.FillPatternType;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.util.Removal;
/**
* High level representation of the style of a cell in a sheet of a workbook.
@ -254,6 +255,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #ALIGN_CENTER_SELECTION
* @deprecated POI 3.15 beta 3. Use {@link #setAlignment(HorizontalAlignment)} instead.
*/
@Removal(version="3.17")
@Override
public void setAlignment(short align)
{
@ -329,6 +331,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see VerticalAlignment
* @deprecated POI 3.15 beta 3. Use {@link #setVerticalAlignment(VerticalAlignment)} instead.
*/
@Removal(version="3.17")
@Override
public void setVerticalAlignment(short align)
{
@ -459,6 +462,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderLeft(BorderStyle)} instead.
*/
@Removal(version="3.17")
@Override
public void setBorderLeft(short border)
{
@ -469,6 +473,7 @@ public final class HSSFCellStyle implements CellStyle {
/**
* set the type of border to use for the left border of the cell
* @param border type
* @since POI 3.15
*/
@Override
public void setBorderLeft(BorderStyle border)
@ -479,9 +484,20 @@ public final class HSSFCellStyle implements CellStyle {
/**
* get the type of border to use for the left border of the cell
* @return border type
* @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderLeftEnum()}.
*/
@Override
public BorderStyle getBorderLeft()
public short getBorderLeft()
{
return _format.getBorderLeft();
}
/**
* get the type of border to use for the left border of the cell
* @return border type
* @since POI 3.15
*/
@Override
public BorderStyle getBorderLeftEnum()
{
return BorderStyle.valueOf(_format.getBorderLeft());
}
@ -505,6 +521,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderRight(BorderStyle)} instead.
*/
@Removal(version="3.17")
@Override
public void setBorderRight(short border)
{
@ -515,6 +532,7 @@ public final class HSSFCellStyle implements CellStyle {
/**
* set the type of border to use for the right border of the cell
* @param border type
* @since POI 3.15
*/
@Override
public void setBorderRight(BorderStyle border)
@ -525,9 +543,20 @@ public final class HSSFCellStyle implements CellStyle {
/**
* get the type of border to use for the right border of the cell
* @return border type
* @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderRightEnum()}.
*/
@Override
public BorderStyle getBorderRight()
public short getBorderRight()
{
return _format.getBorderRight();
}
/**
* get the type of border to use for the right border of the cell
* @return border type
* @since POI 3.15
*/
@Override
public BorderStyle getBorderRightEnum()
{
return BorderStyle.valueOf(_format.getBorderRight());
}
@ -551,6 +580,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderTop(BorderStyle)} instead.
*/
@Removal(version="3.17")
@Override
public void setBorderTop(short border)
{
@ -561,6 +591,7 @@ public final class HSSFCellStyle implements CellStyle {
/**
* set the type of border to use for the top border of the cell
* @param border type
* @since POI 3.15
*/
@Override
public void setBorderTop(BorderStyle border)
@ -571,9 +602,20 @@ public final class HSSFCellStyle implements CellStyle {
/**
* get the type of border to use for the top border of the cell
* @return border type
* @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderTopEnum()}.
*/
@Override
public BorderStyle getBorderTop()
public short getBorderTop()
{
return _format.getBorderTop();
}
/**
* get the type of border to use for the top border of the cell
* @return border type
* @since 3.15
*/
@Override
public BorderStyle getBorderTopEnum()
{
return BorderStyle.valueOf(_format.getBorderTop());
}
@ -597,6 +639,7 @@ public final class HSSFCellStyle implements CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link HSSFCellStyle#setBorderBottom(BorderStyle)} instead.
*/
@Removal(version="3.17")
@Override
public void setBorderBottom(short border)
{
@ -607,6 +650,7 @@ public final class HSSFCellStyle implements CellStyle {
/**
* set the type of border to use for the bottom border of the cell
* @param border type
* @since 3.15 beta 2
*/
@Override
public void setBorderBottom(BorderStyle border)
@ -617,9 +661,20 @@ public final class HSSFCellStyle implements CellStyle {
/**
* get the type of border to use for the bottom border of the cell
* @return border type
* @deprecated POI 3.15. Will return a BorderStyle enum in the future. Use {@link #getBorderBottomEnum()}.
*/
@Override
public BorderStyle getBorderBottom()
public short getBorderBottom()
{
return _format.getBorderBottom();
}
/**
* get the type of border to use for the bottom border of the cell
* @return border type
* @since 3.15
*/
@Override
public BorderStyle getBorderBottomEnum()
{
return BorderStyle.valueOf(_format.getBorderBottom());
}
@ -733,6 +788,7 @@ public final class HSSFCellStyle implements CellStyle {
* @param fp fill pattern (set to 1 to fill w/foreground color)
* @deprecated POI 3.15 beta 3. Use {@link #setFillPattern(FillPatternType)} instead.
*/
@Removal(version="3.17")
@Override
public void setFillPattern(short fp)
{

View File

@ -21,6 +21,7 @@ import org.apache.poi.ddf.EscherClientAnchorRecord;
import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.ss.SpreadsheetVersion;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.util.Removal;
/**
* A client anchor is attached to an excel worksheet. It anchors against a
@ -250,6 +251,7 @@ public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor {
/**
* Gets the anchor type
* Changed from returning an int to an enum in POI 3.14 beta 1.
* @return the anchor type
*/
@Override
@ -260,11 +262,22 @@ public final class HSSFClientAnchor extends HSSFAnchor implements ClientAnchor {
/**
* Sets the anchor type
* @param anchorType the anchor type to set
* @since POI 3.14
*/
@Override
public void setAnchorType(AnchorType anchorType) {
_escherClientAnchor.setFlag(anchorType.value);
}
/**
* 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) {
_escherClientAnchor.setFlag((short) anchorType);
}
private void checkRange(int value, int minRange, int maxRange, String varName) {
if (value < minRange || value > maxRange)

View File

@ -21,6 +21,7 @@ import org.apache.poi.common.usermodel.HyperlinkType;
import org.apache.poi.hssf.record.common.ExtendedColor;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
public class HSSFCreationHelper implements CreationHelper {
private final HSSFWorkbook workbook;
@ -50,6 +51,7 @@ public class HSSFCreationHelper implements CreationHelper {
* @deprecated POI 3.15 beta 3. Use {@link #createHyperlink(HyperlinkType)} instead.
*/
@Deprecated
@Removal(version="3.17")
@Override
public HSSFHyperlink createHyperlink(int type) {
return new HSSFHyperlink(type);

View File

@ -55,6 +55,7 @@ final class HSSFEvaluationCell 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() {
@ -65,7 +66,6 @@ final class HSSFEvaluationCell 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();
@ -99,6 +99,7 @@ final class HSSFEvaluationCell implements EvaluationCell {
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type of cached formula result
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override
public int getCachedFormulaResultType() {
@ -109,7 +110,6 @@ final class HSSFEvaluationCell 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 getCachedFormulaResultTypeEnum() {
return _cell.getCachedFormulaResultTypeEnum();

View File

@ -30,11 +30,10 @@ import org.apache.poi.ss.formula.eval.StringValueEval;
import org.apache.poi.ss.formula.eval.ValueEval;
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;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.util.Internal;
/**
* Evaluates formula cells.<p/>
@ -82,6 +81,11 @@ public class HSSFFormulaEvaluator extends BaseFormulaEvaluator {
return new HSSFFormulaEvaluator(workbook, stabilityClassifier, udfFinder);
}
@Override
protected RichTextString createRichTextString(String str) {
return new HSSFRichTextString(str);
}
/**
* Coordinates several formula evaluators together so that formulas that involve external
@ -137,86 +141,9 @@ public class HSSFFormulaEvaluator extends BaseFormulaEvaluator {
_bookEvaluator.notifyUpdateCell(new HSSFEvaluationCell((HSSFCell)cell));
}
/**
* If cell contains formula, it evaluates the formula, and saves the result of the formula. The
* cell remains as a formula cell. If the cell does not contain formula, rather than throwing an
* exception, this method returns {@link CellType#_NONE} and leaves the cell unchanged.
*
* Note that the type of the <em>formula result</em> is returned, so you know what kind of
* cached formula result is also stored with the formula.
* <pre>
* CellType evaluatedCellType = evaluator.evaluateFormulaCell(cell);
* </pre>
* 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 #evaluateInCell(org.apache.poi.ss.usermodel.Cell)}
* @param cell The cell to evaluate
* @return {@link CellType#_NONE} for non-formula cells, or the type of the <em>formula result</em>
* @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
@Override
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.
* Note that the same instance of HSSFCell is returned to
* allow chained calls like:
* <pre>
* int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
* </pre>
* 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(Cell)}}
*/
@Override
public HSSFCell evaluateInCell(Cell cell) {
if (cell == null) {
return null;
}
HSSFCell result = (HSSFCell) cell;
if (cell.getCellTypeEnum() == CellType.FORMULA) {
CellValue cv = evaluateFormulaCellValue(cell);
setCellValue(cell, cv);
setCellType(cell, cv); // cell will no longer be a formula cell
}
return result;
}
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 HSSFRichTextString(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 + ")");
}
return (HSSFCell) super.evaluateInCell(cell);
}
/**

View File

@ -273,6 +273,8 @@ public class HSSFHyperlink implements Hyperlink {
*
* @return the type of this hyperlink
* @see HyperlinkType#forInt
* @deprecated POI 3.15. Use {@link #getTypeEnum()} instead.
* getType will return a HyperlinkType enum in the future.
*/
@Override
public int getType() {

View File

@ -94,6 +94,8 @@ public class FileBackedDataSource extends DataSource {
if (writable) {
dst = channel.map(FileChannel.MapMode.READ_WRITE, position, length);
worked = 0;
// remember the buffer for cleanup if necessary
buffersToClean.add(dst);
} else {
// Read
channel.position(position);
@ -109,9 +111,6 @@ public class FileBackedDataSource extends DataSource {
// Ready it for reading
dst.position(0);
// remember the buffer for cleanup if necessary
buffersToClean.add(dst);
// All done
return dst;
}

View File

@ -83,6 +83,7 @@ public interface SlideShow<
* @param format The format of the picture.
*
* @return the picture data reference.
* @since 3.15 beta 1
*/
PictureData addPicture(InputStream is, PictureType format) throws IOException;
@ -93,6 +94,7 @@ public interface SlideShow<
* @param format The format of the picture.
*
* @return the picture data reference
* @since 3.15 beta 1
*/
PictureData addPicture(File pict, PictureType format) throws IOException;
@ -101,6 +103,7 @@ public interface 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 3
*/
PictureData findPictureData(byte[] pictureData);

View File

@ -35,7 +35,6 @@ import org.apache.poi.ss.usermodel.ConditionalFormattingRule;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.ss.util.DateFormatConverter;
import org.apache.poi.util.Internal;
/**
* Format a value according to the standard Excel behavior. This "standard" is
@ -44,28 +43,35 @@ import org.apache.poi.util.Internal;
* <p/>
* An Excel format has up to four parts, separated by semicolons. Each part
* specifies what to do with particular kinds of values, depending on the number
* of parts given: <dl> <dt>One part (example: <tt>[Green]#.##</tt>) <dd>If the
* value is a number, display according to this one part (example: green text,
* with up to two decimal points). If the value is text, display it as is.
* <dt>Two parts (example: <tt>[Green]#.##;[Red]#.##</tt>) <dd>If the value is a
* positive number or zero, display according to the first part (example: green
* of parts given:
* <dl>
* <dt>One part (example: <tt>[Green]#.##</tt>)</dt>
* <dd>If the value is a number, display according to this one part (example: green text,
* with up to two decimal points). If the value is text, display it as is.</dd>
*
* <dt>Two parts (example: <tt>[Green]#.##;[Red]#.##</tt>)</dt>
* <dd>If the value is a positive number or zero, display according to the first part (example: green
* text, with up to two decimal points); if it is a negative number, display
* according to the second part (example: red text, with up to two decimal
* points). If the value is text, display it as is. <dt>Three parts (example:
* <tt>[Green]#.##;[Black]#.##;[Red]#.##</tt>) <dd>If the value is a positive
* points). If the value is text, display it as is.</dd>
*
* <dt>Three parts (example: <tt>[Green]#.##;[Black]#.##;[Red]#.##</tt>)</dt>
* <dd>If the value is a positive
* number, display according to the first part (example: green text, with up to
* two decimal points); if it is zero, display according to the second part
* (example: black text, with up to two decimal points); if it is a negative
* number, display according to the third part (example: red text, with up to
* two decimal points). If the value is text, display it as is. <dt>Four parts
* (example: <tt>[Green]#.##;[Black]#.##;[Red]#.##;[@]</tt>) <dd>If the value is
* a positive number, display according to the first part (example: green text,
* two decimal points). If the value is text, display it as is.</dd>
*
* <dt>Four parts (example: <tt>[Green]#.##;[Black]#.##;[Red]#.##;[@]</tt>)</dt>
* <dd>If the value is a positive number, display according to the first part (example: green text,
* with up to two decimal points); if it is zero, display according to the
* second part (example: black text, with up to two decimal points); if it is a
* negative number, display according to the third part (example: red text, with
* up to two decimal points). If the value is text, display according to the
* fourth part (example: text in the cell's usual color, with the text value
* surround by brackets). </dl>
* surround by brackets).</dd>
* </dl>
* <p/>
* A given format part may specify a given Locale, by including something
* like <tt>[$$-409]</tt> or <tt>[$&pound;-809]</tt> or <tt>[$-40C]</tt>. These
@ -421,6 +427,7 @@ public class CellFormat {
* @param cell The cell.
*
* @return The ultimate type of this cell.
* @deprecated POI 3.15. This will return a CellType enum in the future
*/
public static int ultimateType(Cell cell) {
return ultimateTypeEnum(cell).getCode();
@ -439,7 +446,6 @@ public class CellFormat {
* @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 static CellType ultimateTypeEnum(Cell cell) {
CellType type = cell.getCellTypeEnum();
if (type == CellType.FORMULA)

View File

@ -23,6 +23,7 @@ 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.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
@ -109,6 +110,37 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook
}
}
/**
* 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 HSSFCell is returned to
* allow chained calls like:
* <pre>
* int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
* </pre>
* 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(Cell)}}
* @param cell
* @return the {@code cell} that was passed in, allowing for chained calls
*/
@Override
public Cell evaluateInCell(Cell cell) {
if (cell == null) {
return null;
}
Cell result = cell;
if (cell.getCellTypeEnum() == CellType.FORMULA) {
CellValue cv = evaluateFormulaCellValue(cell);
setCellValue(cell, cv);
setCellType(cell, cv); // cell will no longer be a formula cell
}
return result;
}
protected abstract CellValue evaluateFormulaCellValue(Cell cell);
/**
@ -125,14 +157,47 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook
* replaced with the result of the formula, use {@link #evaluateInCell(org.apache.poi.ss.usermodel.Cell)}
* @param cell The cell to evaluate
* @return -1 for non-formula cells, or the type of the <em>formula result</em>
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override
public int evaluateFormulaCell(Cell cell) {
return evaluateFormulaCellEnum(cell).getCode();
}
/**
* 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.
* <pre>
* CellType evaluatedCellType = evaluator.evaluateFormulaCellEnum(cell);
* </pre>
* 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.
*/
@Override
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.getCellTypeEnum();
}
protected static void setCellType(Cell cell, CellValue cv) {
CellType cellType = cv.getCellType();
CellType cellType = cv.getCellTypeEnum();
switch (cellType) {
case BOOLEAN:
case ERROR:
@ -151,6 +216,33 @@ public abstract class BaseFormulaEvaluator implements FormulaEvaluator, Workbook
}
}
protected abstract RichTextString createRichTextString(String str);
protected void setCellValue(Cell cell, CellValue cv) {
CellType cellType = cv.getCellTypeEnum();
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(createRichTextString(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 + ")");
}
}
/**
* Loops over all cells in all sheets of the supplied
* workbook.

View File

@ -42,6 +42,7 @@ public interface 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.
*/
int getCellType();
/**
@ -61,6 +62,7 @@ public interface EvaluationCell {
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type of cached formula result
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
int getCachedFormulaResultType();
/**

View File

@ -28,6 +28,7 @@ import org.apache.poi.ss.formula.ptg.Ptg;
import org.apache.poi.ss.formula.ptg.RangePtg;
import org.apache.poi.ss.formula.ptg.UnionPtg;
import org.apache.poi.ss.formula.ptg.ValueOperatorPtg;
import org.apache.poi.util.Removal;
/**
* This class performs 'operand class' transformation. Non-base tokens are classified into three
@ -59,7 +60,10 @@ final class OperandClassTransformer {
private final FormulaType _formulaType;
/** @deprecated POI 3.15 beta 3. */
/**
* @deprecated POI 3.15 beta 3. Use {@code OperandClassTransformer(FormulaType)} instead.
*/
@Removal(version="3.17")
public OperandClassTransformer(int formulaType) {
this(FormulaType.forInt(formulaType));
}

View File

@ -108,6 +108,7 @@ final class ForkedEvaluationCell 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() {
@ -118,7 +119,6 @@ final class ForkedEvaluationCell 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 _cellType;
@ -160,6 +160,7 @@ final class ForkedEvaluationCell implements EvaluationCell {
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return cell type of cached formula result
* @deprecated 3.15. Will return a {@link CellType} enum in the future.
*/
@Override
public int getCachedFormulaResultType() {
@ -170,7 +171,6 @@ final class ForkedEvaluationCell 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 getCachedFormulaResultTypeEnum() {
return _masterCell.getCachedFormulaResultTypeEnum();

View File

@ -17,7 +17,10 @@
package org.apache.poi.ss.formula.functions;
import org.apache.poi.ss.formula.eval.BlankEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.OperandResolver;
import org.apache.poi.ss.formula.eval.ValueEval;
/**
@ -46,8 +49,18 @@ public final class DGet implements IDStarAlgorithm {
public ValueEval getResult() {
if(result == null) {
return ErrorEval.VALUE_INVALID;
} else {
} else if(result instanceof BlankEval) {
return ErrorEval.VALUE_INVALID;
} else
try {
if(OperandResolver.coerceValueToString(OperandResolver.getSingleValue(result, 0, 0)).equals("")) {
return ErrorEval.VALUE_INVALID;
}
else {
return result;
}
} catch (EvaluationException e) {
return e.getErrorEval();
}
}
}

View File

@ -17,13 +17,13 @@
package org.apache.poi.ss.formula.functions;
import org.apache.poi.ss.formula.TwoDEval;
import org.apache.poi.ss.formula.eval.AreaEval;
import org.apache.poi.ss.formula.eval.BlankEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.NotImplementedException;
import org.apache.poi.ss.formula.eval.NumericValueEval;
import org.apache.poi.ss.formula.eval.RefEval;
import org.apache.poi.ss.formula.eval.OperandResolver;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.StringValueEval;
import org.apache.poi.ss.formula.eval.ValueEval;
@ -62,11 +62,17 @@ public final class DStarRunner implements Function3Arg {
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex,
ValueEval database, ValueEval filterColumn, ValueEval conditionDatabase) {
// Input processing and error checks.
if(!(database instanceof TwoDEval) || !(conditionDatabase instanceof TwoDEval)) {
if(!(database instanceof AreaEval) || !(conditionDatabase instanceof AreaEval)) {
return ErrorEval.VALUE_INVALID;
}
TwoDEval db = (TwoDEval)database;
TwoDEval cdb = (TwoDEval)conditionDatabase;
AreaEval db = (AreaEval)database;
AreaEval cdb = (AreaEval)conditionDatabase;
try {
filterColumn = OperandResolver.getSingleValue(filterColumn, srcRowIndex, srcColumnIndex);
} catch (EvaluationException e) {
return e.getErrorEval();
}
int fc;
try {
@ -100,16 +106,12 @@ public final class DStarRunner implements Function3Arg {
}
// Filter each entry.
if(matches) {
try {
ValueEval currentValueEval = solveReference(db.getValue(row, fc));
ValueEval currentValueEval = resolveReference(db, row, fc);
// Pass the match to the algorithm and conditionally abort the search.
boolean shouldContinue = algorithm.processMatch(currentValueEval);
if(! shouldContinue) {
break;
}
} catch (EvaluationException e) {
return e.getErrorEval();
}
}
}
@ -126,56 +128,16 @@ public final class DStarRunner implements Function3Arg {
}
/**
* Resolve reference(-chains) until we have a normal value.
*
* @param field a ValueEval which can be a RefEval.
* @return a ValueEval which is guaranteed not to be a RefEval
* @throws EvaluationException If a multi-sheet reference was found along the way.
*/
private static ValueEval solveReference(ValueEval field) throws EvaluationException {
if (field instanceof RefEval) {
RefEval refEval = (RefEval)field;
if (refEval.getNumberOfSheets() > 1) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
return solveReference(refEval.getInnerValueEval(refEval.getFirstSheetIndex()));
}
else {
return field;
}
}
/**
* Returns the first column index that matches the given name. The name can either be
* a string or an integer, when it's an integer, then the respective column
* (1 based index) is returned.
* @param nameValueEval
* @param db
* @return the first column index that matches the given name (or int)
*
* @param nameValueEval Must not be a RefEval or AreaEval. Thus make sure resolveReference() is called on the value first!
* @param db Database
* @return Corresponding column number.
* @throws EvaluationException
*/
@SuppressWarnings("unused")
private static int getColumnForTag(ValueEval nameValueEval, TwoDEval db)
private static int getColumnForName(ValueEval nameValueEval, AreaEval db)
throws EvaluationException {
int resultColumn = -1;
// Numbers as column indicator are allowed, check that.
if(nameValueEval instanceof NumericValueEval) {
double doubleResultColumn = ((NumericValueEval)nameValueEval).getNumberValue();
resultColumn = (int)doubleResultColumn;
// Floating comparisions are usually not possible, but should work for 0.0.
if(doubleResultColumn - resultColumn != 0.0)
throw new EvaluationException(ErrorEval.VALUE_INVALID);
resultColumn -= 1; // Numbers are 1-based not 0-based.
} else {
resultColumn = getColumnForName(nameValueEval, db);
}
return resultColumn;
}
private static int getColumnForName(ValueEval nameValueEval, TwoDEval db)
throws EvaluationException {
String name = getStringFromValueEval(nameValueEval);
String name = OperandResolver.coerceValueToString(nameValueEval);
return getColumnForString(db, name);
}
@ -187,16 +149,19 @@ public final class DStarRunner implements Function3Arg {
* @return Corresponding column number.
* @throws EvaluationException If it's not possible to turn all headings into strings.
*/
private static int getColumnForString(TwoDEval db,String name)
private static int getColumnForString(AreaEval db,String name)
throws EvaluationException {
int resultColumn = -1;
final int width = db.getWidth();
for(int column = 0; column < width; ++column) {
ValueEval columnNameValueEval = db.getValue(0, column);
if(solveReference(columnNameValueEval) instanceof BlankEval) {
ValueEval columnNameValueEval = resolveReference(db, 0, column);
if(columnNameValueEval instanceof BlankEval) {
continue;
}
String columnName = getStringFromValueEval(columnNameValueEval);
if(columnNameValueEval instanceof ErrorEval) {
continue;
}
String columnName = OperandResolver.coerceValueToString(columnNameValueEval);
if(name.equals(columnName)) {
resultColumn = column;
break;
@ -215,7 +180,7 @@ public final class DStarRunner implements Function3Arg {
* @throws EvaluationException If references could not be resolved or comparison
* operators and operands didn't match.
*/
private static boolean fullfillsConditions(TwoDEval db, int row, TwoDEval cdb)
private static boolean fullfillsConditions(AreaEval db, int row, AreaEval cdb)
throws EvaluationException {
// Only one row must match to accept the input, so rows are ORed.
// Each row is made up of cells where each cell is a condition,
@ -229,20 +194,15 @@ public final class DStarRunner implements Function3Arg {
// special column that accepts formulas.
boolean columnCondition = true;
ValueEval condition = null;
try {
// The condition to apply.
condition = solveReference(cdb.getValue(conditionRow, column));
} catch (java.lang.RuntimeException e) {
// It might be a special formula, then it is ok if it fails.
columnCondition = false;
}
condition = resolveReference(cdb, conditionRow, column);
// If the condition is empty it matches.
if(condition instanceof BlankEval)
continue;
// The column in the DB to apply the condition to.
ValueEval targetHeader = solveReference(cdb.getValue(0, column));
targetHeader = solveReference(targetHeader);
ValueEval targetHeader = resolveReference(cdb, 0, column);
if(!(targetHeader instanceof StringValueEval)) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
@ -254,14 +214,14 @@ public final class DStarRunner implements Function3Arg {
if(columnCondition == true) { // normal column condition
// Should not throw, checked above.
ValueEval value = db.getValue(
row, getColumnForName(targetHeader, db));
ValueEval value = resolveReference(db, row, getColumnForName(targetHeader, db));
if(!testNormalCondition(value, condition)) {
matches = false;
break;
}
} else { // It's a special formula condition.
if(getStringFromValueEval(condition).isEmpty()) {
// TODO: Check whether the condition cell contains a formula and return #VALUE! if it doesn't.
if(OperandResolver.coerceValueToString(condition).isEmpty()) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
throw new NotImplementedException(
@ -328,7 +288,7 @@ public final class DStarRunner implements Function3Arg {
if(itsANumber) {
return testNumericCondition(value, operator.equal, stringOrNumber);
} else { // It's a string.
String valueString = value instanceof BlankEval ? "" : getStringFromValueEval(value);
String valueString = value instanceof BlankEval ? "" : OperandResolver.coerceValueToString(value);
return stringOrNumber.equals(valueString);
}
} else { // It's a text starts-with condition.
@ -336,7 +296,7 @@ public final class DStarRunner implements Function3Arg {
return value instanceof StringEval;
}
else {
String valueString = value instanceof BlankEval ? "" : getStringFromValueEval(value);
String valueString = value instanceof BlankEval ? "" : OperandResolver.coerceValueToString(value);
return valueString.startsWith(conditionString);
}
}
@ -426,18 +386,18 @@ public final class DStarRunner implements Function3Arg {
}
/**
* Takes a ValueEval and tries to retrieve a String value from it.
* It tries to resolve references if there are any.
* Resolve a ValueEval that's in an AreaEval.
*
* @param value ValueEval to retrieve the string from.
* @return String corresponding to the given ValueEval.
* @throws EvaluationException If it's not possible to retrieve a String value.
* @param db AreaEval from which the cell to resolve is retrieved.
* @param dbRow Relative row in the AreaEval.
* @param dbCol Relative column in the AreaEval.
* @return A ValueEval that is a NumberEval, StringEval, BoolEval, BlankEval or ErrorEval.
*/
private static String getStringFromValueEval(ValueEval value)
throws EvaluationException {
value = solveReference(value);
if(!(value instanceof StringValueEval))
throw new EvaluationException(ErrorEval.VALUE_INVALID);
return ((StringValueEval)value).getStringValue();
private static ValueEval resolveReference(AreaEval db, int dbRow, int dbCol) {
try {
return OperandResolver.getSingleValue(db.getValue(dbRow, dbCol), db.getFirstRow()+dbRow, db.getFirstColumn()+dbCol);
} catch (EvaluationException e) {
return e.getErrorEval();
}
}
}

View File

@ -19,6 +19,8 @@
package org.apache.poi.ss.usermodel;
import org.apache.poi.util.Removal;
/**
* High level representation for Border Formatting component
* of Conditional Formatting settings
@ -27,83 +29,127 @@ public interface BorderFormatting {
/** No border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#NONE}
*/
@Removal(version="3.17")
short BORDER_NONE = 0x0;
/** Thin border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#THIN}
*/
@Removal(version="3.17")
short BORDER_THIN = 0x1;
/** Medium border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM}
*/
@Removal(version="3.17")
short BORDER_MEDIUM = 0x2;
/** dash border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DASHED}
*/
@Removal(version="3.17")
short BORDER_DASHED = 0x3;
/** dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DOTTED}
*/
@Removal(version="3.17")
short BORDER_DOTTED = 0x4;
/** Thick border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#THICK}
*/
@Removal(version="3.17")
short BORDER_THICK = 0x5;
/** double-line border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DOUBLE}
*/
@Removal(version="3.17")
short BORDER_DOUBLE = 0x6;
/** hair-line border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#HAIR}
*/
@Removal(version="3.17")
short BORDER_HAIR = 0x7;
/** Medium dashed border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASHED}
*/
@Removal(version="3.17")
short BORDER_MEDIUM_DASHED = 0x8;
/** dash-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT}
*/
@Removal(version="3.17")
short BORDER_DASH_DOT = 0x9;
/** medium dash-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT}
*/
@Removal(version="3.17")
short BORDER_MEDIUM_DASH_DOT = 0xA;
/** dash-dot-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT_DOT}
*/
@Removal(version="3.17")
short BORDER_DASH_DOT_DOT = 0xB;
/** medium dash-dot-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT_DOT}
*/
@Removal(version="3.17")
short BORDER_MEDIUM_DASH_DOT_DOT = 0xC;
/** slanted dash-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#SLANTED_DASH_DOT}
*/
@Removal(version="3.17")
short BORDER_SLANTED_DASH_DOT = 0xD;
BorderStyle getBorderBottom();
/**
* @deprecated POI 3.15. Use {@link #getBorderBottomEnum()}.
* This method will return an BorderStyle enum in the future.
*/
short getBorderBottom();
/** @since POI 3.15 */
BorderStyle getBorderBottomEnum();
BorderStyle getBorderDiagonal();
/**
* @deprecated POI 3.15. Use {@link #getBorderDiagonalEnum()}.
* This method will return an BorderStyle enum in the future.
*/
short getBorderDiagonal();
/** @since POI 3.15 */
BorderStyle getBorderDiagonalEnum();
BorderStyle getBorderLeft();
/**
* @deprecated POI 3.15. Use {@link #getBorderLeftEnum()}.
* This method will return an BorderStyle enum in the future.
*/
short getBorderLeft();
/** @since POI 3.15 */
BorderStyle getBorderLeftEnum();
BorderStyle getBorderRight();
/**
* @deprecated POI 3.15. Use {@link #getBorderRightEnum()}.
* This method will return an BorderStyle enum in the future.
*/
short getBorderRight();
/** @since POI 3.15 */
BorderStyle getBorderRightEnum();
/**
* @deprecated POI 3.15. Use {@link #getBorderTopEnum()}.
* This method will return an BorderStyle enum in the future.
*/
short getBorderTop();
/** @since POI 3.15 */
BorderStyle getBorderTopEnum();
BorderStyle getBorderTop();
short getBottomBorderColor();
Color getBottomBorderColorColor();

View File

@ -75,7 +75,7 @@ public final class BuiltinFormats {
"#,##0.00",
"\"$\"#,##0_);(\"$\"#,##0)",
"\"$\"#,##0_);[Red](\"$\"#,##0)",
"\"$\"#,##,00_);(\"$\"#,##0.00)",
"\"$\"#,##0.00_);(\"$\"#,##0.00)",
"\"$\"#,##0.00_);[Red](\"$\"#,##0.00)",
"0%",
"0.00%",

View File

@ -24,6 +24,7 @@ import org.apache.poi.ss.formula.FormulaParseException;
import org.apache.poi.ss.util.CellAddress;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
/**
* High level representation of a cell in a row of a spreadsheet.
@ -46,7 +47,8 @@ public interface Cell {
* @see #getCellType()
* @deprecated POI 3.15 beta 3. Use {@link CellType#NUMERIC} instead.
*/
CellType CELL_TYPE_NUMERIC = CellType.NUMERIC;
@Removal(version="4.0")
int CELL_TYPE_NUMERIC = 0; //CellType.NUMERIC.getCode();
/**
* String Cell type (1)
@ -54,7 +56,8 @@ public interface Cell {
* @see #getCellType()
* @deprecated POI 3.15 beta 3. Use {@link CellType#STRING} instead.
*/
CellType CELL_TYPE_STRING = CellType.STRING;
@Removal(version="4.0")
int CELL_TYPE_STRING = 1; //CellType.STRING.getCode();
/**
* Formula Cell type (2)
@ -62,7 +65,8 @@ public interface Cell {
* @see #getCellType()
* @deprecated POI 3.15 beta 3. Use {@link CellType#FORMULA} instead.
*/
CellType CELL_TYPE_FORMULA = CellType.FORMULA;
@Removal(version="4.0")
int CELL_TYPE_FORMULA = 2; //CellType.FORMULA.getCode();
/**
* Blank Cell type (3)
@ -70,7 +74,8 @@ public interface Cell {
* @see #getCellType()
* @deprecated POI 3.15 beta 3. Use {@link CellType#BLANK} instead.
*/
CellType CELL_TYPE_BLANK = CellType.BLANK;
@Removal(version="4.0")
int CELL_TYPE_BLANK = 3; //CellType.BLANK.getCode();
/**
* Boolean Cell type (4)
@ -78,7 +83,8 @@ public interface Cell {
* @see #getCellType()
* @deprecated POI 3.15 beta 3. Use {@link CellType#BOOLEAN} instead.
*/
CellType CELL_TYPE_BOOLEAN = CellType.BOOLEAN;
@Removal(version="4.0")
int CELL_TYPE_BOOLEAN = 4; //CellType.BOOLEAN.getCode();
/**
* Error Cell type (5)
@ -86,7 +92,8 @@ public interface Cell {
* @see #getCellType()
* @deprecated POI 3.15 beta 3. Use {@link CellType#ERROR} instead.
*/
CellType CELL_TYPE_ERROR = CellType.ERROR;
@Removal(version="4.0")
int CELL_TYPE_ERROR = 5; //CellType.ERROR.getCode();
/**
* Returns column index of this cell
@ -136,6 +143,7 @@ public interface Cell {
* @see CellType#ERROR
* @deprecated POI 3.15 beta 3. Use {@link #setCellType(CellType)} instead.
*/
@Removal(version="4.0")
void setCellType(int cellType);
/**
* Set the cells type (numeric, formula or string).
@ -155,10 +163,11 @@ public interface Cell {
/**
* Return the cell type.
*
* Will return {@link CellType} in a future version of POI.
* Will return {@link CellType} in version 4.0 of POI.
* For forwards compatibility, do not hard-code cell type literals in your code.
*
* @return the cell type
* @deprecated POI 3.15. Will return a {@link CellType} enum in the future.
*/
int getCellType();
@ -168,9 +177,9 @@ public interface Cell {
* @return the cell type
* @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.
* Will be renamed to <code>getCellType()</code> when we make the CellType enum transition in POI 4.0. See bug 59791.
*/
@Internal(since="POI 3.15 beta 3")
@Removal(version="4.2")
CellType getCellTypeEnum();
/**
@ -182,6 +191,7 @@ public interface 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.
*/
int getCachedFormulaResultType();
@ -192,9 +202,8 @@ public interface Cell {
* on the cached value of the formula
* @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.
* Will be renamed to <code>getCachedFormulaResultType()</code> when we make the CellType enum transition in POI 4.0. See bug 59791.
*/
@Internal(since="POI 3.15 beta 3")
CellType getCachedFormulaResultTypeEnum();
/**

View File

@ -17,270 +17,316 @@
package org.apache.poi.ss.usermodel;
import org.apache.poi.util.Removal;
public interface CellStyle {
/**
* general (normal) horizontal alignment
* @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#GENERAL} instead.
*/
@Removal(version="3.17")
static final short ALIGN_GENERAL = 0x0; //HorizontalAlignment.GENERAL.getCode();
/**
* left-justified horizontal alignment
* @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#LEFT} instead.
*/
@Removal(version="3.17")
static final short ALIGN_LEFT = 0x1; //HorizontalAlignment.LEFT.getCode();
/**
* center horizontal alignment
* @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#CENTER} instead.
*/
@Removal(version="3.17")
static final short ALIGN_CENTER = 0x2; //HorizontalAlignment.CENTER.getCode();
/**
* right-justified horizontal alignment
* @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#RIGHT} instead.
*/
@Removal(version="3.17")
static final short ALIGN_RIGHT = 0x3; //HorizontalAlignment.RIGHT.getCode();
/**
* fill? horizontal alignment
* @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#FILL} instead.
*/
@Removal(version="3.17")
static final short ALIGN_FILL = 0x4; //HorizontalAlignment.FILL.getCode();
/**
* justified horizontal alignment
* @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#JUSTIFY} instead.
*/
@Removal(version="3.17")
static final short ALIGN_JUSTIFY = 0x5; //HorizontalAlignment.JUSTIFY.getCode();
/**
* center-selection? horizontal alignment
* @deprecated POI 3.15 beta 3. Use {@link HorizontalAlignment#CENTER_SELECTION} instead.
*/
@Removal(version="3.17")
static final short ALIGN_CENTER_SELECTION = 0x6; //HorizontalAlignment.CENTER_SELECTION.getCode();
/**
* top-aligned vertical alignment
* @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#TOP} instead.
*/
@Removal(version="3.17")
static final short VERTICAL_TOP = 0x0; //VerticalAlignment.TOP.getCode();
/**
* center-aligned vertical alignment
* @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#CENTER} instead.
*/
@Removal(version="3.17")
static final short VERTICAL_CENTER = 0x1; //VerticalAlignment.CENTER.getCode();
/**
* bottom-aligned vertical alignment
* @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#BOTTOM} instead.
*/
@Removal(version="3.17")
static final short VERTICAL_BOTTOM = 0x2; //VerticalAlignment.BOTTOM.getCode();
/**
* vertically justified vertical alignment
* @deprecated POI 3.15 beta 3. Use {@link VerticalAlignment#JUSTIFY} instead.
*/
@Removal(version="3.17")
static final short VERTICAL_JUSTIFY = 0x3; //VerticalAlignment.JUSTIFY.getCode();
/**
* No border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#NONE} instead.
*/
@Removal(version="3.17")
static final short BORDER_NONE = 0x0; //BorderStyle.NONE.getCode();
/**
* Thin border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#THIN} instead.
*/
@Removal(version="3.17")
static final short BORDER_THIN = 0x1; //BorderStyle.THIN.getCode();
/**
* Medium border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM} instead.
*/
@Removal(version="3.17")
static final short BORDER_MEDIUM = 0x2; //BorderStyle.MEDIUM.getCode();
/**
* dash border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DASHED} instead.
*/
@Removal(version="3.17")
static final short BORDER_DASHED = 0x3; //BorderStyle.DASHED.getCode();
/**
* dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DOTTED} instead.
*/
@Removal(version="3.17")
static final short BORDER_DOTTED = 0x4; //BorderStyle.DOTTED.getCode();
/**
* Thick border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#THICK} instead.
*/
@Removal(version="3.17")
static final short BORDER_THICK = 0x5; //BorderStyle.THICK.getCode();
/**
* double-line border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DOUBLE} instead.
*/
@Removal(version="3.17")
static final short BORDER_DOUBLE = 0x6; //BorderStyle.DOUBLE.getCode();
/**
* hair-line border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#HAIR} instead.
*/
@Removal(version="3.17")
static final short BORDER_HAIR = 0x7; //BorderStyle.HAIR.getCode();
/**
* Medium dashed border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASHED} instead.
*/
@Removal(version="3.17")
static final short BORDER_MEDIUM_DASHED = 0x8; //BorderStyle.MEDIUM_DASHED.getCode();
/**
* dash-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT} instead.
*/
@Removal(version="3.17")
static final short BORDER_DASH_DOT = 0x9; //BorderStyle.DASH_DOT.getCode();
/**
* medium dash-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT} instead.
*/
@Removal(version="3.17")
static final short BORDER_MEDIUM_DASH_DOT = 0xA; //BorderStyle.MEDIUM_DASH_DOT.getCode();
/**
* dash-dot-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#DASH_DOT_DOT} instead.
*/
@Removal(version="3.17")
static final short BORDER_DASH_DOT_DOT = 0xB; //BorderStyle.DASH_DOT_DOT.getCode();
/**
* medium dash-dot-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#MEDIUM_DASH_DOT_DOT} instead.
*/
@Removal(version="3.17")
static final short BORDER_MEDIUM_DASH_DOT_DOT = 0xC; //BorderStyle.MEDIUM_DASH_DOT_DOT.getCode();
/**
* slanted dash-dot border
* @deprecated 3.15 beta 2. Use {@link BorderStyle#SLANTED_DASH_DOT} instead.
*/
@Removal(version="3.17")
static final short BORDER_SLANTED_DASH_DOT = 0xD; //BorderStyle.SLANTED_DASH_DOT.getCode();
/**
* Fill Pattern: No background
* @deprecated 3.15 beta 3. Use {@link FillPatternType#NO_FILL} instead.
*/
@Removal(version="3.17")
static final short NO_FILL = 0; //FillPatternType.NO_FILL.getCode();
/**
* Fill Pattern: Solidly filled
* @deprecated 3.15 beta 3. Use {@link FillPatternType#SOLID_FOREGROUND} instead.
*/
@Removal(version="3.17")
static final short SOLID_FOREGROUND = 1; //FillPatternType.SOLID_FOREGROUND.getCode();
/**
* Fill Pattern: Small fine dots
* @deprecated 3.15 beta 3. Use {@link FillPatternType#FINE_DOTS} instead.
*/
@Removal(version="3.17")
static final short FINE_DOTS = 2; //FillPatternType.FINE_DOTS.getCode();
/**
* Fill Pattern: Wide dots
* @deprecated 3.15 beta 3. Use {@link FillPatternType#ALT_BARS} instead.
*/
@Removal(version="3.17")
static final short ALT_BARS = 3; //FillPatternType.ALT_BARS.getCode();
/**
* Fill Pattern: Sparse dots
* @deprecated 3.15 beta 3. Use {@link FillPatternType#SPARSE_DOTS} instead.
*/
@Removal(version="3.17")
static final short SPARSE_DOTS = 4; //FillPatternType.SPARSE_DOTS.getCode();
/**
* Fill Pattern: Thick horizontal bands
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_HORZ_BANDS} instead.
*/
@Removal(version="3.17")
static final short THICK_HORZ_BANDS = 5; //FillPatternType.THICK_HORZ_BANDS.getCode();
/**
* Fill Pattern: Thick vertical bands
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_VERT_BANDS} instead.
*/
@Removal(version="3.17")
static final short THICK_VERT_BANDS = 6; //FillPatternType.THICK_VERT_BANDS.getCode();
/**
* Fill Pattern: Thick backward facing diagonals
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_BACKWARD_DIAG} instead.
*/
@Removal(version="3.17")
static final short THICK_BACKWARD_DIAG = 7; //FillPatternType.THICK_BACKWARD_DIAG.getCode();
/**
* Fill Pattern: Thick forward facing diagonals
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THICK_FORWARD_DIAG} instead.
*/
@Removal(version="3.17")
static final short THICK_FORWARD_DIAG = 8; //FillPatternType.THICK_FORWARD_DIAG.getCode();
/**
* Fill Pattern: Large spots
* @deprecated 3.15 beta 3. Use {@link FillPatternType#BIG_SPOTS} instead.
*/
@Removal(version="3.17")
static final short BIG_SPOTS = 9; //FillPatternType.BIG_SPOTS.getCode();
/**
* Fill Pattern: Brick-like layout
* @deprecated 3.15 beta 3. Use {@link FillPatternType#BRICKS} instead.
*/
@Removal(version="3.17")
static final short BRICKS = 10; //FillPatternType.BRICKS.getCode();
/**
* Fill Pattern: Thin horizontal bands
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_HORZ_BANDS} instead.
*/
@Removal(version="3.17")
static final short THIN_HORZ_BANDS = 11; //FillPatternType.THIN_HORZ_BANDS.getCode();
/**
* Fill Pattern: Thin vertical bands
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_VERT_BANDS} instead.
*/
@Removal(version="3.17")
static final short THIN_VERT_BANDS = 12; //FillPatternType.THIN_VERT_BANDS.getCode();
/**
* Fill Pattern: Thin backward diagonal
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_BACKWARD_DIAG} instead.
*/
@Removal(version="3.17")
static final short THIN_BACKWARD_DIAG = 13; //FillPatternType.THIN_BACKWARD_DIAG.getCode();
/**
* Fill Pattern: Thin forward diagonal
* @deprecated 3.15 beta 3. Use {@link FillPatternType#THIN_FORWARD_DIAG} instead.
*/
@Removal(version="3.17")
static final short THIN_FORWARD_DIAG = 14; //FillPatternType.THIN_FORWARD_DIAG.getCode();
/**
* Fill Pattern: Squares
* @deprecated 3.15 beta 3. Use {@link FillPatternType#SQUARES} instead.
*/
@Removal(version="3.17")
static final short SQUARES = 15; //FillPatternType.SQUARES.getCode();
/**
* Fill Pattern: Diamonds
* @deprecated 3.15 beta 3. Use {@link FillPatternType#DIAMONDS} instead.
*/
@Removal(version="3.17")
static final short DIAMONDS = 16; //FillPatternType.DIAMONDS.getCode();
/**
* Fill Pattern: Less Dots
* @deprecated 3.15 beta 3. Use {@link FillPatternType#LESS_DOTS} instead.
*/
@Removal(version="3.17")
static final short LESS_DOTS = 17; //FillPatternType.LESS_DOTS.getCode();
/**
* Fill Pattern: Least Dots
* @deprecated 3.15 beta 3. Use {@link FillPatternType#LEAST_DOTS} instead.
*/
@Removal(version="3.17")
static final short LEAST_DOTS = 18; //FillPatternType.LEAST_DOTS.getCode();
/**
@ -495,19 +541,29 @@ public interface CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link #setBorderLeft(BorderStyle)} instead
*/
@Removal(version="3.17")
void setBorderLeft(short border);
/**
* set the type of border to use for the left border of the cell
* @param border type
* @since POI 3.15
*/
void setBorderLeft(BorderStyle border);
/**
* get the type of border to use for the left border of the cell
* @return border type
* @deprecated POI 3.15. Use {@link #getBorderLeftEnum()} instead.
* This will return a BorderStyle enum in the future.
*/
BorderStyle getBorderLeft();
short getBorderLeft();
/**
* get the type of border to use for the left border of the cell
* @return border type
* @since POI 3.15
*/
BorderStyle getBorderLeftEnum();
/**
* set the type of border to use for the right border of the cell
@ -528,19 +584,29 @@ public interface CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link #setBorderRight(BorderStyle)} instead
*/
@Removal(version="3.17")
void setBorderRight(short border);
/**
* set the type of border to use for the right border of the cell
* @param border type
* @since POI 3.15
*/
void setBorderRight(BorderStyle border);
/**
* get the type of border to use for the right border of the cell
* @return border type
* @deprecated POI 3.15. Use {@link #getBorderRightEnum()} instead.
* This will return a BorderStyle enum in the future.
*/
BorderStyle getBorderRight();
short getBorderRight();
/**
* get the type of border to use for the right border of the cell
* @return border type
* @since POI 3.15
*/
BorderStyle getBorderRightEnum();
/**
* set the type of border to use for the top border of the cell
@ -561,19 +627,29 @@ public interface CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link #setBorderTop(BorderStyle)} instead
*/
@Removal(version="3.17")
void setBorderTop(short border);
/**
* set the type of border to use for the top border of the cell
* @param border type
* @since POI 3.15
*/
void setBorderTop(BorderStyle border);
/**
* get the type of border to use for the top border of the cell
* @return border type
* @deprecated POI 3.15. Use {@link #getBorderTopEnum()} instead.
* This will return a BorderStyle enum in the future.
*/
BorderStyle getBorderTop();
short getBorderTop();
/**
* get the type of border to use for the top border of the cell
* @return border type
* @since POI 3.15
*/
BorderStyle getBorderTopEnum();
/**
* set the type of border to use for the bottom border of the cell
@ -594,19 +670,29 @@ public interface CellStyle {
* @see #BORDER_SLANTED_DASH_DOT
* @deprecated 3.15 beta 2. Use {@link #setBorderBottom(BorderStyle)} instead.
*/
@Removal(version="3.17")
void setBorderBottom(short border);
/**
* set the type of border to use for the bottom border of the cell
* @param border type
* @since POI 3.15
*/
void setBorderBottom(BorderStyle border);
/**
* get the type of border to use for the bottom border of the cell
* @return border type
* @deprecated POI 3.15. Use {@link #getBorderBottomEnum()} instead.
* This will return a BorderStyle enum in the future.
*/
BorderStyle getBorderBottom();
short getBorderBottom();
/**
* get the type of border to use for the bottom border of the cell
* @return border type
* @since POI 3.15
*/
BorderStyle getBorderBottomEnum();
/**
* set the color to use for the left border

View File

@ -78,10 +78,22 @@ public final class CellValue {
}
/**
* @return Returns the cellType.
* @since POI 3.15
*/
public CellType getCellType() {
public CellType getCellTypeEnum() {
return _cellType;
}
/**
* @return Returns the cellType.
* @deprecated POI 3.15. Use {@link #getCellTypeEnum()} instead.
* In the future, the signature of this method will be changed to return a
* {@link CellType}.
*/
@Deprecated
public int getCellType() {
return _cellType.getCode();
}
/**
* @return Returns the errorValue.
*/

View File

@ -17,6 +17,7 @@
package org.apache.poi.ss.usermodel;
import org.apache.poi.util.Internal;
import org.apache.poi.util.Removal;
/**
* A client anchor is attached to an excel worksheet. It anchors against a
@ -35,6 +36,7 @@ public interface ClientAnchor {
* </p>
* @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 {
* </p>
* @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 {
* </p>
* @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();

View File

@ -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);

View File

@ -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;

View File

@ -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:

View File

@ -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;

View File

@ -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);

View File

@ -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<Cell> {
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<Cell> {
*
* @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<Cell> {
*
* @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<Cell> {
*
* @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;

View File

@ -42,7 +42,7 @@ public class DataSources {
return new AbstractCellRangeDataSource<Number>(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<String>(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;

View File

@ -405,10 +405,10 @@ public final class CellUtil {
Map<String, Object> properties = new HashMap<String, Object>();
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());

View File

@ -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<PackagePart> context = new HashSet<PackagePart>();
@ -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);
}
}

View File

@ -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) {
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;

View File

@ -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);
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,37 +142,73 @@ 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
* a custom ZipEntrySource, typically an open archive
@ -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,7 +443,8 @@ public final class ZipPackage extends OPCPackage {
// Save the final package to a temporary file
try {
save(tempFile);
} finally {
try {
// Close the current zip file, so we can
// overwrite it on all platforms
this.zipArchive.close();
@ -408,6 +460,7 @@ public final class ZipPackage extends OPCPackage {
+ "' cannot be deleted ! Make sure that no other application use it.");
}
}
}
} else {
throw new InvalidOperationException(
"Can't close a package not previously open with the open() method !");

View File

@ -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

View File

@ -45,4 +45,9 @@ public interface ZipEntrySource {
* resources may be freed
*/
public void close() throws IOException;
/**
* Has close been called already?
*/
public boolean isClosed();
}

View File

@ -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)

View File

@ -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

View File

@ -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);
}

View File

@ -471,6 +471,7 @@ implements SlideShow<XSLFShape,XSLFTextParagraph> {
* @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<XSLFShape,XSLFTextParagraph> {
* @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<XSLFShape,XSLFTextParagraph> {
*
* @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) {

View File

@ -69,6 +69,10 @@ public class XSLFHyperlink implements Hyperlink<XSLFShape,XSLFTextParagraph> {
_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();

View File

@ -32,9 +32,9 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTTableRow;
* Represents a table in a .pptx presentation
*/
public class XSLFTableRow implements Iterable<XSLFTableCell> {
private CTTableRow _row;
private List<XSLFTableCell> _cells;
private XSLFTable _table;
private final CTTableRow _row;
private final List<XSLFTableCell> _cells;
private final XSLFTable _table;
/*package*/ XSLFTableRow(CTTableRow row, XSLFTable table){
_row = row;
@ -79,5 +79,28 @@ public class XSLFTableRow implements Iterable<XSLFTableCell> {
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);
}
}
}

View File

@ -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)));

View File

@ -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);

View File

@ -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:
* <pre>
* int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
* </pre>
* 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);
}
/**

View File

@ -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.
* <pre>
* CellType evaluatedCellType = evaluator.evaluateFormulaCellEnum(cell);
* </pre>
* 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
*/

View File

@ -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));
}

View File

@ -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;
}
try {
return FormulaError.forString(code).getCode();
} catch (final IllegalArgumentException e) {
throw new IllegalStateException("Unexpected error code", e);
}
}
/**

View File

@ -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));

View File

@ -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

View File

@ -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);

View File

@ -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();

View File

@ -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 {

View File

@ -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.<p/>
@ -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:
* <pre>
* int evaluatedCellType = evaluator.evaluateInCell(cell).getCellType();
* </pre>
* 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.

View File

@ -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() {

View File

@ -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) {
AreaReference pivotArea = getPivotArea();
int lastRowIndex = pivotArea.getLastCell().getRow() - pivotArea.getFirstCell().getRow();
int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol();
checkColumnIndex(columnIndex);
if(columnIndex > lastColIndex) {
throw new IndexOutOfBoundsException();
}
AreaReference pivotArea = getPivotArea();
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) {
AreaReference pivotArea = getPivotArea();
int lastColIndex = pivotArea.getLastCell().getCol() - pivotArea.getFirstCell().getCol();
checkColumnIndex(columnIndex);
AreaReference pivotArea = getPivotArea();
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();

View File

@ -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);
}

View File

@ -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());
try {
doc = new OPCParser(pkg1);
try {
doc.parse(new TestFactory());
context = new HashMap<String,POIXMLDocumentPart>();
traverse(doc, context);
@ -150,6 +184,7 @@ public final class TestPOIXMLDocument {
}
} finally {
doc.close();
pkg1.close();
pkg2.close();
}
}

View File

@ -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",

View File

@ -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();
}
}
}
}

View File

@ -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());
}
}
}

View File

@ -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;
}
}
}

View File

@ -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());

View File

@ -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();

View File

@ -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<XSLFShape> shapes = slide.getShapes();
tbl = (XSLFTable)shapes.get(0);
List<XSLFTableRow> 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<XSLFTableCell> 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<XSLFTableCell> 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);
}
}

View File

@ -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());
}
}

View File

@ -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 {

View File

@ -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:

View File

@ -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:

View File

@ -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());

View File

@ -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();

View File

@ -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();
}
}

View File

@ -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);
@ -115,10 +124,18 @@ public class TestXSSFPivotTable extends TestCase {
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"));
}
}

View File

@ -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);
}
}
}

View File

@ -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");

View File

@ -804,6 +804,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
* @param format The format of the picture.
*
* @return the picture data.
* @since 3.15 beta 2
*/
@Override
public HSLFPictureData addPicture(InputStream is, PictureType format) throws IOException {
@ -822,6 +823,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
* The format of the picture.
*
* @return the picture data.
* @since 3.15 beta 2
*/
@Override
public HSLFPictureData addPicture(File pict, PictureType format) throws IOException {
@ -844,6 +846,7 @@ public final class HSLFSlideShow implements SlideShow<HSLFShape,HSLFTextParagrap
*
* @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 3
*/
@Override
public HSLFPictureData findPictureData(byte[] pictureData) {

View File

@ -193,10 +193,10 @@ public class ExcelToFoConverter extends AbstractExcelConverter
protected boolean isEmptyStyle( CellStyle cellStyle ) {
return cellStyle == null || (
cellStyle.getFillPattern() == 0
&& cellStyle.getBorderTop() == BorderStyle.NONE
&& cellStyle.getBorderRight() == BorderStyle.NONE
&& cellStyle.getBorderBottom() == BorderStyle.NONE
&& cellStyle.getBorderLeft() == BorderStyle.NONE
&& cellStyle.getBorderTopEnum() == BorderStyle.NONE
&& cellStyle.getBorderRightEnum() == BorderStyle.NONE
&& cellStyle.getBorderBottomEnum() == BorderStyle.NONE
&& cellStyle.getBorderLeftEnum() == BorderStyle.NONE
);
}
@ -361,13 +361,13 @@ public class ExcelToFoConverter extends AbstractExcelConverter
}
processCellStyleBorder( workbook, cellTarget, "top",
cellStyle.getBorderTop(), cellStyle.getTopBorderColor() );
cellStyle.getBorderTopEnum(), cellStyle.getTopBorderColor() );
processCellStyleBorder( workbook, cellTarget, "right",
cellStyle.getBorderRight(), cellStyle.getRightBorderColor() );
cellStyle.getBorderRightEnum(), cellStyle.getRightBorderColor() );
processCellStyleBorder( workbook, cellTarget, "bottom",
cellStyle.getBorderBottom(), cellStyle.getBottomBorderColor() );
cellStyle.getBorderBottomEnum(), cellStyle.getBottomBorderColor() );
processCellStyleBorder( workbook, cellTarget, "left",
cellStyle.getBorderLeft(), cellStyle.getLeftBorderColor() );
cellStyle.getBorderLeftEnum(), cellStyle.getLeftBorderColor() );
HSSFFont font = cellStyle.getFont( workbook );
processCellStyleFont( workbook, blockTarget, font );

View File

@ -175,13 +175,13 @@ public class ExcelToHtmlConverter extends AbstractExcelConverter
break;
}
buildStyle_border( workbook, style, "top", cellStyle.getBorderTop(),
buildStyle_border( workbook, style, "top", cellStyle.getBorderTopEnum(),
cellStyle.getTopBorderColor() );
buildStyle_border( workbook, style, "right",
cellStyle.getBorderRight(), cellStyle.getRightBorderColor() );
cellStyle.getBorderRightEnum(), cellStyle.getRightBorderColor() );
buildStyle_border( workbook, style, "bottom",
cellStyle.getBorderBottom(), cellStyle.getBottomBorderColor() );
buildStyle_border( workbook, style, "left", cellStyle.getBorderLeft(),
cellStyle.getBorderBottomEnum(), cellStyle.getBottomBorderColor() );
buildStyle_border( workbook, style, "left", cellStyle.getBorderLeftEnum(),
cellStyle.getLeftBorderColor() );
HSSFFont font = cellStyle.getFont( workbook );

View File

@ -20,9 +20,7 @@ package org.apache.poi.ddf;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
@ -30,6 +28,7 @@ import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.util.IOUtils;
import org.apache.poi.util.LocaleUtil;
import org.apache.poi.util.NullOutputStream;
import org.junit.BeforeClass;
import org.junit.Test;
@ -84,22 +83,5 @@ public class TestEscherDump {
private NullPrinterStream() throws UnsupportedEncodingException {
super(new NullOutputStream(),true,LocaleUtil.CHARSET_1252.name());
}
/**
* Implementation of an OutputStream which does nothing, used
* to redirect stdout to avoid spamming the console with output
*/
private static class NullOutputStream extends OutputStream {
@Override
public void write(byte[] b, int off, int len) {
}
@Override
public void write(int b) {
}
@Override
public void write(byte[] b) throws IOException {
}
}
}
}

View File

@ -21,7 +21,6 @@ import static org.junit.Assert.assertNotNull;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
@ -32,6 +31,7 @@ import java.util.Map;
import org.apache.poi.POIDataSamples;
import org.apache.poi.hssf.record.crypto.Biff8EncryptionKey;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.util.NullOutputStream;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@ -119,22 +119,4 @@ public abstract class BaseXLSIteratingTest {
}
abstract void runOneFile(File pFile) throws Exception;
/**
* Implementation of an OutputStream which does nothing, used
* to redirect stdout to avoid spamming the console with output
*/
private static class NullOutputStream extends OutputStream {
@Override
public void write(byte[] b, int off, int len) {
}
@Override
public void write(int b) {
}
@Override
public void write(byte[] b) throws IOException {
}
}
}

Some files were not shown because too many files have changed in this diff Show More