copy the ooxml branch to trunk
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@712084 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
commit
4b4b139e37
437
build.xml
437
build.xml
@ -45,6 +45,9 @@ under the License.
|
||||
To build the documentation you will need to install forrest and set
|
||||
the FORREST_HOME environment variable. Forrest 0.5.1 required.
|
||||
|
||||
You will need JDK 1.5 or newer to build much of POI. If all you want
|
||||
is the core OLE2 support, then you only need JDK 1.4
|
||||
|
||||
Some people may find the tests hang when run through Ant. If this
|
||||
happens to you, try giving Ant some more memory when you run it, eg:
|
||||
ANT_OPTS="-Xmx1024m -XX:MaxPermSize=256m" ant test
|
||||
@ -72,8 +75,10 @@ under the License.
|
||||
<property name="main.src.test" location="src/testcases"/>
|
||||
<property name="main.documentation" value="src/documentation"/>
|
||||
<property name="main.output.dir" location="build/classes"/>
|
||||
<property name="main14.output.dir" location="build/classes-jdk14"/>
|
||||
<property name="main.output.test.dir" location="build/test-classes"/>
|
||||
<property name="main.lib" location="lib"/>
|
||||
<property name="ooxml.lib" location="ooxml-lib"/>
|
||||
<property name="main.reports.test" location="build/test-results"/>
|
||||
<property name="main.jar1.dir" location="${main.lib}/commons-logging-1.1.jar"/>
|
||||
<property name="main.jar1.url" value="${repository}/commons-logging/jars/commons-logging-1.1.jar"/>
|
||||
@ -107,6 +112,47 @@ under the License.
|
||||
<property name="examples.src" location="src/examples/src"/>
|
||||
<property name="examples.output.dir" location="build/examples-classes"/>
|
||||
|
||||
<!-- Common interfaces for ole2 and ooxml classes -->
|
||||
<property name="interfaces.jdk14.src" location="src/ooxml/interfaces-jdk14"/>
|
||||
<property name="interfaces.jdk15.src" location="src/ooxml/interfaces-jdk15"/>
|
||||
|
||||
<!-- Experimental OOXML support: -->
|
||||
<property name="ooxml.src" location="src/ooxml/java"/>
|
||||
<property name="ooxml.src.test" location="src/ooxml/testcases"/>
|
||||
<property name="ooxml.reports.test" location="build/ooxml-test-results"/>
|
||||
<property name="ooxml.output.dir" location="build/ooxml-classes"/>
|
||||
<property name="ooxml.output.test.dir" location="build/ooxml-test-classes"/>
|
||||
<property name="ooxml.testokfile" location="build/ooxml-testokfile.txt"/>
|
||||
|
||||
<property name="ooxml.jar1.dir" location="${ooxml.lib}/dom4j-1.6.1.jar"/>
|
||||
<property name="ooxml.jar1.url" value="${repository}/dom4j/jars/dom4j-1.6.1.jar"/>
|
||||
<property name="ooxml.jar2.dir" location="${ooxml.lib}/jaxen-1.1.jar"/>
|
||||
<property name="ooxml.jar2.url" value="${repository}/jaxen/jars/jaxen-1.1.jar"/>
|
||||
<property name="ooxml.jar3.dir" location="${ooxml.lib}/xercesImpl-2.8.1.jar"/>
|
||||
<property name="ooxml.jar3.url" value="${repository}/xerces/jars/xercesImpl-2.8.1.jar"/>
|
||||
<property name="ooxml.jar4.dir" location="${ooxml.lib}/xmlbeans-2.3.0.jar"/>
|
||||
<property name="ooxml.jar4.url" value="${repository}/org.apache.xmlbeans/jars/xmlbeans-2.3.0.jar"/>
|
||||
<property name="ooxml.jar5.dir" location="${ooxml.lib}/jsr173_1.0_api.jar"/>
|
||||
<property name="ooxml.jar5.url" value="${repository}/xmlbeans/jars/jsr173_1.0_api.jar"/>
|
||||
<!-- No official release of openxml4j yet -->
|
||||
<property name="ooxml.jar6.dir" location="${ooxml.lib}/openxml4j-bin-beta-080728.jar"/>
|
||||
<property name="ooxml.jar6.url" value="http://people.apache.org/~nick/openxml4j-bin-beta-080728.jar"/>
|
||||
|
||||
<!-- See http://www.ecma-international.org/publications/standards/Ecma-376.htm -->
|
||||
<!-- "Copy these file(s), free of charge" -->
|
||||
<property name="ooxml.xsds.ozip" location="${ooxml.lib}/OfficeOpenXML-Part4.zip"/>
|
||||
<property name="ooxml.xsds.izip" location="${ooxml.lib}/OfficeOpenXML-XMLSchema.zip"/>
|
||||
<property name="ooxml.xsds.url" value="http://www.ecma-international.org/publications/files/ECMA-ST/Office%20Open%20XML%20Part%204%20(DOCX).zip" />
|
||||
<property name="ooxml.xsds.jar" location="${ooxml.lib}/ooxml-schemas.jar"/>
|
||||
|
||||
<!--
|
||||
YK: OOXML requires two dependencies that are not in the Maven repository.
|
||||
-->
|
||||
<property name="maven.ooxml.xsds.version.id" value="1.0"/>
|
||||
<property name="maven.ooxml.xsds.jar" value="ooxml-schemas-${maven.ooxml.xsds.version.id}.jar"/>
|
||||
<property name="maven.openxml4j.version.id" value="1.0-beta"/>
|
||||
<property name="maven.openxml4j.jar" value="openxml4j-${maven.openxml4j.version.id}.jar"/>
|
||||
|
||||
<property name="build.site" location="build/tmp/site/build/site"/>
|
||||
<property name="build.site.src" location="build/tmp/site"/>
|
||||
<property name="junit.report.dir" location="${build.site}/junit"/>
|
||||
@ -118,21 +164,34 @@ under the License.
|
||||
<property name="mavendist.dir" location="build/maven-dist"/>
|
||||
<property name="mavendist.poi.dir" location="build/maven-dist/poi"/>
|
||||
<property name="mavendist.oap.dir" location="build/maven-dist/org.apache.poi"/>
|
||||
<property name="mavendist.ooxml.dir" location="build/maven-ooxml-dependencies"/>
|
||||
<property name="jar.name" value="poi"/>
|
||||
<property name="version.id" value="3.3-alpha1"/>
|
||||
<property name="version.id" value="3.5-beta4"/>
|
||||
<property name="halt.on.test.failure" value="true"/>
|
||||
<property name="jdk.version.source" value="1.3"
|
||||
|
||||
<property name="jdk.version.source" value="1.5"
|
||||
description="JDK version of source code"/>
|
||||
<property name="jdk.version.class" value="1.3"
|
||||
<property name="jdk.version.class" value="1.5"
|
||||
description="JDK version of generated class files"/>
|
||||
<property name="jdk14.version.source" value="1.3"
|
||||
description="JDK version of source code, when built on JDK 1.4"/>
|
||||
<property name="jdk14.version.class" value="1.3"
|
||||
description="JDK version of generated class files, when built on JDK 1.4"/>
|
||||
|
||||
|
||||
<!-- normally use the jdk 1.5 stuff -->
|
||||
<path id="main.classpath">
|
||||
<pathelement location="${main.jar1.dir}"/>
|
||||
<pathelement location="${main.jar2.dir}"/>
|
||||
<pathelement location="${main.resource1.dir}"/>
|
||||
</path>
|
||||
|
||||
<path id="main14.classpath">
|
||||
<pathelement location="${main.jar1.dir}"/>
|
||||
<pathelement location="${main.jar2.dir}"/>
|
||||
<pathelement location="${main.resource1.dir}"/>
|
||||
</path>
|
||||
|
||||
<path id="scratchpad.classpath">
|
||||
<path refid="main.classpath"/>
|
||||
<pathelement location="${main.output.dir}"/>
|
||||
@ -149,11 +208,36 @@ under the License.
|
||||
<pathelement location="${contrib.output.test.dir}"/>
|
||||
</path>
|
||||
|
||||
<path id="examples.classpath">
|
||||
<path refid="main.classpath"/>
|
||||
<pathelement location="${main.output.dir}"/>
|
||||
<pathelement location="${scratchpad.output.dir}"/>
|
||||
</path>
|
||||
<path id="ooxml.classpath">
|
||||
<path refid="main.classpath"/>
|
||||
<path refid="scratchpad.classpath"/>
|
||||
<pathelement location="${scratchpad.output.dir}"/>
|
||||
<fileset dir="${ooxml.lib}">
|
||||
<include name="*.jar" />
|
||||
</fileset>
|
||||
</path>
|
||||
|
||||
<path id="test.classpath">
|
||||
<path refid="main.classpath"/>
|
||||
<pathelement location="${main.output.dir}"/>
|
||||
<pathelement location="${main.output.test.dir}"/>
|
||||
<pathelement location="${junit.jar1.dir}"/>
|
||||
</path>
|
||||
|
||||
<path id="test.ooxml.classpath">
|
||||
<path refid="ooxml.classpath"/>
|
||||
<pathelement location="${ooxml.output.dir}"/>
|
||||
<pathelement location="${ooxml.output.test.dir}"/>
|
||||
<pathelement location="${main.output.test.dir}"/> <!-- ooxml tests use some utilities from main tests -->
|
||||
<pathelement location="${junit.jar1.dir}"/>
|
||||
</path>
|
||||
|
||||
|
||||
<path id="examples.classpath">
|
||||
<path refid="main.classpath"/>
|
||||
<pathelement location="${main.output.dir}"/>
|
||||
<pathelement location="${scratchpad.output.dir}"/>
|
||||
</path>
|
||||
|
||||
|
||||
|
||||
@ -178,6 +262,8 @@ under the License.
|
||||
connection to the Internet.
|
||||
-Dtestcase=org.apache.poi.xxx.xxx : for the single-test target, specify
|
||||
the test to run
|
||||
-Dfilename=xxxx.xls : for the command line task targets, specify the
|
||||
file to run against
|
||||
|
||||
WARNING: This list is not exhaustive.
|
||||
</echo>
|
||||
@ -211,15 +297,19 @@ under the License.
|
||||
<mkdir dir="build"/>
|
||||
<mkdir dir="build/non-ant-classes"/>
|
||||
<mkdir dir="${main.output.dir}"/>
|
||||
<mkdir dir="${main14.output.dir}"/>
|
||||
<mkdir dir="${scratchpad.output.dir}"/>
|
||||
<mkdir dir="${contrib.output.dir}"/>
|
||||
<mkdir dir="${examples.output.dir}"/>
|
||||
<mkdir dir="${ooxml.output.dir}"/>
|
||||
<mkdir dir="${main.output.test.dir}"/>
|
||||
<mkdir dir="${contrib.output.test.dir}"/>
|
||||
<mkdir dir="${scratchpad.output.test.dir}"/>
|
||||
<mkdir dir="${ooxml.output.test.dir}"/>
|
||||
<mkdir dir="${main.reports.test}"/>
|
||||
<mkdir dir="${scratchpad.reports.test}"/>
|
||||
<mkdir dir="${contrib.reports.test}"/>
|
||||
<mkdir dir="${ooxml.reports.test}"/>
|
||||
<mkdir dir="${junit.report.dir}"/>
|
||||
<mkdir dir="${jdepend.report.dir}"/>
|
||||
<mkdir dir="${jdepend.report.out.dir}"/>
|
||||
@ -251,6 +341,12 @@ under the License.
|
||||
<available file="${main.jar1.dir}"/>
|
||||
<available file="${main.jar2.dir}"/>
|
||||
<available file="${junit.jar1.dir}"/>
|
||||
<available file="${ooxml.jar1.dir}"/>
|
||||
<available file="${ooxml.jar2.dir}"/>
|
||||
<available file="${ooxml.jar3.dir}"/>
|
||||
<available file="${ooxml.jar4.dir}"/>
|
||||
<available file="${ooxml.jar5.dir}"/>
|
||||
<available file="${ooxml.jar6.dir}"/>
|
||||
</and>
|
||||
<isset property="disconnected"/>
|
||||
</or>
|
||||
@ -262,10 +358,70 @@ under the License.
|
||||
<get src="${main.jar1.url}" dest="${main.jar1.dir}"/>
|
||||
<get src="${main.jar2.url}" dest="${main.jar2.dir}"/>
|
||||
<get src="${junit.jar1.url}" dest="${junit.jar1.dir}"/>
|
||||
|
||||
<get src="${ooxml.jar1.url}" dest="${ooxml.jar1.dir}"/>
|
||||
<get src="${ooxml.jar2.url}" dest="${ooxml.jar2.dir}"/>
|
||||
<get src="${ooxml.jar3.url}" dest="${ooxml.jar3.dir}"/>
|
||||
<get src="${ooxml.jar4.url}" dest="${ooxml.jar4.dir}"/>
|
||||
<get src="${ooxml.jar5.url}" dest="${ooxml.jar5.dir}"/>
|
||||
<get src="${ooxml.jar6.url}" dest="${ooxml.jar6.dir}"/>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="init, compile-main, compile-scratchpad,
|
||||
compile-contrib, compile-examples"
|
||||
<target name="check-ooxml-xsds">
|
||||
<condition property="ooxml-xsds.present">
|
||||
<or>
|
||||
<and>
|
||||
<available file="${ooxml.xsds.izip}"/>
|
||||
</and>
|
||||
<isset property="disconnected"/>
|
||||
</or>
|
||||
</condition>
|
||||
</target>
|
||||
<target name="fetch-ooxml-xsds" unless="ooxml-xsds.present"
|
||||
description="Fetches needed OOXML xsd files from the Internet">
|
||||
<get src="${ooxml.xsds.url}" dest="${ooxml.xsds.ozip}"/>
|
||||
<unzip src="${ooxml.xsds.ozip}" dest="${ooxml.lib}">
|
||||
<patternset>
|
||||
<include name="OfficeOpenXML-XMLSchema.zip" />
|
||||
</patternset>
|
||||
</unzip>
|
||||
</target>
|
||||
<target name="check-compiled-ooxml-xsds">
|
||||
<condition property="ooxml-compiled-xsds.present">
|
||||
<or>
|
||||
<and>
|
||||
<available file="${ooxml.xsds.jar}"/>
|
||||
</and>
|
||||
<isset property="disconnected"/>
|
||||
</or>
|
||||
</condition>
|
||||
</target>
|
||||
<target name="compile-ooxml-xsds" unless="ooxml-compiled-xsds.present"
|
||||
depends="check-jars,fetch-jars,check-ooxml-xsds,fetch-ooxml-xsds,check-compiled-ooxml-xsds"
|
||||
description="Unpacks the OOXML xsd files, and compiles them into XmlBeans">
|
||||
<taskdef name="xmlbean"
|
||||
classname="org.apache.xmlbeans.impl.tool.XMLBean"
|
||||
classpath="${ooxml.jar2.dir}:${ooxml.jar3.dir}:${ooxml.jar4.dir}:${ooxml.jar4.dir}:${ooxml.jar5.dir}" />
|
||||
|
||||
<unzip src="${ooxml.xsds.izip}" dest="build/ooxml-xsds/" />
|
||||
<!--
|
||||
schema="build/ooxml-xsds/"
|
||||
schema="build/ooxml-xsds/sml-workbook.xsd"
|
||||
-->
|
||||
<xmlbean
|
||||
schema="build/ooxml-xsds/"
|
||||
destfile="${ooxml.xsds.jar}"
|
||||
javasource="1.4"
|
||||
failonerror="true"
|
||||
fork="true"
|
||||
memoryMaximumSize="512m"
|
||||
>
|
||||
<classpath refid="ooxml.classpath"/>
|
||||
</xmlbean>
|
||||
</target>
|
||||
|
||||
<target name="compile" depends="init, compile-main,
|
||||
compile-scratchpad, compile-contrib, compile-examples"
|
||||
description="Compiles the POI main classes, scratchpad, contrib, and examples"/>
|
||||
|
||||
<target name="compile-main" depends="fail-unless-xslt-is-available">
|
||||
@ -273,8 +429,9 @@ under the License.
|
||||
<fileset dir="${main.resource1.dir}"/>
|
||||
</copy>
|
||||
<javac target="${jdk.version.class}" source="${jdk.version.source}"
|
||||
failonerror="true" destdir="${main.output.dir}" debug="on" fork="yes"
|
||||
srcdir="${main.src}">
|
||||
failonerror="true" destdir="${main.output.dir}" debug="on" fork="yes">
|
||||
<src path="${main.src}" />
|
||||
<src path="${interfaces.jdk15.src}" />
|
||||
<classpath refid="main.classpath"/>
|
||||
</javac>
|
||||
<javac target="${jdk.version.class}" source="${jdk.version.source}"
|
||||
@ -282,12 +439,24 @@ under the License.
|
||||
fork="yes" srcdir="${main.src.test}">
|
||||
<classpath>
|
||||
<path refid="main.classpath"/>
|
||||
<pathelement location="${main.output.dir}"/>
|
||||
<pathelement path="${main.output.dir}"/>
|
||||
<pathelement location="${junit.jar1.dir}"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="compile-main-14" depends="fail-unless-xslt-is-available">
|
||||
<copy todir="${main14.output.dir}">
|
||||
<fileset dir="${main.resource1.dir}"/>
|
||||
</copy>
|
||||
<javac target="${jdk14.version.class}" source="${jdk14.version.source}"
|
||||
failonerror="true" destdir="${main14.output.dir}" debug="on" fork="yes">
|
||||
<src path="${main.src}" />
|
||||
<src path="${interfaces.jdk14.src}" />
|
||||
<classpath refid="main.classpath"/>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="compile-scratchpad" depends="init,compile-main">
|
||||
<javac target="${jdk.version.class}" source="${jdk.version.source}"
|
||||
failonerror="true" destdir="${scratchpad.output.dir}" debug="on"
|
||||
@ -331,16 +500,41 @@ under the License.
|
||||
fork="yes" srcdir="${contrib.src.test}">
|
||||
<classpath>
|
||||
<path refid="contrib.classpath"/>
|
||||
<pathelement location="${contrib.output.dir}"/>
|
||||
<pathelement path="${contrib.output.dir}"/>
|
||||
<pathelement location="${junit.jar1.dir}"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="compile-examples" depends="init">
|
||||
<target name="compile-examples" depends="init,compile-ooxml">
|
||||
<javac target="${jdk.version.class}" source="${jdk.version.source}"
|
||||
destdir="${examples.output.dir}" debug="on" srcdir="${examples.src}">
|
||||
<classpath refid="examples.classpath"/>
|
||||
failonerror="true" destdir="${examples.output.dir}" debug="on" fork="yes"
|
||||
srcdir="${examples.src}">
|
||||
<classpath>
|
||||
<path refid="examples.classpath"/>
|
||||
<path refid="ooxml.classpath"/>
|
||||
<pathelement path="${ooxml.output.dir}"/>
|
||||
<pathelement location="${junit.jar1.dir}"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
<target name="compile-ooxml" depends="init, check-ooxml-xsds, fetch-ooxml-xsds, compile-ooxml-xsds, compile-main, compile-scratchpad">
|
||||
<!-- openxml4j requires java 1.5, so so must we, for now -->
|
||||
<javac target="1.5" source="1.5"
|
||||
destdir="${ooxml.output.dir}" debug="on" srcdir="${ooxml.src}">
|
||||
<classpath refid="ooxml.classpath"/>
|
||||
</javac>
|
||||
|
||||
<javac target="1.5" source="1.5"
|
||||
failonerror="true" destdir="${ooxml.output.test.dir}" debug="on"
|
||||
fork="yes" srcdir="${ooxml.src.test}">
|
||||
<classpath>
|
||||
<path refid="ooxml.classpath"/>
|
||||
<pathelement path="${ooxml.output.dir}"/>
|
||||
<pathelement path="${main.output.test.dir}"/>
|
||||
<pathelement location="${junit.jar1.dir}"/>
|
||||
</classpath>
|
||||
</javac>
|
||||
</target>
|
||||
|
||||
@ -361,29 +555,26 @@ under the License.
|
||||
<!-- Compile -->
|
||||
<javac target="${jdk.version.class}" source="${jdk.version.source}"
|
||||
failonerror="true" destdir="${main.output.dir}" debug="on" fork="yes"
|
||||
srcdir="${main.output.dir}" />
|
||||
<javac target="${jdk14.version.class}" source="${jdk14.version.source}"
|
||||
failonerror="true" destdir="${main14.output.dir}" debug="on" fork="yes"
|
||||
srcdir="${main.output.dir}" />
|
||||
|
||||
<!-- Tidy up -->
|
||||
<delete file="${version.java}" />
|
||||
</target>
|
||||
|
||||
<target name="test" depends="test-main,test-scratchpad,test-contrib"
|
||||
description="Tests main, contrib and scratchpad"/>
|
||||
<target name="test" depends="test-main,test-scratchpad,test-contrib,test-ooxml"
|
||||
description="Tests main, contrib, scratchpad and ooxml"/>
|
||||
|
||||
<target name="-test-main-check">
|
||||
<uptodate property="main.test.notRequired" targetfile="${main.testokfile}">
|
||||
<srcfiles dir="${main.src}"/>
|
||||
<srcfiles dir="${main.src.test}"/>
|
||||
<srcfiles dir="${ooxml.src}"/>
|
||||
</uptodate>
|
||||
</target>
|
||||
|
||||
<path id="test.classpath">
|
||||
<path refid="main.classpath"/>
|
||||
<pathelement location="${main.output.dir}"/>
|
||||
<pathelement location="${main.output.test.dir}"/>
|
||||
<pathelement location="${junit.jar1.dir}"/>
|
||||
</path>
|
||||
|
||||
<target name="test-main" unless="main.test.notRequired"
|
||||
depends="compile-main, -test-main-check, fail-unless-junit-is-available">
|
||||
<junit fork="no" printsummary="yes" haltonfailure="${halt.on.test.failure}"
|
||||
@ -469,6 +660,7 @@ under the License.
|
||||
<sysproperty key="HDGF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hdgf/data"/>
|
||||
<sysproperty key="HPBF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hpbf/data"/>
|
||||
<sysproperty key="POIFS.testdata.path" file="${main.src.test}/org/apache/poi/poifs/data"/>
|
||||
<sysproperty key="OOXML.testdata.path" file="${ooxml.src.test}/org/apache/poi/ooxml/data"/>
|
||||
<sysproperty key="java.awt.headless" value="true"/>
|
||||
<formatter type="plain" usefile="no"/>
|
||||
<formatter type="xml"/>
|
||||
@ -547,14 +739,14 @@ under the License.
|
||||
|
||||
<target name="single-scratchpad-test" depends="compile-scratchpad,-test-property-check" description="Runs a single test case specified with -Dtestcase=classname">
|
||||
<junit printsummary="yes" showoutput="true" filtertrace="no" haltonfailure="false" >
|
||||
<classpath refid="test.classpath"/>
|
||||
<classpath>
|
||||
<path refid="scratchpad.classpath"/>
|
||||
<pathelement location="${main.output.dir}"/>
|
||||
<pathelement location="${scratchpad.output.dir}"/>
|
||||
<pathelement location="${scratchpad.output.test.dir}"/>
|
||||
<pathelement location="${junit.jar1.dir}"/>
|
||||
</classpath>
|
||||
<classpath refid="test.classpath"/>
|
||||
<classpath>
|
||||
<path refid="scratchpad.classpath"/>
|
||||
<pathelement location="${main.output.dir}"/>
|
||||
<pathelement location="${scratchpad.output.dir}"/>
|
||||
<pathelement location="${scratchpad.output.test.dir}"/>
|
||||
<pathelement location="${junit.jar1.dir}"/>
|
||||
</classpath>
|
||||
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/>
|
||||
<sysproperty key="HPSF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hpsf/data"/>
|
||||
<sysproperty key="HWPF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hwpf/data"/>
|
||||
@ -564,7 +756,7 @@ under the License.
|
||||
<sysproperty key="HPBF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hpbf/data"/>
|
||||
<sysproperty key="POIFS.testdata.path" file="${main.src.test}/org/apache/poi/poifs/data"/>
|
||||
<sysproperty key="java.awt.headless" value="true"/>
|
||||
<sysproperty key="java.awt.headless" value="true"/>
|
||||
<sysproperty key="java.awt.headless" value="true"/>
|
||||
<formatter type="plain" usefile="no"/>
|
||||
<formatter type="xml"/>
|
||||
<test name="${testcase}"/>
|
||||
@ -607,6 +799,62 @@ under the License.
|
||||
<echo file="${contrib.testokfile}" append="false" message="testok"/>
|
||||
</target>
|
||||
|
||||
<target name="-test-ooxml-check">
|
||||
<uptodate property="ooxml.test.notRequired" targetfile="${ooxml.testokfile}">
|
||||
<srcfiles dir="${ooxml.src}"/>
|
||||
<srcfiles dir="${ooxml.src.test}"/>
|
||||
</uptodate>
|
||||
</target>
|
||||
|
||||
<target name="test-ooxml" depends="compile-main,compile-ooxml,-test-ooxml-check" unless="ooxml.test.notRequired">
|
||||
<junit printsummary="yes" fork="no" haltonfailure="${halt.on.test.failure}" failureproperty="ooxml.test.failed">
|
||||
<classpath refid="test.ooxml.classpath" />
|
||||
<sysproperty key="POIFS.testdata.path" file="${main.src.test}/org/apache/poi/poifs/data"/>
|
||||
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/>
|
||||
<sysproperty key="HWPF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hwpf/data"/>
|
||||
<sysproperty key="HSLF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hslf/data"/>
|
||||
<sysproperty key="HDGF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hdgf/data"/>
|
||||
<sysproperty key="OOXML.testdata.path" file="${ooxml.src.test}/org/apache/poi/ooxml/data"/>
|
||||
<sysproperty key="java.awt.headless" value="true"/>
|
||||
<formatter type="plain"/>
|
||||
<formatter type="xml"/>
|
||||
<batchtest todir="${ooxml.reports.test}">
|
||||
<fileset dir="${ooxml.src.test}">
|
||||
<include name="**/Test*.java"/>
|
||||
<exclude name="**/All*Tests.java"/>
|
||||
</fileset>
|
||||
</batchtest>
|
||||
</junit>
|
||||
<delete file="${ooxml.testokfile}"/>
|
||||
<antcall target="-test-ooxml-write-testfile"/>
|
||||
</target>
|
||||
|
||||
<target name="-test-ooxml-write-testfile" unless="ooxml.test.failed">
|
||||
<echo file="${ooxml.testokfile}" append="false" message="testok"/>
|
||||
</target>
|
||||
|
||||
<target name="single-test-ooxml" depends="-test-property-check,compile-main,compile-ooxml" description="Runs a single ooxml test case specified with -Dtestcase=classname">
|
||||
<junit printsummary="yes" showoutput="true" filtertrace="no" haltonfailure="false" >
|
||||
<classpath>
|
||||
<path refid="ooxml.classpath"/>
|
||||
<pathelement location="${main.output.dir}"/>
|
||||
<pathelement location="${ooxml.output.dir}"/>
|
||||
<pathelement location="${ooxml.output.test.dir}"/>
|
||||
<pathelement location="${junit.jar1.dir}"/>
|
||||
</classpath>
|
||||
<sysproperty key="HSSF.testdata.path" file="${main.src.test}/org/apache/poi/hssf/data"/>
|
||||
<sysproperty key="HPSF.testdata.path" file="${main.src.test}/org/apache/poi/hpsf/data"/>
|
||||
<sysproperty key="HSLF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hslf/data"/>
|
||||
<sysproperty key="HWPF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hwpf/data"/>
|
||||
<sysproperty key="HSMF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hsmf/data"/>
|
||||
<sysproperty key="HDGF.testdata.path" file="${scratchpad.src.test}/org/apache/poi/hdgf/data"/>
|
||||
<sysproperty key="java.awt.headless" value="true"/>
|
||||
<formatter type="plain" usefile="no"/>
|
||||
<formatter type="xml"/>
|
||||
<test name="${testcase}"/>
|
||||
</junit>
|
||||
</target>
|
||||
|
||||
<target name="-check-docs">
|
||||
<uptodate property="main.docs.notRequired" targetfile="${build.site}/index.html">
|
||||
<srcfiles dir="${build.site.src}"/>
|
||||
@ -752,7 +1000,7 @@ FORREST_HOME environment variable!</echo>
|
||||
<packageset dir="${contrib.src}" defaultexcludes="yes">
|
||||
<include name="org/apache/poi/**"/>
|
||||
</packageset>
|
||||
<packageset dir="${examples.src}" defaultexcludes="yes">
|
||||
<packageset dir="${ooxml.src}" defaultexcludes="yes">
|
||||
<include name="org/apache/poi/**"/>
|
||||
</packageset>
|
||||
|
||||
@ -851,7 +1099,7 @@ FORREST_HOME environment variable!</echo>
|
||||
description="Generates POI's website's contents"/>
|
||||
|
||||
|
||||
<target name="maven-dist" depends="jar" description="Builds the POM files for a maven distribution, and copies these and the jars to the appropriate locations">
|
||||
<target name="maven-dist" depends="jar,jar-ooxml" description="Builds the POM files for a maven distribution, and copies these and the jars to the appropriate locations">
|
||||
<!-- Copy the jar files into the maven jar directory -->
|
||||
<!-- Same jars as for the main release, only lacking the datestamp -->
|
||||
<copy
|
||||
@ -863,6 +1111,9 @@ FORREST_HOME environment variable!</echo>
|
||||
<copy
|
||||
file="${dist.dir}/${jar.name}-scratchpad-${version.id}-${DSTAMP}.jar"
|
||||
tofile="${mavendist.oap.dir}/jars/${jar.name}-scratchpad-${version.id}.jar" />
|
||||
<copy
|
||||
file="${dist.dir}/${jar.name}-ooxml-${version.id}-${DSTAMP}.jar"
|
||||
tofile="${mavendist.oap.dir}/jars/${jar.name}-ooxml-${version.id}.jar" />
|
||||
|
||||
<!-- TODO: Decide about source jars, and copy them if we have some -->
|
||||
|
||||
@ -918,6 +1169,22 @@ FORREST_HOME environment variable!</echo>
|
||||
</tokenfilter>
|
||||
</filterchain>
|
||||
</copy>
|
||||
<!-- And the ooxml pom -->
|
||||
<copy
|
||||
file="maven/poi-ooxml.pom"
|
||||
tofile="${mavendist.oap.dir}/poms/${jar.name}-ooxml-${version.id}.pom"
|
||||
>
|
||||
<filterchain>
|
||||
<replacetokens>
|
||||
<token key="VERSION" value="${version.id}" />
|
||||
<token key="ARTIFICAT" value="poi-ooxml" />
|
||||
</replacetokens>
|
||||
<tokenfilter>
|
||||
<replaceregex pattern="..-- START_NON_MAIN_DEPENDENCY --." replace="" flags="s"/>
|
||||
<replaceregex pattern="..-- END_NON_MAIN_DEPENDENCY --." replace="" flags="s"/>
|
||||
</tokenfilter>
|
||||
</filterchain>
|
||||
</copy>
|
||||
|
||||
<!-- Build the poi => org.apache.poi redirect poms -->
|
||||
<!-- Copy from the base file, substituting in the version+artifact -->
|
||||
@ -952,7 +1219,45 @@ FORREST_HOME environment variable!</echo>
|
||||
<!-- And that's it for maven -->
|
||||
</target>
|
||||
|
||||
<target name="jar" depends="compile,compile-version" description="Creates jar files for distribution">
|
||||
<target name="maven-ooxml-dependencies" description="Builds the POM files for OpenXml4J and compiled XmlBeans generated from the Ecma supplied xsds">
|
||||
<!-- OpenXml4J -->
|
||||
<copy file="${ooxml.jar6.dir}" tofile="${mavendist.ooxml.dir}/org.openxml4j/jars/${maven.openxml4j.jar}" />
|
||||
<copy file="maven/openxml4j.pom" tofile="${mavendist.ooxml.dir}/org.openxml4j/poms/openxml4j-${maven.openxml4j.version.id}.pom">
|
||||
<filterchain>
|
||||
<replacetokens>
|
||||
<token key="VERSION" value="${maven.openxml4j.version.id}" />
|
||||
</replacetokens>
|
||||
</filterchain>
|
||||
</copy>
|
||||
|
||||
<!-- ooxml-schemas -->
|
||||
<copy file="${ooxml.xsds.jar}" tofile="${mavendist.ooxml.dir}/org.apache.poi/jars/${maven.ooxml.xsds.jar}" />
|
||||
<copy file="maven/ooxml-schemas.pom" tofile="${mavendist.ooxml.dir}/org.apache.poi/poms/ooxml-schemas-${maven.ooxml.xsds.version.id}.pom">
|
||||
<filterchain>
|
||||
<replacetokens>
|
||||
<token key="VERSION" value="${maven.ooxml.xsds.version.id}" />
|
||||
</replacetokens>
|
||||
</filterchain>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<target name="jar-14" depends="compile-main-14, compile-version" description="Creates the jdk 1.4 only jar file">
|
||||
<jar destfile="${dist.dir}/${jar.name}-jdk14-${version.id}-${DSTAMP}.jar">
|
||||
<fileset dir="${main14.output.dir}" />
|
||||
<fileset dir="legal/" />
|
||||
<manifest>
|
||||
<attribute name="Built-By" value="${user.name}"/>
|
||||
<attribute name="Specification-Title" value="Apache POI"/>
|
||||
<attribute name="Specification-Version" value="${version.id}-${DSTAMP}"/>
|
||||
<attribute name="Specification-Vendor" value="Apache"/>
|
||||
<attribute name="Implementation-Title" value="Apache POI for JDK 1.3/1.4"/>
|
||||
<attribute name="Implementation-Version" value="${version.id}-${DSTAMP}"/>
|
||||
<attribute name="Implementation-Vendor" value="Apache"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="jar" depends="compile, compile-version, jar-ooxml" description="Creates jar files for distribution">
|
||||
<jar destfile="${dist.dir}/${jar.name}-${version.id}-${DSTAMP}.jar">
|
||||
<fileset dir="${main.output.dir}" />
|
||||
<fileset dir="legal/" />
|
||||
@ -993,8 +1298,23 @@ FORREST_HOME environment variable!</echo>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
<target name="jar-ooxml" depends="compile-ooxml" description="Creates the ooxml jar files for distribution">
|
||||
<jar destfile="${dist.dir}/${jar.name}-ooxml-${version.id}-${DSTAMP}.jar">
|
||||
<fileset dir="${ooxml.output.dir}" />
|
||||
<fileset dir="legal/" />
|
||||
<manifest>
|
||||
<attribute name="Built-By" value="${user.name}"/>
|
||||
<attribute name="Specification-Title" value="Apache POI"/>
|
||||
<attribute name="Specification-Version" value="${version.id}-${DSTAMP}"/>
|
||||
<attribute name="Specification-Vendor" value="Apache"/>
|
||||
<attribute name="Implementation-Title" value="Apache POI"/>
|
||||
<attribute name="Implementation-Version" value="${version.id}-${DSTAMP}"/>
|
||||
<attribute name="Implementation-Vendor" value="Apache"/>
|
||||
</manifest>
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="dist" depends="clean, fail-unless-tools-are-available, compile, site, jar"
|
||||
<target name="dist" depends="clean, fail-unless-tools-are-available, compile, site, jar, jar-ooxml"
|
||||
description="Creates the entire distribution into build/dist, from scratch">
|
||||
|
||||
<property name="zipdir" value="${jar.name}-${version.id}" />
|
||||
@ -1002,10 +1322,15 @@ FORREST_HOME environment variable!</echo>
|
||||
<zip destfile="${dist.dir}/${jar.name}-bin-${version.id}-${DSTAMP}.zip">
|
||||
<zipfileset dir="legal/" prefix="${zipdir}" />
|
||||
<zipfileset dir="lib/" prefix="${zipdir}/lib" />
|
||||
<zipfileset dir="ooxml-lib/" prefix="${zipdir}/ooxml-lib">
|
||||
<exclude name="*.zip"/>
|
||||
</zipfileset>
|
||||
<zipfileset dir="${build.site}" prefix="${zipdir}/docs"/>
|
||||
<zipfileset file="${dist.dir}/${jar.name}-${version.id}-${DSTAMP}.jar" prefix="${zipdir}" />
|
||||
<zipfileset file="${dist.dir}/${jar.name}-jdk14-${version.id}-${DSTAMP}.jar" prefix="${zipdir}" />
|
||||
<zipfileset file="${dist.dir}/${jar.name}-contrib-${version.id}-${DSTAMP}.jar" prefix="${zipdir}" />
|
||||
<zipfileset file="${dist.dir}/${jar.name}-scratchpad-${version.id}-${DSTAMP}.jar" prefix="${zipdir}" />
|
||||
<zipfileset file="${dist.dir}/${jar.name}-ooxml-${version.id}-${DSTAMP}.jar" prefix="${zipdir}" />
|
||||
</zip>
|
||||
|
||||
<zip destfile="${dist.dir}/${jar.name}-src-${version.id}-${DSTAMP}.zip">
|
||||
@ -1028,10 +1353,15 @@ FORREST_HOME environment variable!</echo>
|
||||
compression="gzip">
|
||||
<tarfileset dir="legal/" prefix="${zipdir}" />
|
||||
<tarfileset dir="lib/" prefix="${zipdir}/lib" />
|
||||
<tarfileset dir="ooxml-lib/" prefix="${zipdir}/ooxml-lib">
|
||||
<exclude name="*.zip"/>
|
||||
</tarfileset>
|
||||
<tarfileset dir="${build.site}" prefix="${zipdir}/docs"/>
|
||||
<tarfileset file="${dist.dir}/${jar.name}-${version.id}-${DSTAMP}.jar" prefix="${zipdir}" />
|
||||
<tarfileset file="${dist.dir}/${jar.name}-jdk14-${version.id}-${DSTAMP}.jar" prefix="${zipdir}" />
|
||||
<tarfileset file="${dist.dir}/${jar.name}-contrib-${version.id}-${DSTAMP}.jar" prefix="${zipdir}" />
|
||||
<tarfileset file="${dist.dir}/${jar.name}-scratchpad-${version.id}-${DSTAMP}.jar" prefix="${zipdir}" />
|
||||
<tarfileset file="${dist.dir}/${jar.name}-ooxml-${version.id}-${DSTAMP}.jar" prefix="${zipdir}" />
|
||||
</tar>
|
||||
|
||||
<tar destfile="${dist.dir}/${jar.name}-src-${version.id}-${DSTAMP}.tar.gz"
|
||||
@ -1192,6 +1522,35 @@ FORREST_HOME environment variable!</echo>
|
||||
style="jdepend.xsl"/>
|
||||
</target>
|
||||
|
||||
|
||||
<target name="-require-filename" description="Ensure -Dfilename=... was given">
|
||||
<fail unless="filename" message="A filename must be supplied with -Dfilename=, eg -Dfilename=test.xls" />
|
||||
</target>
|
||||
|
||||
<!-- These tasks make it easy to run our command line tools, -->
|
||||
<!-- without you needing to worry about classpaths etc -->
|
||||
<target name="POIFSViewer" depends="compile-main,-require-filename"
|
||||
description="Runs poifs.dev.POIFSViewer against the supplied file">
|
||||
<java classname="org.apache.poi.poifs.dev.POIFSViewer">
|
||||
<arg line="${filename}" />
|
||||
<classpath refid="test.classpath"/>
|
||||
</java>
|
||||
</target>
|
||||
<target name="OOXMLLister" depends="compile-ooxml,-require-filename"
|
||||
description="Runs dev.OOXMLLister against the supplied file">
|
||||
<java classname="org.apache.poi.dev.OOXMLLister">
|
||||
<arg line="${filename}" />
|
||||
<classpath refid="test.ooxml.classpath"/>
|
||||
</java>
|
||||
</target>
|
||||
<target name="BiffViewer" depends="compile-main,-require-filename"
|
||||
description="Runs hssf.dev.BiffViewer against the supplied file">
|
||||
<java classname="org.apache.poi.hssf.dev.BiffViewer">
|
||||
<arg line="${filename}" />
|
||||
<classpath refid="test.classpath"/>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
</project>
|
||||
|
||||
<!-- Keep this comment at the end of the file
|
||||
|
@ -22,8 +22,8 @@ For those wishing to avoid this component, the HDGF part of the POI
|
||||
See http://www.gnome.ru/projects/vsdump_en.html
|
||||
|
||||
|
||||
The Office Open XML experimental support had additional dependencies,
|
||||
with their own licensing:
|
||||
The Office Open XML support had additional dependencies, with their
|
||||
own licensing:
|
||||
* XML Beans - http://xmlbeans.apache.org/
|
||||
Apache Licence Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0
|
||||
* DOM4J - http://www.dom4j.org/
|
||||
|
70
maven/ooxml-schemas.pom
Executable file
70
maven/ooxml-schemas.pom
Executable file
@ -0,0 +1,70 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
|
||||
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.
|
||||
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>ooxml-schemas</artifactId>
|
||||
<version>@VERSION@</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>OOXML schemas</name>
|
||||
<description>XmlBeans generated from the Ecma supplied xsds:
|
||||
http://www.ecma-international.org/publications/files/ECMA-ST/Office%20Open%20XML%20Part%204%20(DOCX).zip</description>
|
||||
<url>http://poi.apache.org/</url>
|
||||
|
||||
<mailingLists>
|
||||
<mailingList>
|
||||
<name>POI Users List</name>
|
||||
<subscribe>user-subscribe@poi.apache.org</subscribe>
|
||||
<unsubscribe>user-unsubscribe@poi.apache.org</unsubscribe>
|
||||
<archive>http://mail-archives.apache.org/mod_mbox/poi-user/</archive>
|
||||
</mailingList>
|
||||
<mailingList>
|
||||
<name>POI Developer List</name>
|
||||
<subscribe>dev-subscribe@poi.apache.org</subscribe>
|
||||
<unsubscribe>dev-unsubscribe@poi.apache.org</unsubscribe>
|
||||
<archive>http://mail-archives.apache.org/mod_mbox/poi-dev/</archive>
|
||||
</mailingList>
|
||||
</mailingLists>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<organization>
|
||||
<name>Apache Software Foundation</name>
|
||||
<url>http://www.apache.org/</url>
|
||||
</organization>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.xmlbeans</groupId>
|
||||
<artifactId>xmlbeans</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
70
maven/openxml4j.pom
Executable file
70
maven/openxml4j.pom
Executable file
@ -0,0 +1,70 @@
|
||||
<?xml version="1.0"?>
|
||||
<!--
|
||||
|
||||
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.
|
||||
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.openxml4j</groupId>
|
||||
<artifactId>openxml4j</artifactId>
|
||||
<version>@VERSION@</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>OpenXML4J</name>
|
||||
<url>http://openxml4j.org/</url>
|
||||
<description>Office Open XML File Format library for Java</description>
|
||||
|
||||
<mailingLists>
|
||||
<mailingList>
|
||||
<name>OpenXML4J Users List</name>
|
||||
<archive>http://sourceforge.net/mailarchive/forum.php?forum_name=openxml4j-users</archive>
|
||||
</mailingList>
|
||||
<mailingList>
|
||||
<name>OpenXML4J Developer List</name>
|
||||
<archive>http://sourceforge.net/mailarchive/forum.php?forum_name=openxml4j-devs</archive>
|
||||
</mailingList>
|
||||
</mailingLists>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<organization>
|
||||
<name>OpenXML4J</name>
|
||||
<url>http://www.openxml4j.org/</url>
|
||||
</organization>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>dom4j</groupId>
|
||||
<artifactId>dom4j</artifactId>
|
||||
<version>1.6.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.8</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
86
maven/poi-ooxml.pom
Executable file
86
maven/poi-ooxml.pom
Executable file
@ -0,0 +1,86 @@
|
||||
:tab<?xml version="1.0"?>
|
||||
<!--
|
||||
|
||||
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.
|
||||
|
||||
-->
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>@ARTIFICAT@</artifactId>
|
||||
<version>@VERSION@</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Apache POI</name>
|
||||
<url>http://poi.apache.org/</url>
|
||||
<description>Apache POI - Java API To Access Microsoft Format Files</description>
|
||||
|
||||
<mailingLists>
|
||||
<mailingList>
|
||||
<name>OpenXML4J Users List</name>
|
||||
<archive>http://sourceforge.net/mailarchive/forum.php?forum_name=openxml4j-users</archive>
|
||||
</mailingList>
|
||||
<mailingList>
|
||||
<name>OpenXML4J Developer List</name>
|
||||
<archive>http://sourceforge.net/mailarchive/forum.php?forum_name=openxml4j-devs</archive>
|
||||
</mailingList>
|
||||
<mailingList>
|
||||
<name>POI Developer List</name>
|
||||
<subscribe>dev-subscribe@poi.apache.org</subscribe>
|
||||
<unsubscribe>dev-unsubscribe@poi.apache.org</unsubscribe>
|
||||
<archive>http://mail-archives.apache.org/mod_mbox/poi-dev/</archive>
|
||||
</mailingList>
|
||||
</mailingLists>
|
||||
|
||||
<licenses>
|
||||
<license>
|
||||
<name>The Apache Software License, Version 2.0</name>
|
||||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
|
||||
<distribution>repo</distribution>
|
||||
</license>
|
||||
</licenses>
|
||||
|
||||
<organization>
|
||||
<name>Apache Software Foundation</name>
|
||||
<url>http://www.apache.org/</url>
|
||||
</organization>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.xmlbeans</groupId>
|
||||
<artifactId>xmlbeans</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>poi</artifactId>
|
||||
<version>@VERSION@</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>openxml4j</artifactId>
|
||||
<version>@VERSION@</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.poi</groupId>
|
||||
<artifactId>ooxml-schemas</artifactId>
|
||||
<version>@VERSION@</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -21,8 +21,8 @@ import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.hssf.util.CellRangeAddress;
|
||||
import org.apache.poi.hssf.util.Region;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.Region;
|
||||
|
||||
/**
|
||||
* Various utility functions that make working with a region of cells easier.
|
||||
|
@ -35,10 +35,10 @@
|
||||
<menu label="Project">
|
||||
<menu-item label="Overview" href="overview.html"/>
|
||||
<menu-item label="POIFS" href="poifs/index.html"/>
|
||||
<menu-item label="HSSF" href="hssf/index.html"/>
|
||||
<menu-item label="HSSF+XSSF" href="spreadsheet/index.html"/>
|
||||
<menu-item label="HWPF" href="hwpf/index.html"/>
|
||||
<menu-item label="HPSF" href="hpsf/index.html"/>
|
||||
<menu-item label="HSLF" href="hslf/index.html"/>
|
||||
<menu-item label="HSLF" href="slideshow/index.html"/>
|
||||
<menu-item label="HSMF" href="hsmf/index.html"/>
|
||||
<menu-item label="HDGF" href="hdgf/index.html"/>
|
||||
<menu-item label="HPBF" href="hpbf/index.html"/>
|
||||
|
@ -132,7 +132,7 @@ format,
|
||||
reports financial statistical data to Excel format using the
|
||||
<link href="http://poi.apache.org/">Apache POI</link>
|
||||
project's
|
||||
<link href="hssf/">
|
||||
<link href="spreadsheet/">
|
||||
HSSF</link> API. The system is based on Oracle JServer and
|
||||
utilizes a Java stored procedure that outputs to XLS format
|
||||
using the HSSF API. - Arian Lashkov (alaskov at lbank.lt)
|
||||
|
@ -46,6 +46,34 @@
|
||||
<action dev="POI-DEVELOPERS" type="fix">45778 - fixed ObjRecord to read ftLbsData properly</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">46053 - fixed evaluation cache dependency analysis when changing blank cells</action>
|
||||
</release>
|
||||
<release version="3.5-beta3" date="2008-09-26">
|
||||
<action dev="POI-DEVELOPERS" type="fix">45518 - Fix up ColumnHelper to output valid col tags, by making 1 based and 0 based bits clearer, and using the right ones</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">45676 - Handle very long cells in the XSSF EventUserModel example</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Initial ExtractorFactory support for building TextExtractors for embeded documents</action>
|
||||
</release>
|
||||
<release version="3.5-beta2" date="2008-08-20">
|
||||
<action dev="POI-DEVELOPERS" type="add">Support stripping XSSF header and footer fields (eg page number) out of header and footer text if required</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Add POIXMLPropertiesTextExtractor, which provides to the OOXML file formats a similar function to HPSF's HPSFPropertiesExtractor</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45539 - Improve XWPFWordExtractor to extract headers and footers</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">Improve how XWPF handles paragraph text</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Support in XWPF handles headers and footers</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45592 - Improve XWPF text extraction to include tables always, and picture text where possible</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45545 - Improve XSLF usermodel support, and include XSLF comments in extracted text</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45540 - Fix XSSF header and footer support, and include headers and footers in the output of XSSFExcelExtractor</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45431 - Support for .xlsm files, sufficient for simple files to be loaded by excel without warning</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">New class org.apache.poi.hssf.record.RecordFormatException, which DDF uses instead of the HSSF version, and the HSSF version inherits from</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45431 - Partial support for .xlm files. Not quite enough for excel to load them though</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">45430 - Correct named range sheet reporting when no local sheet id is given in the xml</action>
|
||||
</release>
|
||||
<release version="3.5-beta1" date="2008-07-18">
|
||||
<action dev="POI-DEVELOPERS" type="add">45018 - Support for fetching embeded documents from within an OOXML file</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Port support for setting a policy on missing / blank cells when fetching, to XSSF too</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Common text extraction factory, which returns the correct POITextExtractor for the supplied data</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Text Extraction support for the new OOXML files (.xlsx, .docx and .pptx)</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Initial support for processing OOXML Excel files (.xlsx), both directly through XSSF, and also through the new common UserModel</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Created a common interface for handling PowerPoint files, irrespective of if they are .ppt or .pptx</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
|
||||
</release>
|
||||
<release version="3.2-FINAL" date="2008-10-19">
|
||||
<action dev="POI-DEVELOPERS" type="fix">45866 - allowed for change of unicode compression across Continue records</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">45964 - support for link formulas in Text Objects</action>
|
||||
|
@ -181,7 +181,7 @@ System.out.println("Core POI came from " + path);
|
||||
</question>
|
||||
<answer>
|
||||
<p>
|
||||
Yes. You first need to get a HSSFDataFormat object from the workbook and call getFormat with the desired format. Some examples are <link href="hssf/quick-guide.html#DataFormats">here</link>.
|
||||
Yes. You first need to get a HSSFDataFormat object from the workbook and call getFormat with the desired format. Some examples are <link href="spreadsheet/quick-guide.html#DataFormats">here</link>.
|
||||
</p>
|
||||
</answer>
|
||||
</faq>
|
||||
|
@ -31,6 +31,19 @@
|
||||
</header>
|
||||
|
||||
<body>
|
||||
<section><title>POI 3.5.1 beta 1, and Office Open XML Support (2008-07-18)</title>
|
||||
<p>We are currently working to support the new Office Open XML
|
||||
file formats, such as XLSX and PPTX, which were introduced in
|
||||
Office 2007.</p>
|
||||
<p>Development for this is in a svn branch, but we are please to
|
||||
announce our first preview release containing this support.
|
||||
Users interested in the OOXML support should download the
|
||||
<link href="http://www.apache.org/dyn/closer.cgi/poi/dev/">POI 3.5.1 beta 1</link>
|
||||
the source and binaries from their
|
||||
<link href="http://www.apache.org/dyn/closer.cgi/poi/dev/">local mirror</link>.
|
||||
People interested should also follow the
|
||||
<link href="mailinglists.html">dev list</link> to track progress.</p>
|
||||
</section>
|
||||
<section><title>POI 3.2-FINAL Released (2008-10-19)</title>
|
||||
<p>
|
||||
The POI team is pleased to announce the release of 3.2 FINAL, the latest release of Apache POI.
|
||||
@ -46,47 +59,27 @@
|
||||
under Group ID "org.apache.poi" and Version "3.2-FINAL".
|
||||
</p>
|
||||
</section>
|
||||
<section><title>Office Open XML Support - POI 3.5</title>
|
||||
<p>We are currently working to support the new Office Open XML
|
||||
file formats, such as XLSX and PPTX, which were introduced in
|
||||
Office 2007.</p>
|
||||
<p>Support for these is currently only available in the 3.5 series,
|
||||
which is in a svn branch (not trunk). POI 3.5.1 beta 3 was released
|
||||
in October 2008, and is our first release including the OOXML support.
|
||||
It is available to download from your favourite
|
||||
<link href="http://www.apache.org/dyn/closer.cgi/poi/dev/">local mirror</link>.
|
||||
</p>
|
||||
<p>Please note that the documentation on the website is for the
|
||||
3.2 series of POI. Documentation on the new OOXML support is
|
||||
included in the 3.5.1 beta 3 distribution.</p>
|
||||
</section>
|
||||
|
||||
<section><title>Purpose</title>
|
||||
<p>
|
||||
The POI project consists of APIs for manipulating various file formats
|
||||
based upon Microsoft's OLE 2 Compound Document format using pure Java.
|
||||
In short, you can read and write MS Excel files using Java. Soon,
|
||||
you'll be able to read and write Word, PowerPoint and Visio files
|
||||
using Java. POI is your Java Excel solution as well as your Java
|
||||
Word solution. However, we have a complete API for porting other OLE
|
||||
2 Compound Document formats, and welcome others to participate.
|
||||
based upon Microsoft's OLE 2 Compound Document format, and Office OpenXML format, using
|
||||
pure Java. In short, you can read and write MS Excel files using Java. In addition,
|
||||
you can read and write MS Word and MS PowerPoint files using Java. POI is your Java Excel
|
||||
solution (for Excel 97-2007). However, we have a complete API for porting other OLE 2
|
||||
Compound Document formats and welcome others to participate.
|
||||
</p>
|
||||
<p>
|
||||
OLE 2 Compound Document Format based files include most Microsoft Office
|
||||
files such as XLS and DOC as well as MFC serialization API based file
|
||||
formats.
|
||||
files such as XLS and DOC as well as MFC serialization API based file formats.
|
||||
</p>
|
||||
<p>
|
||||
At this time, none of our releases support the new Office Open XML
|
||||
file formats, such as .xlsx or .docx. Work to support these is in
|
||||
progress, and people interested should follow the
|
||||
<link href="mailinglists.html">dev list</link>. We expect this
|
||||
support to make it into a full release by the summer.
|
||||
Office OpenXML Format based files include the new (2007+) xml based file formats,
|
||||
including Microsoft office files such as XLSX, DOCX and PPTX.
|
||||
</p>
|
||||
<p>
|
||||
As a general policy, we try to collaborate as much as possible
|
||||
with other projects to provide this functionality. Examples
|
||||
include: <link href="http://xml.apache.org/cocoon">Cocoon</link> for
|
||||
As a general policy we try to collaborate as much as possible with other projects to
|
||||
provide this functionality. Examples include: <link href="http://xml.apache.org/cocoon">Cocoon</link> for
|
||||
which there are serializers for HSSF;
|
||||
<link href="http://www.openoffice.org">Open Office.org</link> with whom we collaborate in documenting the
|
||||
XLS format; and <link href="http://lucene.apache.org/">Lucene</link>
|
||||
@ -98,7 +91,7 @@
|
||||
We'll tackle this on a component level. POI refers to the whole project.
|
||||
</p>
|
||||
<p>
|
||||
So why should you use POIFS or HSSF?
|
||||
So why should you use POIFS, HSSF or XSSF?
|
||||
</p>
|
||||
<p>
|
||||
You'd use POIFS if you had a document written in OLE 2 Compound Document Format, probably written using
|
||||
@ -107,8 +100,10 @@
|
||||
we say that POIFS is the most complete and correct implementation of this file format to date!
|
||||
</p>
|
||||
<p>
|
||||
You'd use HSSF if you needed to read, write or modify an Excel file
|
||||
using Java (XLS).
|
||||
You'd use HSSF if you needed to read or write an Excel file using Java (XLS). You'd use
|
||||
XSSF if you need to read or write an OOXML Excel file using Java (XLSX). The combined
|
||||
SS interface allows you to easily read and write all kinds of Excel files (XLS and XLSX)
|
||||
using Java.
|
||||
</p>
|
||||
</section>
|
||||
</section>
|
||||
@ -124,12 +119,12 @@
|
||||
pure Java. It supports both read and write functionality. All of our components ultimately rely on it by
|
||||
definition. Please see <link href="./poifs/index.html">the POIFS project page</link> for more information.</p>
|
||||
</section>
|
||||
<section><title>HSSF for Excel Documents</title>
|
||||
<p>HSSF is our port of the Microsoft Excel 97(-2003) file
|
||||
format (BIFF8) to pure Java. It supports read and write
|
||||
capability. (Support for Excel 2007 .xlsx files is in progress).
|
||||
Please see <link href="./hssf/index.html">the HSSF project
|
||||
page</link> for more information.</p>
|
||||
<section><title>HSSF and XSSF for Excel Documents</title>
|
||||
<p>HSSF is our port of the Microsoft Excel 97(-2007) file format (BIFF8) to pure
|
||||
Java. XSSF is our port of the Microsoft Excel XML (2007+) file format (OOXML) to
|
||||
pure Java. They both supports read and write capability. Please see
|
||||
<link href="./spreadsheet/index.html">the HSSF+XSSF project page</link> for more
|
||||
information.</p>
|
||||
</section>
|
||||
<section><title>HWPF for Word Documents</title>
|
||||
<p>HWPF is our port of the Microsoft Word 97 file format to pure
|
||||
@ -143,7 +138,7 @@
|
||||
<section><title>HSLF for PowerPoint Documents</title>
|
||||
<p>HSLF is our port of the Microsoft PowerPoint 97(-2003) file format to pure
|
||||
Java. It supports read and write capabilities. Please see <link
|
||||
href="./hslf/index.html">the HSLF project page for more
|
||||
href="./slideshow/index.html">the HSLF project page for more
|
||||
information</link>.</p>
|
||||
</section>
|
||||
<section><title>HPSF for Document Properties</title>
|
||||
|
@ -48,10 +48,11 @@
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<section><title>HSSF</title>
|
||||
<section><title>HSSF and XSSF</title>
|
||||
<p>
|
||||
<link href="hssf/index.html">HSSF</link> is the set of APIs
|
||||
for reading and writing Microsoft Excel 97(-XP) spreadsheets using (only) Java.
|
||||
<link href="spreadsheet/index.html">HSSF and XSSF</link> are
|
||||
the set of APIs for reading and writing Microsoft Excel
|
||||
97-2007 and OOXML spreadsheets using (only) Java.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
@ -64,7 +65,7 @@
|
||||
|
||||
<section><title>HSLF</title>
|
||||
<p>
|
||||
<link href="hslf/index.html">HSLF</link> is the set of APIs
|
||||
<link href="slideshow/index.html">HSLF</link> is the set of APIs
|
||||
for reading and writing Microsoft PowerPoint 97(-XP) documents using (only) Java.
|
||||
</p>
|
||||
</section>
|
||||
|
@ -110,7 +110,7 @@
|
||||
h.write(File.new("test.xls","w"))
|
||||
</source>
|
||||
<p> The <em>tc_base_tests.rb</em> file in the <em>tests</em> sub directory of the source distribution
|
||||
contains examples of simple uses of the API. The <link href="hssf/quick-guide.html">quick quide </link> is the best
|
||||
contains examples of simple uses of the API. The <link href="spreadsheet/quick-guide.html">quick quide </link> is the best
|
||||
place to learn HSSF API use. (Note however that none of the Drawing features are implemented in the Ruby binding.)
|
||||
See also the <link href="apidocs/overview-summary.html">POI API documentation</link> for more details.
|
||||
</p>
|
||||
|
@ -62,7 +62,7 @@
|
||||
<p>PowerPoint does not normally store embeded files
|
||||
in the OLE2 layer. Instead, they are held within records
|
||||
of the main PowerPoint file.
|
||||
<br/>See the <link href="./../hslf/how-to-shapes.html#OLE">HSLF Tutorial</link>
|
||||
<br/>See the <link href="./../slideshow/how-to-shapes.html#OLE">HSLF Tutorial</link>
|
||||
for how to retrieve embedded OLE objects from a presentation</p>
|
||||
</section>
|
||||
</section>
|
||||
|
@ -47,7 +47,6 @@
|
||||
<li><link href="#Graphics2D">Shapes and Graphics2D</link></li>
|
||||
<li><link href="#Render">How to convert slides into images</link></li>
|
||||
<li><link href="#HeadersFooters">Headers / Footers</link></li>
|
||||
<li><link href="#Movies">How to embed movies</link></li>
|
||||
</ul>
|
||||
</section>
|
||||
<section><title>Features</title>
|
||||
@ -621,6 +620,7 @@
|
||||
</source>
|
||||
</section>
|
||||
|
||||
</section>
|
||||
<anchor id="HeadersFooters"/>
|
||||
<section><title>How to extract Headers / Footers from an existing presentation</title>
|
||||
<source>
|
||||
@ -663,29 +663,6 @@
|
||||
hdd.setFootersText("Created by POI-HSLF");
|
||||
</source>
|
||||
</section>
|
||||
<anchor id="Movies"/>
|
||||
<section><title>How to embed movies</title>
|
||||
<source>
|
||||
|
||||
SlideShow ppt = new SlideShow();
|
||||
Slide slide = ppt.createSlide();
|
||||
|
||||
//UNC or local Returns UNC or local path to a video file
|
||||
String moviePath = "card.mpg";
|
||||
int movieIdx = ppt.addMovie(moviePath, MovieShape.MOVIE_MPEG);
|
||||
|
||||
String thumbnailPath = "card.png";
|
||||
int thumbnailIdx = ppt.addPicture(new File(thumbnailPath), Picture.PNG);
|
||||
MovieShape shape = new MovieShape(movieIdx, thumbnailIdx);
|
||||
shape.setAnchor(new Rectangle2D.Float(300,225,120,90));
|
||||
slide.addShape(shape);
|
||||
|
||||
FileOutputStream out = new FileOutputStream("hslf-movie.ppt");
|
||||
ppt.write(out);
|
||||
out.close();
|
||||
</source>
|
||||
</section>
|
||||
</section>
|
||||
</section>
|
||||
</body>
|
||||
</document>
|
@ -20,17 +20,18 @@
|
||||
<!DOCTYPE book PUBLIC "-//APACHE//DTD Cocoon Documentation Book V1.0//EN" "../dtd/book-cocoon-v10.dtd">
|
||||
|
||||
<book software="POI Project"
|
||||
title="HSSF"
|
||||
title="HSSF+XSSF"
|
||||
copyright="@year@ POI Project">
|
||||
|
||||
<menu label="Apache POI">
|
||||
<menu-item label="Top" href="../index.html"/>
|
||||
</menu>
|
||||
|
||||
<menu label="HSSF">
|
||||
<menu label="HSSF+XSSF">
|
||||
<menu-item label="Overview" href="index.html"/>
|
||||
<menu-item label="Quick Guide" href="quick-guide.html"/>
|
||||
<menu-item label="HOWTO" href="how-to.html"/>
|
||||
<menu-item label="HSSF to SS Converting" href="converting.html"/>
|
||||
<menu-item label="Formula Support" href="formula.html" />
|
||||
<menu-item label="Formula Evaluation" href="eval.html" />
|
||||
<menu-item label="Eval Dev Guide" href="eval-devguide.html" />
|
232
src/documentation/content/xdocs/spreadsheet/converting.xml
Normal file
232
src/documentation/content/xdocs/spreadsheet/converting.xml
Normal file
@ -0,0 +1,232 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
====================================================================
|
||||
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.
|
||||
====================================================================
|
||||
-->
|
||||
<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.1//EN" "../dtd/document-v11.dtd">
|
||||
|
||||
<document>
|
||||
<header>
|
||||
<title>Upgrading to POI 3.5, including converting existing HSSF Usermodel code to SS Usermodel (for XSSF and HSSF)</title>
|
||||
<authors>
|
||||
<person email="nick@apache.org" name="Nick Burch" id="NB"/>
|
||||
</authors>
|
||||
</header>
|
||||
<body>
|
||||
<section><title>Things that have to be changed when upgrading to POI 3.5</title>
|
||||
<p>Wherever possible, we have tried to ensure that you can use your
|
||||
existing POI code with POI 3.5 without requiring any changes. However,
|
||||
Java doesn't always make that easy, and unfortunately there are a
|
||||
few changes that may be required for some users.</p>
|
||||
<section><title>org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.CellValue</title>
|
||||
<p>Annoyingly, java will not let you access a static inner class via
|
||||
a child of the parent one. So, all references to
|
||||
<em>org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator.CellValue</em>
|
||||
will need to be changed to
|
||||
<em>org.apache.poi.ss.usermodel.FormulaEvaluator.CellValue</em>
|
||||
</p>
|
||||
</section>
|
||||
<section><title>org.apache.poi.hssf.usermodel.HSSFRow.MissingCellPolicy</title>
|
||||
<p>Annoyingly, java will not let you access a static inner class via
|
||||
a child of the parent one. So, all references to
|
||||
<em>org.apache.poi.hssf.usermodel.HSSFRow.MissingCellPolicy</em>
|
||||
will need to be changed to
|
||||
<em>org.apache.poi.ss.usermodel.Row.MissingCellPolicy</em>
|
||||
</p>
|
||||
</section>
|
||||
<section><title>DDF and org.apache.poi.hssf.record.RecordFormatException</title>
|
||||
<p>Previously, record level errors within DDF would throw an
|
||||
exception from the hssf class heirachy. Now, record level errors
|
||||
within DDF will throw a more general RecordFormatException,
|
||||
<em>org.apache.poi.util.RecordFormatException</em></p>
|
||||
<p>In addition, org.apache.poi.hssf.record.RecordFormatException
|
||||
has been changed to inherit from the new
|
||||
<em>org.apache.poi.util.RecordFormatException</em>, so you may
|
||||
wish to change catches of the hssf version to the new util version.
|
||||
</p>
|
||||
</section>
|
||||
</section>
|
||||
<section><title>Converting existing HSSF Usermodel code to SS Usermodel (for XSSF and HSSF)</title>
|
||||
|
||||
<section><title>Why change?</title>
|
||||
<p>If you have existing HSSF usermodel code that works just
|
||||
fine, and you don't want to use the new OOXML XSSF support,
|
||||
then you probably don't need to. Your existing HSSF only code
|
||||
will continue to work just fine.</p>
|
||||
<p>However, if you want to be able to work with both HSSF for
|
||||
your .xls files, and also XSSF for .xslx files, then you will
|
||||
need to make some slight tweaks to your code.</p>
|
||||
</section>
|
||||
<section><title>org.apache.poi.ss.usermodel</title>
|
||||
<p>The new SS usermodel (org.apache.poi.ss.usermodel) is very
|
||||
heavily based on the old HSSF usermodel
|
||||
(org.apache.poi.hssf.usermodel). The main difference is that
|
||||
the package name and class names have been tweaked to remove
|
||||
HSSF from them. Otherwise, the new SS Usermodel interfaces
|
||||
should provide the same functionality.</p>
|
||||
</section>
|
||||
<section><title>Constructors</title>
|
||||
<p>Calling the empty HSSFWorkbook remains as the way to
|
||||
create a new, empty Workbook object. To open an existing
|
||||
Worbook, you should now call WorkbookFactory.create(inp).</p>
|
||||
<p>For all other cases when you would have called a
|
||||
Usermodel constructor, such as 'new HSSFRichTextString()' or
|
||||
'new HSSFDataFormat', you should instead use a CreationHelper.
|
||||
There's a method on the Workbook to get a CreationHelper, and
|
||||
the CreationHelper will then handle constructing new objects
|
||||
for you.</p>
|
||||
</section>
|
||||
<section><title>Other Code</title>
|
||||
<p>For all other code, generally change a reference from
|
||||
org.apache.poi.hssf.usermodel.HSSFFoo to a reference to
|
||||
org.apache.poi.ss.usermodel.Foo. Method signatures should
|
||||
otherwise remain the same, and it should all then work for
|
||||
both XSSF and HSSF.</p>
|
||||
</section>
|
||||
</section>
|
||||
<section><title>Worked Examples</title>
|
||||
<section><title>Old HSSF Code</title>
|
||||
<source><![CDATA[
|
||||
// import org.apache.poi.hssf.usermodel.*;
|
||||
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
// create a new sheet
|
||||
HSSFSheet s = wb.createSheet();
|
||||
// declare a row object reference
|
||||
HSSFRow r = null;
|
||||
// declare a cell object reference
|
||||
HSSFCell c = null;
|
||||
// create 2 cell styles
|
||||
HSSFCellStyle cs = wb.createCellStyle();
|
||||
HSSFCellStyle cs2 = wb.createCellStyle();
|
||||
HSSFDataFormat df = wb.createDataFormat();
|
||||
|
||||
// create 2 fonts objects
|
||||
HSSFFont f = wb.createFont();
|
||||
HSSFFont f2 = wb.createFont();
|
||||
|
||||
// Set font 1 to 12 point type, blue and bold
|
||||
f.setFontHeightInPoints((short) 12);
|
||||
f.setColor( (short)0xc );
|
||||
f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
|
||||
|
||||
// Set font 2 to 10 point type, red and bold
|
||||
f2.setFontHeightInPoints((short) 10);
|
||||
f2.setColor( (short)HSSFFont.COLOR_RED );
|
||||
f2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
|
||||
|
||||
// Set cell style and formatting
|
||||
cs.setFont(f);
|
||||
cs.setDataFormat(df.getFormat("#,##0.0"));
|
||||
|
||||
// Set the other cell style and formatting
|
||||
cs2.setBorderBottom(cs2.BORDER_THIN);
|
||||
cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
|
||||
cs2.setFont(f2);
|
||||
|
||||
|
||||
// Define a few rows
|
||||
for(short rownum = (short)0; rownum < 30; rownum++) {
|
||||
HSSFRow r = s.createRow(rownum);
|
||||
for(short cellnum = (short)0; cellnum < 10; cellnum += 2) {
|
||||
HSSFCell c = r.createCell(cellnum);
|
||||
HSSFCell c2 = r.createCell(cellnum+1);
|
||||
|
||||
c.setCellValue((double)rownum + (cellnum/10));
|
||||
c2.setCellValue(new HSSFRichTextString("Hello! " + cellnum);
|
||||
}
|
||||
}
|
||||
|
||||
// Save
|
||||
FileOutputStream out = new FileOutputStream("workbook.xls");
|
||||
wb.write(out);
|
||||
out.close();
|
||||
]]></source>
|
||||
</section>
|
||||
<section><title>New, generic SS Usermodel Code</title>
|
||||
<source><![CDATA[
|
||||
// import org.apache.poi.ss.usermodel.*;
|
||||
|
||||
Workbook[] wbs = new Workbook[] { new HSSFWorkbook(), new XSSFWorkbook() };
|
||||
for(int i=0; i<wbs.length; i++) {
|
||||
Workbook wb = wbs[i];
|
||||
CreationHelper createHelper = wb.getCreationHelper();
|
||||
|
||||
// create a new sheet
|
||||
Sheet s = wb.createSheet();
|
||||
// declare a row object reference
|
||||
Row r = null;
|
||||
// declare a cell object reference
|
||||
Cell c = null;
|
||||
// create 2 cell styles
|
||||
CellStyle cs = wb.createCellStyle();
|
||||
CellStyle cs2 = wb.createCellStyle();
|
||||
DataFormat df = wb.createDataFormat();
|
||||
|
||||
// create 2 fonts objects
|
||||
Font f = wb.createFont();
|
||||
Font f2 = wb.createFont();
|
||||
|
||||
// Set font 1 to 12 point type, blue and bold
|
||||
f.setFontHeightInPoints((short) 12);
|
||||
f.setColor( (short)0xc );
|
||||
f.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
||||
|
||||
// Set font 2 to 10 point type, red and bold
|
||||
f2.setFontHeightInPoints((short) 10);
|
||||
f2.setColor( (short)Font.COLOR_RED );
|
||||
f2.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
||||
|
||||
// Set cell style and formatting
|
||||
cs.setFont(f);
|
||||
cs.setDataFormat(df.getFormat("#,##0.0"));
|
||||
|
||||
// Set the other cell style and formatting
|
||||
cs2.setBorderBottom(cs2.BORDER_THIN);
|
||||
cs2.setDataFormat(df.getFormat("text"));
|
||||
cs2.setFont(f2);
|
||||
|
||||
|
||||
// Define a few rows
|
||||
for(int rownum = 0; rownum < 30; rownum++) {
|
||||
Row r = s.createRow(rownum);
|
||||
for(int cellnum = 0; cellnum < 10; cellnum += 2) {
|
||||
Cell c = r.createCell(cellnum);
|
||||
Cell c2 = r.createCell(cellnum+1);
|
||||
|
||||
c.setCellValue((double)rownum + (cellnum/10));
|
||||
c2.setCellValue(
|
||||
createHelper.createRichTextString("Hello! " + cellnum)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Save
|
||||
String filename = "workbook.xls";
|
||||
if(wb instanceof XSSFWorkbook) {
|
||||
filename = filename + "x";
|
||||
}
|
||||
|
||||
FileOutputStream out = new FileOutputStream(filename);
|
||||
wb.write(out);
|
||||
out.close();
|
||||
}
|
||||
]]></source>
|
||||
</section>
|
||||
</section>
|
||||
</body>
|
||||
</document>
|
@ -81,45 +81,84 @@
|
||||
</section>
|
||||
<section><title>Walkthrough of an "evaluate()" implementation.</title>
|
||||
<p>So here is the fun part - lets walk through the implementation of the excel
|
||||
function... <strong>NOT()</strong> </p>
|
||||
function... <strong>SQRT()</strong> </p>
|
||||
<section><title>The Code</title>
|
||||
<source>
|
||||
public final class Not implements Function {
|
||||
public class Sqrt extends NumericFunction {
|
||||
|
||||
private static final ValueEvalToNumericXlator NUM_XLATOR =
|
||||
new ValueEvalToNumericXlator((short)
|
||||
( ValueEvalToNumericXlator.BOOL_IS_PARSED
|
||||
| ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
|
||||
| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
|
||||
| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
|
||||
| ValueEvalToNumericXlator.STRING_IS_PARSED
|
||||
));
|
||||
|
||||
protected ValueEvalToNumericXlator getXlator() {
|
||||
return NUM_XLATOR;
|
||||
}
|
||||
|
||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
||||
double d = 0;
|
||||
ValueEval retval = null;
|
||||
|
||||
switch (operands.length) {
|
||||
default:
|
||||
retval = ErrorEval.VALUE_INVALID;
|
||||
break;
|
||||
case 1:
|
||||
ValueEval ve = singleOperandEvaluate(operands[0], srcRow, srcCol);
|
||||
if (ve instanceof NumericValueEval) {
|
||||
NumericValueEval ne = (NumericValueEval) ve;
|
||||
d = ne.getNumberValue();
|
||||
}
|
||||
else if (ve instanceof BlankEval) {
|
||||
// do nothing
|
||||
}
|
||||
else {
|
||||
retval = ErrorEval.NUM_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (retval == null) {
|
||||
d = Math.sqrt(d);
|
||||
retval = (Double.isNaN(d)) ? (ValueEval) ErrorEval.VALUE_INVALID : new NumberEval(d);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) {
|
||||
if (args.length != 1) {
|
||||
return ErrorEval.VALUE_INVALID;
|
||||
}
|
||||
boolean boolArgVal;
|
||||
try {
|
||||
ValueEval ve = OperandResolver.getSingleValue(args[0], srcCellRow, srcCellCol);
|
||||
Boolean b = OperandResolver.coerceValueToBoolean(ve, false);
|
||||
boolArgVal = b == null ? false : b.booleanValue();
|
||||
} catch (EvaluationException e) {
|
||||
return e.getErrorEval();
|
||||
}
|
||||
|
||||
return BoolEval.valueOf(!boolArgVal);
|
||||
}
|
||||
}
|
||||
|
||||
</source>
|
||||
</section>
|
||||
<section><title>Implementation Details</title>
|
||||
<ul>
|
||||
<li>The first thing to realise is that classes already exist, even for functions that are not yet implemented.
|
||||
Just that they extend from NotImplementedFunction whose behaviour is to return an ErrorEval.FUNCTION_NOT_IMPLEMENTED value.</li>
|
||||
<li>In order to implement NOT(..), we need to implement the interface 'Function' which has a method 'evaluate(..)'</li>
|
||||
<li>Since NOT(..) takes a single argument, we verify the length of the operands array else set the return value to ErrorEval.VALUE_INVALID</li>
|
||||
Just that they extend from DefaultFunctionImpl whose behaviour is to return an ErrorEval.FUNCTION_NOT_IMPLEMENTED value.</li>
|
||||
<li>In order to implement SQRT(..), we need to: a. Extend from the correct Abstract super class; b. implement the evaluate(..) method</li>
|
||||
<li>Hence we extend SQRT(..) from the predefined class NumericFunction</li>
|
||||
<li>Since SQRT(..) takes a single argument, we verify the length of the operands array else set the return value to ErrorEval.VALUE_INVALID</li>
|
||||
<li>Next we normalize each operand to a limited set of ValueEval subtypes, specifically, we call the function
|
||||
<code>OperandResolver.getSingleValue</code> to do conversions of different value eval types to one of: NumericValueEval,
|
||||
BlankEval and ErrorEval. The conversion logic is performed by OperandResolver.coerceValueToBoolean()
|
||||
<code>singleOperandEvaluate(..)</code> to do conversions of different value eval types to one of: NumericValueEval,
|
||||
BlankEval and ErrorEval. The conversion logic is configured by a ValueEvalToNumericXlator instance which
|
||||
is returned by the Factory method: <code>getXlator(..)</code> The flags used to create the ValueEvalToNumericXlator
|
||||
instance are briefly explained as follows:
|
||||
BOOL_IS_PARSED means whether this function treats Boolean values as 1,
|
||||
REF_BOOL_IS_PARSED means whether Boolean values in cell references are parsed or not.
|
||||
So also, EVALUATED_REF_BOOL_IS_PARSED means if the operand was a RefEval that was assigned a
|
||||
Boolean value as a result of evaluation of the formula that it contained.
|
||||
eg. SQRT(TRUE) returns 1: This means BOOL_IS_PARSED should be set.
|
||||
SQRT(A1) returns 1 when A1 has TRUE: This means REF_BOOL_IS_PARSED should be set.
|
||||
SQRT(A1) returns 1 when A1 has a formula that evaluates to TRUE: This means EVALUATED_REF_BOOL_IS_PARSED should be set.
|
||||
If the flag is not set for a particular case, that case is ignored (treated as if the cell is blank) _unless_
|
||||
there is a flag like: STRING_IS_INVALID_VALUE (which means that Strings should be treated as resulting in VALUE_INVALID ErrorEval)
|
||||
</li>
|
||||
<li>Next perform the appropriate java operation (if an error didnt occur already).</li>
|
||||
<li>Finally return the BoolEval wrapping primitive boolean result. Note - in the case of numeric results
|
||||
you should check for NaN and Infinity, because exel likes these translated into specific error codes like
|
||||
VALUE_INVALID, NUM_ERROR, DIV_ZERO etc.
|
||||
(Thanks to Avik for bringing this issue up early!)</li>
|
||||
<li>Next perform the appropriate Math function on the double value (if an error didnt occur already).</li>
|
||||
<li>Finally before returning the NumberEval wrapping the double value that
|
||||
you computed, do one final check to see if the double is a NaN, (or if it is "Infinite")
|
||||
If it is return the appropriate ErrorEval instance. Note: The OpenOffice.org error codes
|
||||
should NOT be preferred. Instead use the excel specific error codes like VALUE_INVALID, NUM_ERROR, DIV_ZERO etc.
|
||||
(Thanks to Avik for bringing this issue up early!) The Oo.o ErrorCodes will be removed (if they havent already been :)</li>
|
||||
</ul>
|
||||
</section>
|
||||
<section><title>Modelling Excel Semantics</title>
|
||||
@ -131,8 +170,8 @@ public final class Not implements Function {
|
||||
Because when you use TRUE in referenced cells with arithmetic functions, it evaluates to blank - meaning it is not evaluated - as if it was string or a blank cell.
|
||||
eg. "=SUM(1,A1)" when A1 is TRUE evaluates to 1.
|
||||
This behaviour changes depending on which function you are using. eg. SQRT(..) that was
|
||||
described earlier treats a TRUE as 1 in all cases. The various conversion logic has been refactored into common places like the following classes:
|
||||
OperandResolver, TextFunction, NumericFunction, MultiOperandNumericFunction and FinanceFunction.
|
||||
described earlier treats a TRUE as 1 in all cases. This is why the configurable ValueEvalToNumericXlator
|
||||
class had to be written.
|
||||
</p>
|
||||
<p>Note that when you are extending from an abstract function class like
|
||||
NumericFunction (rather than implementing the interface o.a.p.hssf.record.formula.eval.Function directly)
|
||||
@ -147,16 +186,18 @@ public final class Not implements Function {
|
||||
</section>
|
||||
<section><title>Testing Framework</title>
|
||||
<p>Automated testing of the implemented Function is easy.
|
||||
The source code for this is in the file: o.a.p.h.record.formula.TestFormulasFromSpreadsheet.java
|
||||
This class has a reference to the Excel test sample file 'FormulaEvalTestData.xls'. In this file,
|
||||
The source code for this is in the file: o.a.p.h.record.formula.GenericFormulaTestCase.java
|
||||
This class has a reference to the test xls file (not /a/ test xls, /the/ test xls :)
|
||||
which may need to be changed for your environment. Once you do that, in the test xls,
|
||||
locate the entry for the function that you have implemented and enter different tests
|
||||
in a cell in the FORMULA row. Then copy the "value of" the formula that you entered in the
|
||||
cell just below it (this is easily done in excel as:
|
||||
[copy the formula cell] > [go to cell below] > Edit > Paste Special > Values > "ok").
|
||||
You can enter multiple such formulas and paste their values in the cell below and the
|
||||
test framework will automatically test if the formula evaluation matches the expected
|
||||
value (Please take time to quickly look at the code and the currently entered tests in the
|
||||
file "FormulaEvalTestData.xls").
|
||||
value (Again, hard to put in words, so if you will, please take time to quickly look
|
||||
at the code and the currently entered tests in the patch attachment "FormulaEvalTestData.xls"
|
||||
file).
|
||||
</p>
|
||||
</section>
|
||||
</body>
|
@ -20,13 +20,13 @@
|
||||
<!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.1//EN" "../dtd/document-v11.dtd">
|
||||
|
||||
<document>
|
||||
<header>
|
||||
<title>Formula Evaluation</title>
|
||||
<authors>
|
||||
<header>
|
||||
<title>Formula Evaluation</title>
|
||||
<authors>
|
||||
<person email="amoweb@yahoo.com" name="Amol Deshmukh" id="AD"/>
|
||||
</authors>
|
||||
</header>
|
||||
<body>
|
||||
</authors>
|
||||
</header>
|
||||
<body>
|
||||
<section><title>Introduction</title>
|
||||
<p>The POI formula evaluation code enables you to calculate the result of
|
||||
formulas in Excels sheets read-in, or created in POI. This document explains
|
||||
@ -35,7 +35,7 @@
|
||||
<note>In versions of POI before 3.0.3, this code lived in the
|
||||
scratchpad area of the POI SVN repository. If using an such an older
|
||||
version of POI, ensure that you have the scratchpad jar or the
|
||||
scratchpad build area in your classpath before experimenting with this
|
||||
scratchpad build area in your classpath before experimenting with this
|
||||
code. Users of all versions of POI may wish to make use of a recent
|
||||
SVN checkout, as new functions are currently being added fairly frequently.
|
||||
</note>
|
||||
@ -48,56 +48,59 @@
|
||||
functions in Excel. The framework however makes is easy to add
|
||||
implementation of new functions. See the <link href="eval-devguide.html"> Formula
|
||||
evaluation development guide</link> for details. </p>
|
||||
<p> Both HSSFWorkbook and XSSFWorkbook are supported, so you can
|
||||
evaluate formulas on both .xls and .xlsx files.</p>
|
||||
<p> Note that user-defined functions are not supported, and is not likely to done
|
||||
any time soon... at least, not till there is a VB implementation in Java!
|
||||
</p>
|
||||
</section>
|
||||
<section><title>User API How-TO</title>
|
||||
<p>The following code demonstrates how to use the HSSFFormulaEvaluator
|
||||
<p>The following code demonstrates how to use the FormulaEvaluator
|
||||
in the context of other POI excel reading code.
|
||||
</p>
|
||||
<p>There are several ways in which you can use the HSSFFormulaEvalutator API.</p>
|
||||
<p>There are several ways in which you can use the FormulaEvalutator API.</p>
|
||||
|
||||
<anchor id="Evaluate"/>
|
||||
<section><title>Using HSSFFormulaEvaluator.<strong>evaluate</strong>(HSSFCell cell)</title>
|
||||
<section><title>Using FormulaEvaluator.<strong>evaluate</strong>(Cell cell)</title>
|
||||
<p>This evaluates a given cell, and returns the new value,
|
||||
without affecting the cell</p>
|
||||
<source>
|
||||
FileInputStream fis = new FileInputStream("c:/temp/test.xls");
|
||||
HSSFWorkbook wb = new HSSFWorkbook(fis);
|
||||
HSSFSheet sheet = wb.getSheetAt(0);
|
||||
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb);
|
||||
Workbook wb = new HSSFWorkbook(fis);
|
||||
Sheet sheet = wb.getSheetAt(0);
|
||||
FormulaEvaluator evaluator = new FormulaEvaluator(sheet, wb);
|
||||
|
||||
// suppose your formula is in B3
|
||||
CellReference cellReference = new CellReference("B3");
|
||||
HSSFRow row = sheet.getRow(cellReference.getRow());
|
||||
HSSFCell cell = row.getCell((int)cellReference.getCol());
|
||||
CellReference cellReference = new CellReference("B3");
|
||||
Row row = sheet.getRow(cellReference.getRow());
|
||||
Cell cell = row.getCell(cellReference.getCol());
|
||||
|
||||
HSSFFormulaEvaluator.CellValue cellValue = evaluator.evaluate(cell);
|
||||
evaluator.setCurrentRow(row);
|
||||
FormulaEvaluator.CellValue cellValue = evaluator.evaluate(cell);
|
||||
|
||||
switch (cellValue.getCellType()) {
|
||||
case HSSFCell.CELL_TYPE_BOOLEAN:
|
||||
System.out.println(cellValue.getBooleanValue());
|
||||
break;
|
||||
case HSSFCell.CELL_TYPE_NUMERIC:
|
||||
System.out.println(cellValue.getNumberValue());
|
||||
break;
|
||||
case HSSFCell.CELL_TYPE_STRING:
|
||||
System.out.println(cellValue.getStringValue());
|
||||
break;
|
||||
case HSSFCell.CELL_TYPE_BLANK:
|
||||
break;
|
||||
case HSSFCell.CELL_TYPE_ERROR:
|
||||
break;
|
||||
case Cell.CELL_TYPE_BOOLEAN:
|
||||
System.out.println(cellValue.getBooleanValue());
|
||||
break;
|
||||
case Cell.CELL_TYPE_NUMERIC:
|
||||
System.out.println(cellValue.getNumberValue());
|
||||
break;
|
||||
case Cell.CELL_TYPE_STRING:
|
||||
System.out.println(cellValue.getStringValue());
|
||||
break;
|
||||
case Cell.CELL_TYPE_BLANK:
|
||||
break;
|
||||
case Cell.CELL_TYPE_ERROR:
|
||||
break;
|
||||
|
||||
// CELL_TYPE_FORMULA will never happen
|
||||
case HSSFCell.CELL_TYPE_FORMULA:
|
||||
break;
|
||||
}
|
||||
case Cell.CELL_TYPE_FORMULA:
|
||||
break;
|
||||
}
|
||||
</source>
|
||||
<p>Thus using the retrieved value (of type
|
||||
HSSFFormulaEvaluator.CellValue - a nested class) returned
|
||||
by HSSFFormulaEvaluator is similar to using a HSSFCell object
|
||||
FormulaEvaluator.CellValue - a nested class) returned
|
||||
by FormulaEvaluator is similar to using a Cell object
|
||||
containing the value of the formula evaluation. CellValue is
|
||||
a simple value object and does not maintain reference
|
||||
to the original cell.
|
||||
@ -105,99 +108,93 @@ switch (cellValue.getCellType()) {
|
||||
</section>
|
||||
|
||||
<anchor id="EvaluateFormulaCell"/>
|
||||
<section><title>Using HSSFFormulaEvaluator.<strong>evaluateFormulaCell</strong>(HSSFCell cell)</title>
|
||||
<p><strong>evaluateFormulaCell</strong>(HSSFCell cell)
|
||||
<section><title>Using FormulaEvaluator.<strong>evaluateFormulaCell</strong>(Cell cell)</title>
|
||||
<p><strong>evaluateFormulaCell</strong>(Cell cell)
|
||||
will check to see if the supplied cell is a formula cell.
|
||||
If it isn't, then no changes will be made to it. If it is,
|
||||
then the formula is evaluated. The value for the formula
|
||||
is saved alongside it, to be displayed in excel. The
|
||||
formula remains in the cell, just with a new value</p>
|
||||
<p>The return of the function is the type of the
|
||||
formula result, such as HSSFCell.CELL_TYPE_BOOLEAN</p>
|
||||
formula result, such as Cell.CELL_TYPE_BOOLEAN</p>
|
||||
<source>
|
||||
FileInputStream fis = new FileInputStream("/somepath/test.xls");
|
||||
HSSFWorkbook wb = new HSSFWorkbook(fis);
|
||||
HSSFSheet sheet = wb.getSheetAt(0);
|
||||
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb);
|
||||
Workbook wb = new HSSFWorkbook(fis);
|
||||
Sheet sheet = wb.getSheetAt(0);
|
||||
FormulaEvaluator evaluator = new FormulaEvaluator(sheet, wb);
|
||||
|
||||
// suppose your formula is in B3
|
||||
CellReference cellReference = new CellReference("B3");
|
||||
HSSFRow row = sheet.getRow(cellReference.getRow());
|
||||
HSSFCell cell = row.getCell((int)cellReference.getCol());
|
||||
CellReference cellReference = new CellReference("B3");
|
||||
Row row = sheet.getRow(cellReference.getRow());
|
||||
Cell cell = row.getCell(cellReference.getCol());
|
||||
evaluator.setCurrentRow(row);
|
||||
|
||||
if (cell!=null) {
|
||||
int valueType = evaluator.evaluateFormulaCell(cell);
|
||||
if (valueType == -1) {
|
||||
// Cell was not a formula cell
|
||||
// but we can read the plain value from the cell just the same as a formula result
|
||||
valueType = cell.getCellType();
|
||||
}
|
||||
switch (valueType) {
|
||||
case HSSFCell.CELL_TYPE_BOOLEAN:
|
||||
System.out.println(cell.getBooleanCellValue());
|
||||
break;
|
||||
case HSSFCell.CELL_TYPE_NUMERIC:
|
||||
System.out.println(cell.getNumericCellValue());
|
||||
break;
|
||||
case HSSFCell.CELL_TYPE_STRING:
|
||||
System.out.println(cell.getRichStringCellValue().getString());
|
||||
break;
|
||||
case HSSFCell.CELL_TYPE_BLANK:
|
||||
break;
|
||||
case HSSFCell.CELL_TYPE_ERROR:
|
||||
System.out.println(HSSFErrorConstants.getText(cell.getErrorCellValue()));
|
||||
break;
|
||||
|
||||
case HSSFCell.CELL_TYPE_FORMULA:
|
||||
throw new IllegalStateException("Result-type 'formula' cannot occur");
|
||||
switch (<strong>evaluator.evaluateFormulaCell</strong>(cell)) {
|
||||
case Cell.CELL_TYPE_BOOLEAN:
|
||||
System.out.println(cell.getBooleanCellValue());
|
||||
break;
|
||||
case Cell.CELL_TYPE_NUMERIC:
|
||||
System.out.println(cell.getNumberCellValue());
|
||||
break;
|
||||
case Cell.CELL_TYPE_STRING:
|
||||
System.out.println(cell.getStringCellValue());
|
||||
break;
|
||||
case Cell.CELL_TYPE_BLANK:
|
||||
break;
|
||||
case Cell.CELL_TYPE_ERROR:
|
||||
System.out.println(cell.getErrorCellValue());
|
||||
break;
|
||||
|
||||
// CELL_TYPE_FORMULA will never occur
|
||||
case Cell.CELL_TYPE_FORMULA:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</source>
|
||||
</section>
|
||||
|
||||
<anchor id="EvaluateInCell"/>
|
||||
<section><title>Using HSSFFormulaEvaluator.<strong>evaluateInCell</strong>(HSSFCell cell)</title>
|
||||
<p><strong>evaluateInCell</strong>(HSSFCell cell) will check to
|
||||
<section><title>Using FormulaEvaluator.<strong>evaluateInCell</strong>(Cell cell)</title>
|
||||
<p><strong>evaluateInCell</strong>(Cell cell) will check to
|
||||
see if the supplied cell is a formula cell. If it isn't,
|
||||
then no changes will be made to it. If it is, then the
|
||||
formula is evaluated, and the new value saved into the cell,
|
||||
in place of the old formula.</p>
|
||||
<source>
|
||||
FileInputStream fis = new FileInputStream("/somepath/test.xls");
|
||||
HSSFWorkbook wb = new HSSFWorkbook(fis);
|
||||
HSSFSheet sheet = wb.getSheetAt(0);
|
||||
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb);
|
||||
Workbook wb = new HSSFWorkbook(fis);
|
||||
Sheet sheet = wb.getSheetAt(0);
|
||||
FormulaEvaluator evaluator = new FormulaEvaluator(sheet, wb);
|
||||
|
||||
// suppose your formula is in B3
|
||||
CellReference cellReference = new CellReference("B3");
|
||||
HSSFRow row = sheet.getRow(cellReference.getRow());
|
||||
HSSFCell cell = row.getCell((int)cellReference.getCol());
|
||||
CellReference cellReference = new CellReference("B3");
|
||||
Row row = sheet.getRow(cellReference.getRow());
|
||||
Cell cell = row.getCell(cellReference.getCol());
|
||||
evaluator.setCurrentRow(row);
|
||||
|
||||
if (cell!=null) {
|
||||
switch (evaluator.evaluateInCell(cell).getCellType()) {
|
||||
case HSSFCell.CELL_TYPE_BOOLEAN:
|
||||
System.out.println(cell.getBooleanCellValue());
|
||||
break;
|
||||
case HSSFCell.CELL_TYPE_NUMERIC:
|
||||
System.out.println(cell.getNumericCellValue());
|
||||
break;
|
||||
case HSSFCell.CELL_TYPE_STRING:
|
||||
System.out.println(cell.getRichStringCellValue().getString());
|
||||
break;
|
||||
case HSSFCell.CELL_TYPE_BLANK:
|
||||
break;
|
||||
case HSSFCell.CELL_TYPE_ERROR:
|
||||
System.out.println(cell.getErrorCellValue());
|
||||
break;
|
||||
|
||||
switch (<strong>evaluator.evaluateInCell</strong>(cell).getCellType()) {
|
||||
case Cell.CELL_TYPE_BOOLEAN:
|
||||
System.out.println(cell.getBooleanCellValue());
|
||||
break;
|
||||
case Cell.CELL_TYPE_NUMERIC:
|
||||
System.out.println(cell.getNumberCellValue());
|
||||
break;
|
||||
case Cell.CELL_TYPE_STRING:
|
||||
System.out.println(cell.getStringCellValue());
|
||||
break;
|
||||
case Cell.CELL_TYPE_BLANK:
|
||||
break;
|
||||
case Cell.CELL_TYPE_ERROR:
|
||||
System.out.println(cell.getErrorCellValue());
|
||||
break;
|
||||
|
||||
// CELL_TYPE_FORMULA will never occur
|
||||
case HSSFCell.CELL_TYPE_FORMULA:
|
||||
break;
|
||||
case Cell.CELL_TYPE_FORMULA:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
</source>
|
||||
</section>
|
||||
|
||||
@ -205,24 +202,24 @@ if (cell!=null) {
|
||||
<section><title>Re-calculating all formulas in a Workbook</title>
|
||||
<source>
|
||||
FileInputStream fis = new FileInputStream("/somepath/test.xls");
|
||||
HSSFWorkbook wb = new HSSFWorkbook(fis);
|
||||
HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(wb);
|
||||
Workbook wb = new HSSFWorkbook(fis);
|
||||
for(int sheetNum = 0; sheetNum < wb.getNumberOfSheets(); sheetNum++) {
|
||||
HSSFSheet sheet = wb.getSheetAt(sheetNum);
|
||||
Sheet sheet = wb.getSheetAt(sheetNum);
|
||||
FormulaEvaluator evaluator = new FormulaEvaluator(sheet, wb);
|
||||
|
||||
for(Iterator rit = sheet.rowIterator(); rit.hasNext();) {
|
||||
HSSFRow r = (HSSFRow)rit.next();
|
||||
Row r = (Row)rit.next();
|
||||
evaluator.setCurrentRow(r);
|
||||
|
||||
for(Iterator cit = r.cellIterator(); cit.hasNext();) {
|
||||
HSSFCell c = (HSSFCell)cit.next();
|
||||
if(c.getCellType() == HSSFCell.CELL_TYPE_FORMULA) {
|
||||
Cell c = (Cell)cit.next();
|
||||
if(c.getCellType() == Cell.CELL_TYPE_FORMULA) {
|
||||
evaluator.evaluateFormulaCell(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
wb.write(new FileOutputStream("/somepath/changed.xls"));
|
||||
|
||||
</source>
|
||||
</section>
|
||||
</section>
|
||||
@ -230,22 +227,22 @@ wb.write(new FileOutputStream("/somepath/changed.xls"));
|
||||
<anchor id="Performance"/>
|
||||
<section><title>Performance Notes</title>
|
||||
<ul>
|
||||
<li>Generally you should have to create only one HSSFFormulaEvaluator
|
||||
instance per workbook, but there really is no overhead in creating
|
||||
multiple HSSFFormulaEvaluators per workbook other than that of the
|
||||
HSSFFormulaEvaluator object creation.
|
||||
<li>Generally you should have to create only one FormulaEvaluator
|
||||
instance per sheet, but there really is no overhead in creating
|
||||
multiple FormulaEvaluators per sheet other than that of the
|
||||
FormulaEvaluator object creation.
|
||||
</li>
|
||||
<li>Also note that HSSFFormulaEvaluator maintains a reference to
|
||||
the workbook, so ensure that the evaluator instance
|
||||
<li>Also note that FormulaEvaluator maintains a reference to
|
||||
the sheet and workbook, so ensure that the evaluator instance
|
||||
is available for garbage collection when you are done with it
|
||||
(in other words don't maintain long lived reference to
|
||||
HSSFFormulaEvaluator if you don't really need to - unless
|
||||
FormulaEvaluator if you don't really need to - unless
|
||||
all references to the sheet and workbook are removed, these
|
||||
don't get garbage collected and continue to occupy potentially
|
||||
large amounts of memory).
|
||||
</li>
|
||||
<li>CellValue instances however do not maintain reference to the
|
||||
HSSFCell or the sheet or workbook, so these can be long-lived
|
||||
Cell or the sheet or workbook, so these can be long-lived
|
||||
objects without any adverse effect on performance.
|
||||
</li>
|
||||
</ul>
|
@ -99,7 +99,7 @@
|
||||
org.apache.poi.hssf.record.formula.FormulaParser</strong> class. This class implements a hand
|
||||
written recursive descent parser.
|
||||
</p>
|
||||
<p>Check out the <link href="http://poi.apache.org/apidocs/">javadocs</link> for details.
|
||||
<p>Check out the <link href="http://poi.apache.org/apidocs/">javadocs </link> for details.
|
||||
</p>
|
||||
</section>
|
||||
|
@ -33,7 +33,8 @@
|
||||
<section><title>How to use the HSSF API</title>
|
||||
|
||||
<section><title>Capabilities</title>
|
||||
<p>This release of the how-to outlines functionality for the CVS HEAD.
|
||||
<p>This release of the how-to outlines functionality for the
|
||||
current svn trunk.
|
||||
Those looking for information on previous releases should
|
||||
look in the documentation distributed with that release.</p>
|
||||
<p>
|
||||
@ -53,55 +54,64 @@
|
||||
have different characteristics, so you should read up on
|
||||
all to select the best for you.</p>
|
||||
<ul>
|
||||
<li><link href="#user_api">User API</link></li>
|
||||
<li><link href="#event_api">Event API</link></li>
|
||||
<li><link href="#record_aware_event_api">Event API with extensions to be Record Aware</link></li>
|
||||
<li><link href="#user_api">User API (HSSF and XSSF)</link></li>
|
||||
<li><link href="#event_api">Event API (HSSF Only)</link></li>
|
||||
<li><link href="#record_aware_event_api">Event API with extensions to be Record Aware (HSSF Only)</link></li>
|
||||
<li><link href="#xssf_sax_api">XSSF and SAX (Event API)</link></li>
|
||||
<li><link href="#low_level_api">Low Level API</link></li>
|
||||
</ul>
|
||||
</section>
|
||||
</section>
|
||||
<section><title>General Use</title>
|
||||
<anchor id="user_api" />
|
||||
<section><title>User API</title>
|
||||
<section><title>User API (HSSF and XSSF)</title>
|
||||
<section><title>Writing a new file</title>
|
||||
|
||||
<p>The high level API (package: org.apache.poi.hssf.usermodel)
|
||||
<p>The high level API (package: org.apache.poi.ss.usermodel)
|
||||
is what most people should use. Usage is very simple.
|
||||
</p>
|
||||
<p>Workbooks are created by creating an instance of
|
||||
org.apache.poi.hssf.usermodel.HSSFWorkbook.
|
||||
org.apache.poi.ss.usermodel.Workbook. Either create
|
||||
a concrete class directly
|
||||
(org.apache.poi.hssf.usermodel.HSSFWorkbook or
|
||||
org.apache.poi.xssf.usermodel.XSSFWorkbook), or use
|
||||
the handy factory class
|
||||
org.apache.poi.ss.usermodel.WorkbookFactory.
|
||||
</p>
|
||||
<p>Sheets are created by calling createSheet() from an existing
|
||||
instance of HSSFWorkbook, the created sheet is automatically added in
|
||||
instance of Workbook, the created sheet is automatically added in
|
||||
sequence to the workbook. Sheets do not in themselves have a sheet
|
||||
name (the tab at the bottom); you set
|
||||
the name associated with a sheet by calling
|
||||
HSSFWorkbook.setSheetName(sheetindex,"SheetName",encoding).
|
||||
The name may be in 8bit format (HSSFWorkbook.ENCODING_COMPRESSED_UNICODE)
|
||||
or Unicode (HSSFWorkbook.ENCODING_UTF_16). Default encoding is 8bit per char.
|
||||
Workbook.setSheetName(sheetindex,"SheetName",encoding).
|
||||
For HSSF, the name may be in 8bit format
|
||||
(HSSFWorkbook.ENCODING_COMPRESSED_UNICODE)
|
||||
or Unicode (HSSFWorkbook.ENCODING_UTF_16). Default
|
||||
encoding for HSSF is 8bit per char. For XSSF, the name
|
||||
is automatically handled as unicode.
|
||||
</p>
|
||||
<p>Rows are created by calling createRow(rowNumber) from an existing
|
||||
instance of HSSFSheet. Only rows that have cell values should be
|
||||
instance of Sheet. Only rows that have cell values should be
|
||||
added to the sheet. To set the row's height, you just call
|
||||
setRowHeight(height) on the row object. The height must be given in
|
||||
twips, or 1/20th of a point. If you prefer, there is also a
|
||||
setRowHeightInPoints method.
|
||||
</p>
|
||||
<p>Cells are created by calling createCell(column, type) from an
|
||||
existing HSSFRow. Only cells that have values should be added to the
|
||||
existing Row. Only cells that have values should be added to the
|
||||
row. Cells should have their cell type set to either
|
||||
HSSFCell.CELL_TYPE_NUMERIC or HSSFCell.CELL_TYPE_STRING depending on
|
||||
Cell.CELL_TYPE_NUMERIC or Cell.CELL_TYPE_STRING depending on
|
||||
whether they contain a numeric or textual value. Cells must also have
|
||||
a value set. Set the value by calling setCellValue with either a
|
||||
String or double as a parameter. Individual cells do not have a
|
||||
width; you must call setColumnWidth(colindex, width) (use units of
|
||||
1/256th of a character) on the HSSFSheet object. (You can't do it on
|
||||
1/256th of a character) on the Sheet object. (You can't do it on
|
||||
an individual basis in the GUI either).</p>
|
||||
<p>Cells are styled with HSSFCellStyle objects which in turn contain
|
||||
a reference to an HSSFFont object. These are created via the
|
||||
HSSFWorkbook object by calling createCellStyle() and createFont().
|
||||
<p>Cells are styled with CellStyle objects which in turn contain
|
||||
a reference to an Font object. These are created via the
|
||||
Workbook object by calling createCellStyle() and createFont().
|
||||
Once you create the object you must set its parameters (colors,
|
||||
borders, etc). To set a font for an HSSFCellStyle call
|
||||
borders, etc). To set a font for an CellStyle call
|
||||
setFont(fontobj).
|
||||
</p>
|
||||
<p>Once you have generated your workbook, you can write it out by
|
||||
@ -118,21 +128,21 @@ short rownum;
|
||||
// create a new file
|
||||
FileOutputStream out = new FileOutputStream("workbook.xls");
|
||||
// create a new workbook
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
Workbook wb = new HSSFWorkbook();
|
||||
// create a new sheet
|
||||
HSSFSheet s = wb.createSheet();
|
||||
Sheet s = wb.createSheet();
|
||||
// declare a row object reference
|
||||
HSSFRow r = null;
|
||||
Row r = null;
|
||||
// declare a cell object reference
|
||||
HSSFCell c = null;
|
||||
Cell c = null;
|
||||
// create 3 cell styles
|
||||
HSSFCellStyle cs = wb.createCellStyle();
|
||||
HSSFCellStyle cs2 = wb.createCellStyle();
|
||||
HSSFCellStyle cs3 = wb.createCellStyle();
|
||||
HSSFDataFormat df = wb.createDataFormat();
|
||||
CellStyle cs = wb.createCellStyle();
|
||||
CellStyle cs2 = wb.createCellStyle();
|
||||
CellStyle cs3 = wb.createCellStyle();
|
||||
DataFormat df = wb.createDataFormat();
|
||||
// create 2 fonts objects
|
||||
HSSFFont f = wb.createFont();
|
||||
HSSFFont f2 = wb.createFont();
|
||||
Font f = wb.createFont();
|
||||
Font f2 = wb.createFont();
|
||||
|
||||
//set font 1 to 12 point type
|
||||
f.setFontHeightInPoints((short) 12);
|
||||
@ -140,14 +150,14 @@ f.setFontHeightInPoints((short) 12);
|
||||
f.setColor( (short)0xc );
|
||||
// make it bold
|
||||
//arial is the default font
|
||||
f.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
|
||||
f.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
||||
|
||||
//set font 2 to 10 point type
|
||||
f2.setFontHeightInPoints((short) 10);
|
||||
//make it red
|
||||
f2.setColor( (short)HSSFFont.COLOR_RED );
|
||||
f2.setColor( (short)Font.COLOR_RED );
|
||||
//make it bold
|
||||
f2.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
|
||||
f2.setBoldweight(Font.BOLDWEIGHT_BOLD);
|
||||
|
||||
f2.setStrikeout( true );
|
||||
|
||||
@ -159,8 +169,8 @@ cs.setDataFormat(df.getFormat("#,##0.0"));
|
||||
//set a thin border
|
||||
cs2.setBorderBottom(cs2.BORDER_THIN);
|
||||
//fill w fg fill color
|
||||
cs2.setFillPattern((short) HSSFCellStyle.SOLID_FOREGROUND);
|
||||
//set the cell format to text see HSSFDataFormat for a full list
|
||||
cs2.setFillPattern((short) CellStyle.SOLID_FOREGROUND);
|
||||
//set the cell format to text see DataFormat for a full list
|
||||
cs2.setDataFormat(HSSFDataFormat.getBuiltinFormat("text"));
|
||||
|
||||
// set the font
|
||||
@ -168,10 +178,9 @@ cs2.setFont(f2);
|
||||
|
||||
// set the sheet name in Unicode
|
||||
wb.setSheetName(0, "\u0422\u0435\u0441\u0442\u043E\u0432\u0430\u044F " +
|
||||
"\u0421\u0442\u0440\u0430\u043D\u0438\u0447\u043A\u0430",
|
||||
HSSFWorkbook.ENCODING_UTF_16 );
|
||||
// in case of compressed Unicode
|
||||
// wb.setSheetName(0, "HSSF Test", HSSFWorkbook.ENCODING_COMPRESSED_UNICODE );
|
||||
"\u0421\u0442\u0440\u0430\u043D\u0438\u0447\u043A\u0430" );
|
||||
// in case of plain ascii
|
||||
// wb.setSheetName(0, "HSSF Test");
|
||||
// create a sheet with 30 rows (0-29)
|
||||
for (rownum = (short) 0; rownum < 30; rownum++)
|
||||
{
|
||||
@ -206,14 +215,12 @@ for (rownum = (short) 0; rownum < 30; rownum++)
|
||||
// set this cell to the first cell style we defined
|
||||
c.setCellStyle(cs);
|
||||
// set the cell's string value to "Test"
|
||||
c.setEncoding( HSSFCell.ENCODING_COMPRESSED_UNICODE );
|
||||
c.setCellValue( "Test" );
|
||||
}
|
||||
else
|
||||
{
|
||||
c.setCellStyle(cs2);
|
||||
// set the cell's string value to "\u0422\u0435\u0441\u0442"
|
||||
c.setEncoding( HSSFCell.ENCODING_UTF_16 );
|
||||
c.setCellValue( "\u0422\u0435\u0441\u0442" );
|
||||
}
|
||||
|
||||
@ -280,7 +287,7 @@ call workbook.write(outputstream) just as you did above.</p>
|
||||
</section>
|
||||
|
||||
<anchor id="event_api" />
|
||||
<section><title>Event API</title>
|
||||
<section><title>Event API (HSSF Only)</title>
|
||||
|
||||
<p>The event API is newer than the User API. It is intended for intermediate
|
||||
developers who are willing to learn a little bit of the low level API
|
||||
@ -419,7 +426,7 @@ public class EventExample
|
||||
</section>
|
||||
|
||||
<anchor id="record_aware_event_api" />
|
||||
<section><title>Record Aware Event API</title>
|
||||
<section><title>Record Aware Event API (HSSF Only)</title>
|
||||
<p>
|
||||
This is an extension to the normal
|
||||
<link href="#event_api">Event API</link>. With this, your listener
|
||||
@ -463,13 +470,158 @@ The latest version is always available from
|
||||
<link href="http://svn.apache.org/repos/asf/poi/trunk/src/scratchpad/examples/src/org/apache/poi/hssf/eventusermodel/examples/">subversion</link>.
|
||||
</p>
|
||||
<p>
|
||||
<em>In POI versions before 3.0.3, this code lived in the scratchpad section.
|
||||
<em>In POI versions before 3.0.3, this code lived in the scratchpad section.
|
||||
If you're using one of these older versions of POI, you will either
|
||||
need to include the scratchpad jar on your classpath, or build from a</em>
|
||||
<link href="../subversion.html">subversion checkout</link>.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
<anchor id="xssf_sax_api"/>
|
||||
<section><title>XSSF and SAX (Event API)</title>
|
||||
|
||||
<p>If memory footprint is an issue, then for XSSF, you can get at
|
||||
the underlying XML data, and process it yourself. This is intended
|
||||
for intermediate developers who are willing to learn a little bit of
|
||||
low level structure of .xlsx files, and who are happy processing
|
||||
XML in java. Its relatively simple to use, but requires a basic
|
||||
understanding of the file structure. The advantage provided is that
|
||||
you can read a XLSX file with a relatively small memory footprint.
|
||||
</p>
|
||||
<p>One important thing to note with the basic Event API is that it
|
||||
triggers events only for things actually stored within the file.
|
||||
With the XLSX file format, it is quite common for things that
|
||||
have yet to be edited to simply not exist in the file. This means
|
||||
there may well be apparent "gaps" in the record stream, which
|
||||
you need to work around.</p>
|
||||
<p>To use this API you construct an instance of
|
||||
org.apache.poi.xssf.eventmodel.XSSFReader. This will optionally
|
||||
provide a nice interace on the shared strings table, and the styles.
|
||||
It provides methods to get the raw xml data from the rest of the
|
||||
file, which you will then pass to SAX.</p>
|
||||
<p>This example shows how to get at a single known sheet, or at
|
||||
all sheets in the file. It is based on the example in svn
|
||||
src/examples/src/org/apache/poi/xssf/eventusermodel/exmaples/FromHowTo.java</p>
|
||||
<source><![CDATA[
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.poi.xssf.eventusermodel.XSSFReader;
|
||||
import org.apache.poi.xssf.model.SharedStringsTable;
|
||||
import org.openxml4j.opc.Package;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
public class ExampleEventUserModel {
|
||||
public void processOneSheet(String filename) throws Exception {
|
||||
Package pkg = Package.open(filename);
|
||||
XSSFReader r = new XSSFReader( pkg );
|
||||
SharedStringsTable sst = r.getSharedStringsTable();
|
||||
|
||||
XMLReader parser = fetchSheetParser(sst);
|
||||
|
||||
// rId2 found by processing the Workbook
|
||||
// Seems to either be rId# or rSheet#
|
||||
InputStream sheet2 = r.getSheet("rId2");
|
||||
InputSource sheetSource = new InputSource(sheet2);
|
||||
parser.parse(sheetSource);
|
||||
sheet2.close();
|
||||
}
|
||||
|
||||
public void processAllSheets(String filename) throws Exception {
|
||||
Package pkg = Package.open(filename);
|
||||
XSSFReader r = new XSSFReader( pkg );
|
||||
SharedStringsTable sst = r.getSharedStringsTable();
|
||||
|
||||
XMLReader parser = fetchSheetParser(sst);
|
||||
|
||||
Iterator<InputStream> sheets = r.getSheetsData();
|
||||
while(sheets.hasNext()) {
|
||||
System.out.println("Processing new sheet:\n");
|
||||
InputStream sheet = sheets.next();
|
||||
InputSource sheetSource = new InputSource(sheet);
|
||||
parser.parse(sheetSource);
|
||||
sheet.close();
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
|
||||
public XMLReader fetchSheetParser(SharedStringsTable sst) throws SAXException {
|
||||
XMLReader parser =
|
||||
XMLReaderFactory.createXMLReader(
|
||||
"org.apache.xerces.parsers.SAXParser"
|
||||
);
|
||||
ContentHandler handler = new SheetHandler(sst);
|
||||
parser.setContentHandler(handler);
|
||||
return parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* See org.xml.sax.helpers.DefaultHandler javadocs
|
||||
*/
|
||||
private static class SheetHandler extends DefaultHandler {
|
||||
private SharedStringsTable sst;
|
||||
private String lastContents;
|
||||
private boolean nextIsString;
|
||||
|
||||
private SheetHandler(SharedStringsTable sst) {
|
||||
this.sst = sst;
|
||||
}
|
||||
|
||||
public void startElement(String uri, String localName, String name,
|
||||
Attributes attributes) throws SAXException {
|
||||
// c => cell
|
||||
if(name.equals("c")) {
|
||||
// Print the cell reference
|
||||
System.out.print(attributes.getValue("r") + " - ");
|
||||
// Figure out if the value is an index in the SST
|
||||
String cellType = attributes.getValue("t");
|
||||
if(cellType != null && cellType.equals("s")) {
|
||||
nextIsString = true;
|
||||
} else {
|
||||
nextIsString = false;
|
||||
}
|
||||
}
|
||||
// Clear contents cache
|
||||
lastContents = "";
|
||||
}
|
||||
|
||||
public void endElement(String uri, String localName, String name)
|
||||
throws SAXException {
|
||||
// Process the last contents as required.
|
||||
// Do now, as characters() may be called more than once
|
||||
if(nextIsString) {
|
||||
int idx = Integer.parseInt(lastContents);
|
||||
lastContents = sst.getSharedStringAt(idx);
|
||||
}
|
||||
|
||||
// v => contents of a cell
|
||||
// Output after we've seen the string contents
|
||||
if(name.equals("v")) {
|
||||
System.out.println(lastContents);
|
||||
}
|
||||
}
|
||||
|
||||
public void characters(char[] ch, int start, int length)
|
||||
throws SAXException {
|
||||
lastContents += new String(ch, start, length);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
FromHowTo howto = new FromHowTo();
|
||||
howto.processOneSheet(args[0]);
|
||||
howto.processAllSheets(args[0]);
|
||||
}
|
||||
}
|
||||
]]></source>
|
||||
</section>
|
||||
|
||||
<anchor id="low_level_api" />
|
||||
<section><title>Low Level APIs</title>
|
||||
|
@ -21,7 +21,7 @@
|
||||
|
||||
<document>
|
||||
<header>
|
||||
<title>POI-HSSF - Java API To Access Microsoft Excel Format Files</title>
|
||||
<title>POI-HSSF and POI-XSSF - Java API To Access Microsoft Excel Format Files</title>
|
||||
<subtitle>Overview</subtitle>
|
||||
<authors>
|
||||
<person name="Andrew C. Oliver" email="acoliver@apache.org"/>
|
||||
@ -33,31 +33,38 @@
|
||||
<section>
|
||||
<title>Overview</title>
|
||||
|
||||
<p>HSSF is the POI Project's pure Java implementation of the Excel
|
||||
'97(-2007) file format. It <em>does not</em> support the new
|
||||
Excel 2007 .xlsx OOXML file format, which is not OLE2 based.</p>
|
||||
<p>HSSF provides a way to read spreadsheets create, modify, read and write XLS spreadsheets
|
||||
It provides:
|
||||
<p>HSSF is the POI Project's pure Java implementation of the
|
||||
Excel '97(-2007) file format. XSSF is the POI Project's pure
|
||||
Java implementation of the Excel 2007 OOXML (.xlsx) file
|
||||
format.</p>
|
||||
<p>HSSF and XSSF provides ways to read spreadsheets create,
|
||||
modify, read and write XLS spreadsheets. They provide:
|
||||
</p>
|
||||
<ul>
|
||||
<li>low level structures for those with special needs</li>
|
||||
<li>an eventmodel api for efficient read-only access</li>
|
||||
<li>a full usermodel api for creating, reading and modifying XLS files</li>
|
||||
</ul>
|
||||
<p>For people converting from pure HSSF usermodel, who wish
|
||||
to use the joint SS Usermodel for HSSF and XSSF support, then
|
||||
see the <link href="converting.html">ss usermodel converting
|
||||
guide</link>.
|
||||
</p>
|
||||
<p>
|
||||
An alternate way of generating a spreadsheet is via the <link href="http://cocoon.apache.org">Cocoon</link> serializer (yet you'll still be using HSSF indirectly).
|
||||
With Cocoon you can serialize any XML datasource (which might be a ESQL page outputting in SQL for instance) by simply
|
||||
applying the stylesheet and designating the serializer.
|
||||
</p>
|
||||
<p>
|
||||
If you're merely reading spreadsheet data, then use the eventmodel api
|
||||
in the org.apache.poi.hssf.eventusermodel package.
|
||||
If you're merely reading spreadsheet data, then use the
|
||||
eventmodel api in either the org.apache.poi.hssf.eventusermodel
|
||||
package, or the org.apache.poi.xssf.eventusermodel package, depending
|
||||
on your file format.
|
||||
</p>
|
||||
<p>
|
||||
If you're modifying spreadsheet data then use the usermodel api. You
|
||||
can also generate spreadsheets this way.
|
||||
</p>
|
||||
|
||||
</section>
|
||||
</body>
|
||||
</document>
|
@ -21,7 +21,7 @@
|
||||
|
||||
<document>
|
||||
<header>
|
||||
<title>Busy Developers' Guide to HSSF Features</title>
|
||||
<title>Busy Developers' Guide to HSSF and XSSF Features</title>
|
||||
<authors>
|
||||
<person email="user@poi.apache.org" name="Glen Stampoultzis" id="CO"/>
|
||||
<person email="user@poi.apache.org" name="Yegor Kozlov" id="YK"/>
|
||||
@ -30,8 +30,9 @@
|
||||
<body>
|
||||
<section><title>Busy Developers' Guide to Features</title>
|
||||
<p>
|
||||
Want to use HSSF read and write spreadsheets in a hurry? This guide is for you. If you're after
|
||||
more in-depth coverage of the HSSF user-API please consult the <link href="how-to.html">HOWTO</link>
|
||||
Want to use HSSF and XSSF read and write spreadsheets in a hurry? This
|
||||
guide is for you. If you're after more in-depth coverage of the HSSF and
|
||||
XSSF user-APIs, please consult the <link href="how-to.html">HOWTO</link>
|
||||
guide as it contains actual descriptions of how to use this stuff.
|
||||
</p>
|
||||
<section><title>Index of Features</title>
|
||||
@ -42,6 +43,7 @@
|
||||
<li><link href="#CreateDateCells">How to create date cells</link></li>
|
||||
<li><link href="#CellTypes">Working with different types of cells</link></li>
|
||||
<li><link href="#Iterator">Iterate over rows and cells</link></li>
|
||||
<li><link href="#CellContents">Getting the cell contents</link></li>
|
||||
<li><link href="#TextExtraction">Text Extraction</link></li>
|
||||
<li><link href="#Alignment">Aligning cells</link></li>
|
||||
<li><link href="#Borders">Working with borders</link></li>
|
||||
@ -76,18 +78,24 @@
|
||||
<anchor id="NewWorkbook"/>
|
||||
<section><title>New Workbook</title>
|
||||
<source>
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
Workbook wb = new HSSFWorkbook();
|
||||
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
|
||||
Workbook wb = new XSSFWorkbook();
|
||||
FileOutputStream fileOut = new FileOutputStream("workbook.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
</source>
|
||||
</section>
|
||||
<anchor id="NewSheet"/>
|
||||
<section><title>New Sheet</title>
|
||||
<source>
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sheet1 = wb.createSheet("new sheet");
|
||||
HSSFSheet sheet2 = wb.createSheet("second sheet");
|
||||
Workbook wb = new HSSFWorkbook();
|
||||
//Workbook wb = new XSSFWorkbook();
|
||||
Sheet sheet1 = wb.createSheet("new sheet");
|
||||
Sheet sheet2 = wb.createSheet("second sheet");
|
||||
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
@ -96,18 +104,21 @@
|
||||
<anchor id="CreateCells"/>
|
||||
<section><title>Creating Cells</title>
|
||||
<source>
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sheet = wb.createSheet("new sheet");
|
||||
Workbook wb = new HSSFWorkbook();
|
||||
//Workbook wb = new XSSFWorkbook();
|
||||
CreationHelper createHelper = wb.getCreationHelper();
|
||||
Sheet sheet = wb.createSheet("new sheet");
|
||||
|
||||
// Create a row and put some cells in it. Rows are 0 based.
|
||||
HSSFRow row = sheet.createRow((short)0);
|
||||
Row row = sheet.createRow((short)0);
|
||||
// Create a cell and put a value in it.
|
||||
HSSFCell cell = row.createCell((short)0);
|
||||
Cell cell = row.createCell((short)0);
|
||||
cell.setCellValue(1);
|
||||
|
||||
// Or do it on one line.
|
||||
row.createCell((short)1).setCellValue(1.2);
|
||||
row.createCell((short)2).setCellValue("This is a string");
|
||||
row.createCell((short)2).setCellValue(
|
||||
createHelper.createRichTextString("This is a string"));
|
||||
row.createCell((short)3).setCellValue(true);
|
||||
|
||||
// Write the output to a file
|
||||
@ -119,22 +130,25 @@
|
||||
<anchor id="CreateDateCells"/>
|
||||
<section><title>Creating Date Cells</title>
|
||||
<source>
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sheet = wb.createSheet("new sheet");
|
||||
Workbook wb = new HSSFWorkbook();
|
||||
//Workbook wb = new XSSFWorkbook();
|
||||
CreationHelper createHelper = wb.getCreationHelper();
|
||||
Sheet sheet = wb.createSheet("new sheet");
|
||||
|
||||
// Create a row and put some cells in it. Rows are 0 based.
|
||||
HSSFRow row = sheet.createRow((short)0);
|
||||
Row row = sheet.createRow((short)0);
|
||||
|
||||
// Create a cell and put a date value in it. The first cell is not styled
|
||||
// as a date.
|
||||
HSSFCell cell = row.createCell((short)0);
|
||||
Cell cell = row.createCell((short)0);
|
||||
cell.setCellValue(new Date());
|
||||
|
||||
// we style the second cell as a date (and time). It is important to
|
||||
// create a new cell style from the workbook otherwise you can end up
|
||||
// modifying the built in style and effecting not only this cell but other cells.
|
||||
HSSFCellStyle cellStyle = wb.createCellStyle();
|
||||
cellStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy h:mm"));
|
||||
CellStyle cellStyle = wb.createCellStyle();
|
||||
cellStyle.setDataFormat(
|
||||
createHelper.createDataFormat().getFormat("m/d/yy h:mm"));
|
||||
cell = row.createCell((short)1);
|
||||
cell.setCellValue(new Date());
|
||||
cell.setCellStyle(cellStyle);
|
||||
@ -241,21 +255,20 @@
|
||||
<p>Sometimes, you'd like to just iterate over all the rows in
|
||||
a sheet, or all the cells in a row. This is possible with
|
||||
a simple for loop.</p>
|
||||
<p>Luckily, this is very easy. HSSFRow defines a
|
||||
<p>Luckily, this is very easy. Row defines a
|
||||
<em>CellIterator</em> inner class to handle iterating over
|
||||
the cells (get one with a call to <em>row.cellIterator()</em>),
|
||||
and HSSFSheet provides a <em>rowIterator()</em> method to
|
||||
and Sheet provides a <em>rowIterator()</em> method to
|
||||
give an iterator over all the rows.</p>
|
||||
<p>(Unfortunately, due to the broken and
|
||||
backwards-incompatible way that Java 5 foreach loops were
|
||||
implemented, it isn't possible to use them on a codebase
|
||||
that supports Java 1.4, as POI does)</p>
|
||||
<p>Alternately, Sheet and Row both implement java.lang.Iterable,
|
||||
so if you're using Java 1.5, you can simply take advantage
|
||||
of the built in "foreach" support - see below.</p>
|
||||
<source>
|
||||
HSSFSheet sheet = wb.getSheetAt(0);
|
||||
Sheet sheet = wb.getSheetAt(0);
|
||||
for (Iterator rit = sheet.rowIterator(); rit.hasNext(); ) {
|
||||
HSSFRow row = (HSSFRow)rit.next();
|
||||
Row row = (Row)rit.next();
|
||||
for (Iterator cit = row.cellIterator(); cit.hasNext(); ) {
|
||||
HSSFCell cell = (HSSFCell)cit.next();
|
||||
Cell cell = (Cell)cit.next();
|
||||
// Do something here
|
||||
}
|
||||
}
|
||||
@ -271,27 +284,73 @@
|
||||
}
|
||||
</source>
|
||||
</section>
|
||||
<section><title>Iterate over rows and cells using Java 1.5 foreach loops - OOXML Branch Only</title>
|
||||
<section><title>Iterate over rows and cells using Java 1.5 foreach loops</title>
|
||||
<p>Sometimes, you'd like to just iterate over all the rows in
|
||||
a sheet, or all the cells in a row. If you are using Java
|
||||
5 or later, then this is especially handy, as it'll allow the
|
||||
new foreach loop support to work.</p>
|
||||
<p>Luckily, this is very easy. Both HSSFSheet and HSSFRow
|
||||
<p>Luckily, this is very easy. Both Sheet and Row
|
||||
implement <em>java.lang.Iterable</em> to allow foreach
|
||||
loops. For HSSFRow this allows access to the
|
||||
loops. For Row this allows access to the
|
||||
<em>CellIterator</em> inner class to handle iterating over
|
||||
the cells, and for HSSFSheet gives the
|
||||
the cells, and for Sheet gives the
|
||||
<em>rowIterator()</em> to iterator over all the rows.</p>
|
||||
<source>
|
||||
HSSFSheet sheet = wb.getSheetAt(0);
|
||||
for (HSSFRow row : sheet.rowIterator()) {
|
||||
for (HSSFCell cell : row.cellIterator()) {
|
||||
Sheet sheet = wb.getSheetAt(0);
|
||||
for (Row row : sheet) {
|
||||
for (Cell cell : row) {
|
||||
// Do something here
|
||||
}
|
||||
}
|
||||
</source>
|
||||
<note>This only works on the OOXML branch of POI</note>
|
||||
</section>
|
||||
|
||||
<anchor id="CellContents"/>
|
||||
<section><title>Getting the cell contents</title>
|
||||
<p>To get the contents of a cell, you first need to
|
||||
know what kind of cell it is (asking a string cell
|
||||
for its numeric contents will get you a
|
||||
NumberFormatException for example). So, you will
|
||||
want to switch on the cell's type, and then call
|
||||
the appropriate getter for that cell.</p>
|
||||
<p>In the code below, we loop over every cell
|
||||
in one sheet, print out the cell's reference
|
||||
(eg A3), and then the cell's contents.</p>
|
||||
<source>
|
||||
// import org.apache.poi.ss.usermodel.*;
|
||||
|
||||
Sheet sheet1 = wb.getSheetAt(0);
|
||||
for (Row row : sheet1) {
|
||||
for (Cell cell : row) {
|
||||
CellReference cellRef = new CellReference(row.getRowNum(), cell.getCellNum());
|
||||
System.out.print(cellRef.formatAsString());
|
||||
System.out.print(" - ");
|
||||
|
||||
switch(cell.getCellType()) {
|
||||
case Cell.CELL_TYPE_STRING:
|
||||
System.out.println(cell.getRichStringCellValue().getString());
|
||||
break;
|
||||
case Cell.CELL_TYPE_NUMERIC:
|
||||
if(DateUtil.isCellDateFormatted(cell)) {
|
||||
System.out.println(cell.getDateCellValue());
|
||||
} else {
|
||||
System.out.println(cell.getNumericCellValue());
|
||||
}
|
||||
break;
|
||||
case Cell.CELL_TYPE_BOOLEAN:
|
||||
System.out.println(cell.getBooleanCellValue());
|
||||
break;
|
||||
case Cell.CELL_TYPE_FORMULA:
|
||||
System.out.println(cell.getCellFormula());
|
||||
break;
|
||||
default:
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
</source>
|
||||
</section>
|
||||
|
||||
<anchor id="TextExtraction"/>
|
||||
<section><title>Text Extraction</title>
|
||||
<p>For most text extraction requirements, the standard
|
||||
@ -480,15 +539,16 @@ Examples:
|
||||
<anchor id="ReadWriteWorkbook"/>
|
||||
<section><title>Reading and Rewriting Workbooks</title>
|
||||
<source>
|
||||
POIFSFileSystem fs =
|
||||
new POIFSFileSystem(new FileInputStream("workbook.xls"));
|
||||
HSSFWorkbook wb = new HSSFWorkbook(fs);
|
||||
HSSFSheet sheet = wb.getSheetAt(0);
|
||||
HSSFRow row = sheet.getRow(2);
|
||||
HSSFCell cell = row.getCell((short)3);
|
||||
InputStream inp = new FileInputStream("workbook.xls");
|
||||
//InputStream inp = new FileInputStream("workbook.xlsx");
|
||||
|
||||
Workbook wb = WorkbookFactory.create(inp);
|
||||
Sheet sheet = wb.getSheetAt(0);
|
||||
Row row = sheet.getRow(2);
|
||||
Cell cell = row.getCell((short)3);
|
||||
if (cell == null)
|
||||
cell = row.createCell((short)3);
|
||||
cell.setCellType(HSSFCell.CELL_TYPE_STRING);
|
||||
cell.setCellType(Cell.CELL_TYPE_STRING);
|
||||
cell.setCellValue("a test");
|
||||
|
||||
// Write the output to a file
|
||||
@ -1143,7 +1203,8 @@ Examples:
|
||||
degenerate case of Named Range in that the 'group of cells' contains exactly one
|
||||
cell. You can create as well as refer to cells in a workbook by their named range.
|
||||
When working with Named Ranges, the classes: org.apache.poi.hssf.util.CellReference and
|
||||
& org.apache.poi.hssf.util.AreaReference are used.
|
||||
& org.apache.poi.hssf.util.AreaReference are used (these
|
||||
work for both XSSF and HSSF, despite the package name).
|
||||
</p>
|
||||
<p>
|
||||
Creating Named Range / Named Cell
|
||||
@ -1151,28 +1212,27 @@ Examples:
|
||||
<source>
|
||||
// setup code
|
||||
String sname = "TestSheet", cname = "TestName", cvalue = "TestVal";
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sheet = wb.createSheet(sname);
|
||||
Workbook wb = new HSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet(sname);
|
||||
sheet.createRow(0).createCell((short) 0).setCellValue(cvalue);
|
||||
|
||||
// 1. create named range for a single cell using areareference
|
||||
HSSFName namedCell = wb.createName();
|
||||
Name namedCell = wb.createName();
|
||||
namedCell.setNameName(cname);
|
||||
String reference = sname+"!A1:A1"; // area reference
|
||||
namedCell.setReference(reference);
|
||||
|
||||
// 2. create named range for a single cell using cellreference
|
||||
HSSFName namedCell = wb.createName();
|
||||
Name namedCell = wb.createName();
|
||||
namedCell.setNameName(cname);
|
||||
String reference = sname+"!A1"; // cell reference
|
||||
namedCell.setReference(reference);
|
||||
|
||||
// 3. create named range for an area using AreaReference
|
||||
HSSFName namedCell = wb.createName();
|
||||
Name namedCell = wb.createName();
|
||||
namedCell.setNameName(cname);
|
||||
String reference = sname+"!A1:C5"; // area reference
|
||||
namedCell.setReference(reference);
|
||||
|
||||
</source>
|
||||
<p>
|
||||
Reading from Named Range / Named Cell
|
||||
@ -1180,19 +1240,19 @@ Examples:
|
||||
<source>
|
||||
// setup code
|
||||
String cname = "TestName";
|
||||
HSSFWorkbook wb = getMyWorkbook(); // retrieve workbook
|
||||
Workbook wb = getMyWorkbook(); // retrieve workbook
|
||||
|
||||
// retrieve the named range
|
||||
int namedCellIdx = wb.getNameIndex(cellName);
|
||||
HSSFName aNamedCell = wb.getNameAt(namedCellIdx);
|
||||
Name aNamedCell = wb.getNameAt(namedCellIdx);
|
||||
|
||||
// retrieve the cell at the named range and test its contents
|
||||
AreaReference aref = new AreaReference(aNamedCell.getReference());
|
||||
CellReference[] crefs = aref.getAllReferencedCells();
|
||||
for (int i=0; i<crefs.length; i++) {
|
||||
HSSFSheet s = wb.getSheet(crefs[i].getSheetName());
|
||||
HSSFRow r = sheet.getRow(crefs[i].getRow());
|
||||
HSSFCell c = r.getCell(crefs[i].getCol());
|
||||
Sheet s = wb.getSheet(crefs[i].getSheetName());
|
||||
Row r = sheet.getRow(crefs[i].getRow());
|
||||
Cell c = r.getCell(crefs[i].getCol());
|
||||
// extract the cell contents based on cell type etc.
|
||||
}
|
||||
</source>
|
||||
@ -1202,12 +1262,12 @@ Examples:
|
||||
<source>
|
||||
// Setup code
|
||||
String cname = "TestName";
|
||||
HSSFWorkbook wb = getMyWorkbook(); // retrieve workbook
|
||||
Workbook wb = getMyWorkbook(); // retrieve workbook
|
||||
|
||||
// Retrieve the named range
|
||||
// Will be something like "$C$10,$D$12:$D$14";
|
||||
int namedCellIdx = wb.getNameIndex(cellName);
|
||||
HSSFName aNamedCell = wb.getNameAt(namedCellIdx);
|
||||
Name aNamedCell = wb.getNameAt(namedCellIdx);
|
||||
|
||||
// Retrieve the cell at the named range and test its contents
|
||||
// Will get back one AreaReference for C10, and
|
||||
@ -1219,68 +1279,85 @@ Examples:
|
||||
CellReference[] crefs = arefs[i].getCells();
|
||||
for (int j=0; j<crefs.length; j++) {
|
||||
// Check it turns into real stuff
|
||||
HSSFSheet s = wb.getSheet(crefs[j].getSheetName());
|
||||
HSSFRow r = s.getRow(crefs[j].getRow());
|
||||
HSSFCell c = r.getCell(crefs[j].getCol());
|
||||
Sheet s = wb.getSheet(crefs[j].getSheetName());
|
||||
Row r = s.getRow(crefs[j].getRow());
|
||||
Cell c = r.getCell(crefs[j].getCol());
|
||||
// Do something with this corner cell
|
||||
}
|
||||
}
|
||||
</source>
|
||||
<p>
|
||||
Note, when a cell is deleted, Excel does not delete the attached named range.
|
||||
As result, workbook can contain named ranges that point to cells that no longer exist.
|
||||
You should check the validity of a reference before constructing AreaReference
|
||||
</p>
|
||||
<source>
|
||||
</source>
|
||||
<p>
|
||||
Note, when a cell is deleted, Excel does not delete the
|
||||
attached named range. As result, workbook can contain
|
||||
named ranges that point to cells that no longer exist.
|
||||
You should check the validity of a reference before
|
||||
constructing AreaReference
|
||||
</p>
|
||||
<source>
|
||||
if(hssfName.isDeleted()){
|
||||
//named range points to a deleted cell.
|
||||
} else {
|
||||
AreaReference ref = new AreaReference(hssfName.getReference());
|
||||
}
|
||||
</source>
|
||||
</source>
|
||||
</section>
|
||||
<anchor id="CellComments"/>
|
||||
<section><title>Cell Comments</title>
|
||||
<section><title>Cell Comments - HSSF and XSSF (slight differences though)</title>
|
||||
<p>
|
||||
In Excel a comment is a kind of a text shape,
|
||||
so inserting a comment is very similar to placing a text box in a worksheet:
|
||||
In HSSF Excel, cell comments were added to the file format as a bit of a
|
||||
cludge. As such, comments are a kind of a text shape, so inserting a
|
||||
comment is very similar to placing a text box in a worksheet.
|
||||
</p>
|
||||
<p>
|
||||
In XSSF Excel, cell comments are more cleanly done. Each Sheet has a list
|
||||
of its comments, and they can be added much like other cell properties.
|
||||
</p>
|
||||
<p>
|
||||
Once you have created your comment, how you use it is very similar between
|
||||
HSSF and XSSF. It is only the creation of a new comment where things
|
||||
differ.
|
||||
</p>
|
||||
<p>
|
||||
For HSSF, the process is:
|
||||
</p>
|
||||
<source>
|
||||
HSSFWorkbook wb = new HSSFWorkbook();
|
||||
HSSFSheet sheet = wb.createSheet("Cell comments in POI HSSF");
|
||||
CreationHelper createHelper = wb.getCreationHelper();
|
||||
|
||||
// Create the drawing patriarch. This is the top level container for all shapes including cell comments.
|
||||
HSSFPatriarch patr = sheet.createDrawingPatriarch();
|
||||
|
||||
//create a cell in row 3
|
||||
HSSFCell cell1 = sheet.createRow(3).createCell((short)1);
|
||||
// Create a cell in row 3
|
||||
Cell cell1 = sheet.createRow(3).createCell((short)1);
|
||||
cell1.setCellValue(new HSSFRichTextString("Hello, World"));
|
||||
|
||||
//anchor defines size and position of the comment in worksheet
|
||||
HSSFComment comment1 = patr.createComment(new HSSFClientAnchor(0, 0, 0, 0, (short)4, 2, (short) 6, 5));
|
||||
// Anchor defines size and position of the comment in worksheet
|
||||
Comment comment1 = patr.createComment(new HSSFClientAnchor(0, 0, 0, 0, (short)4, 2, (short) 6, 5));
|
||||
|
||||
// set text in the comment
|
||||
comment1.setString(new HSSFRichTextString("We can set comments in POI"));
|
||||
comment1.setString(createHelper.createRichTextString("We can set comments in POI"));
|
||||
|
||||
//set comment author.
|
||||
//you can see it in the status bar when moving mouse over the commented cell
|
||||
// set comment author.
|
||||
// you can see it in the status bar when moving mouse over the commented cell
|
||||
comment1.setAuthor("Apache Software Foundation");
|
||||
|
||||
// The first way to assign comment to a cell is via HSSFCell.setCellComment method
|
||||
// The first way to assign comment to a cell is via Cell.setCellComment method
|
||||
cell1.setCellComment(comment1);
|
||||
|
||||
//create another cell in row 6
|
||||
HSSFCell cell2 = sheet.createRow(6).createCell((short)1);
|
||||
|
||||
// Create another cell in row 6
|
||||
Cell cell2 = sheet.createRow(6).createCell((short)1);
|
||||
cell2.setCellValue(36.6);
|
||||
|
||||
|
||||
// And a comment for it
|
||||
HSSFComment comment2 = patr.createComment(new HSSFClientAnchor(0, 0, 0, 0, (short)4, 8, (short) 6, 11));
|
||||
//modify background color of the comment
|
||||
// Modify background color of the comment
|
||||
comment2.setFillColor(204, 236, 255);
|
||||
|
||||
HSSFRichTextString string = new HSSFRichTextString("Normal body temperature");
|
||||
|
||||
//apply custom font to the text in the comment
|
||||
// Apply custom font to the text in the comment
|
||||
HSSFFont font = wb.createFont();
|
||||
font.setFontName("Arial");
|
||||
font.setFontHeightInPoints((short)10);
|
||||
@ -1289,19 +1366,58 @@ Examples:
|
||||
string.applyFont(font);
|
||||
|
||||
comment2.setString(string);
|
||||
//by default comments are hidden. This one is always visible.
|
||||
// By default comments are hidden. This one is always visible.
|
||||
comment2.setVisible(true);
|
||||
|
||||
comment2.setAuthor("Bill Gates");
|
||||
|
||||
|
||||
/**
|
||||
* The second way to assign comment to a cell is to implicitly specify its row and column.
|
||||
* Note, it is possible to set row and column of a non-existing cell.
|
||||
* It works, the commnet is visible.
|
||||
* It works, the comment is visible.
|
||||
*/
|
||||
comment2.setRow(6);
|
||||
comment2.setColumn((short)1);
|
||||
|
||||
FileOutputStream out = new FileOutputStream("poi_comment.xls");
|
||||
wb.write(out);
|
||||
out.close();
|
||||
</source>
|
||||
<p>
|
||||
For XSSF, the simpler process is:
|
||||
</p>
|
||||
<source>
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
XSSFSheet sheet = wb.createSheet("Cell comments in POI XSSF");
|
||||
CreationHelper createHelper = wb.getCreationHelper();
|
||||
|
||||
// Create a cell in row 3
|
||||
Cell cell1 = sheet.createRow(3).createCell((short)1);
|
||||
cell1.setCellValue(new XSSFRichTextString("Hello, World"));
|
||||
|
||||
// Create a comment, and set the text and author
|
||||
// (You can see the author in the status bar when moving mouse
|
||||
// over the commented cell)
|
||||
Comment comment1 = sheet.createComment();
|
||||
comment1.setString(createHelper.createRichTextString("We can set comments in POI"));
|
||||
comment1.setAuthor("Apache Software Foundation");
|
||||
|
||||
|
||||
// The first way to assign comment to a cell is via Cell.setCellComment method
|
||||
cell1.setCellComment(comment1);
|
||||
|
||||
|
||||
// The other way is to set the row and column
|
||||
// This could point to a cell that isn't defined, and the comment will
|
||||
// will still show up all the same
|
||||
Comment comment2 = sheet.createComment();
|
||||
comment2.setString(createHelper.createRichTextString("Comment for missing cell"));
|
||||
comment2.setAuthor("Apache POI");
|
||||
comment2.setRow(11);
|
||||
comment2.setColumn(1);
|
||||
|
||||
// Write out
|
||||
FileOutputStream out = new FileOutputStream("poi_comment.xls");
|
||||
wb.write(out);
|
||||
out.close();
|
||||
@ -1310,16 +1426,17 @@ Examples:
|
||||
Reading cell comments
|
||||
</p>
|
||||
<source>
|
||||
HSSFCell cell = sheet.get(3).getColumn((short)1);
|
||||
HSSFComment comment = cell.getCellComment();
|
||||
Cell cell = sheet.get(3).getColumn((short)1);
|
||||
Comment comment = cell.getCellComment();
|
||||
if (comment != null) {
|
||||
HSSFRichTextString str = comment.getString();
|
||||
RichTextString str = comment.getString();
|
||||
String author = comment.getAuthor();
|
||||
}
|
||||
// alternatively you can retrieve cell comments by (row, column)
|
||||
comment = sheet.getCellComment(3, 1);
|
||||
</source>
|
||||
</section>
|
||||
|
||||
<anchor id="Autofit"/>
|
||||
<section><title>Adjust column width to fit the contents</title>
|
||||
<source>
|
@ -43,6 +43,34 @@
|
||||
<action dev="POI-DEVELOPERS" type="fix">45778 - fixed ObjRecord to read ftLbsData properly</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">46053 - fixed evaluation cache dependency analysis when changing blank cells</action>
|
||||
</release>
|
||||
<release version="3.5-beta3" date="2008-09-26">
|
||||
<action dev="POI-DEVELOPERS" type="fix">45518 - Fix up ColumnHelper to output valid col tags, by making 1 based and 0 based bits clearer, and using the right ones</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">45676 - Handle very long cells in the XSSF EventUserModel example</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Initial ExtractorFactory support for building TextExtractors for embeded documents</action>
|
||||
</release>
|
||||
<release version="3.5-beta2" date="2008-08-20">
|
||||
<action dev="POI-DEVELOPERS" type="add">Support stripping XSSF header and footer fields (eg page number) out of header and footer text if required</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Add POIXMLPropertiesTextExtractor, which provides to the OOXML file formats a similar function to HPSF's HPSFPropertiesExtractor</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45539 - Improve XWPFWordExtractor to extract headers and footers</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">Improve how XWPF handles paragraph text</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Support in XWPF handles headers and footers</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45592 - Improve XWPF text extraction to include tables always, and picture text where possible</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45545 - Improve XSLF usermodel support, and include XSLF comments in extracted text</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45540 - Fix XSSF header and footer support, and include headers and footers in the output of XSSFExcelExtractor</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45431 - Support for .xlsm files, sufficient for simple files to be loaded by excel without warning</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">New class org.apache.poi.hssf.record.RecordFormatException, which DDF uses instead of the HSSF version, and the HSSF version inherits from</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">45431 - Partial support for .xlm files. Not quite enough for excel to load them though</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">45430 - Correct named range sheet reporting when no local sheet id is given in the xml</action>
|
||||
</release>
|
||||
<release version="3.5-beta1" date="2008-07-18">
|
||||
<action dev="POI-DEVELOPERS" type="add">45018 - Support for fetching embeded documents from within an OOXML file</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Port support for setting a policy on missing / blank cells when fetching, to XSSF too</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Common text extraction factory, which returns the correct POITextExtractor for the supplied data</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Text Extraction support for the new OOXML files (.xlsx, .docx and .pptx)</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Initial support for processing OOXML Excel files (.xlsx), both directly through XSSF, and also through the new common UserModel</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Created a common interface for handling PowerPoint files, irrespective of if they are .ppt or .pptx</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
|
||||
</release>
|
||||
<release version="3.2-FINAL" date="2008-10-19">
|
||||
<action dev="POI-DEVELOPERS" type="fix">45866 - allowed for change of unicode compression across Continue records</action>
|
||||
<action dev="POI-DEVELOPERS" type="fix">45964 - support for link formulas in Text Objects</action>
|
||||
@ -192,6 +220,7 @@
|
||||
</release>
|
||||
<release version="3.1-beta1" date="2008-04-28">
|
||||
<action dev="POI-DEVELOPERS" type="fix">44857 - Avoid OOM on unknown escher records when EscherMetafileBlip is incorrect</action>
|
||||
>>>>>>> .merge-right.r653675
|
||||
<action dev="POI-DEVELOPERS" type="add">HSLF: Support for getting embedded sounds from slide show </action>
|
||||
<action dev="POI-DEVELOPERS" type="add">HSLF: Initial support for rendering slides into images</action>
|
||||
<action dev="POI-DEVELOPERS" type="add">HSLF: Support for getting OLE object data from slide show </action>
|
||||
|
@ -31,7 +31,7 @@
|
||||
<menu label="Projekt">
|
||||
<menu-item label="Überblick" href="../../overview.html"/>
|
||||
<menu-item label="POIFS" href="../../poifs/index.html"/>
|
||||
<menu-item label="HSSF" href="../../hssf/index.html"/>
|
||||
<menu-item label="HSSF" href="../../spreadsheet/index.html"/>
|
||||
<menu-item label="HWPF" href="../../hwpf/index.html"/>
|
||||
<menu-item label="HPSF" href="../../hpsf/index.html"/>
|
||||
<menu-item label="POI-Utils" href="../../utils/index.html"/>
|
||||
|
@ -154,7 +154,7 @@
|
||||
HSSF ist unsere Portierung des Microsoft Excel 97(-2002)
|
||||
Dateiformats in reinem Java. Es unterstützt Lesen und
|
||||
Schreiben. Mehr Informationen gibt es auf der
|
||||
<link href="../../hssf/index.html">HSSF-Seite</link>.
|
||||
<link href="../../spreadsheet/index.html">HSSF-Seite</link>.
|
||||
</p>
|
||||
</section>
|
||||
<section><title>HWPF</title>
|
||||
|
@ -35,7 +35,7 @@
|
||||
<menu label="Proyecto">
|
||||
<menu-item label="Descripción General" href="overview.html"/>
|
||||
<menu-item label="POIFS [EN]" href="../../poifs/index.html"/>
|
||||
<menu-item label="HSSF [EN]" href="../../hssf/index.html"/>
|
||||
<menu-item label="HSSF [EN]" href="../../spreadsheet/index.html"/>
|
||||
<menu-item label="HWPF [EN]" href="../../hwpf/index.html"/>
|
||||
<menu-item label="HPSF [EN]" href="../../hpsf/index.html"/>
|
||||
<menu-item label="POI-Utils [EN]" href="../../utils/index.html"/>
|
||||
|
@ -99,7 +99,7 @@
|
||||
El
|
||||
<link href="http://www.lbank.lt/">Banco de Lituania</link>
|
||||
genera informes de datos estadísticos financieros en formato Excel
|
||||
utilizando el API <link href="http://jakarta.apache.org/poi/hssf/">
|
||||
utilizando el API <link href="http://jakarta.apache.org/poi/spreadsheet/">
|
||||
HSSF</link> del proyecto
|
||||
<link href="http://jakarta.apache.org/poi/">Jakarta POI</link>
|
||||
El sistema está basado en Oracle JServer y utiliza
|
||||
|
@ -86,7 +86,7 @@
|
||||
</section>
|
||||
<section><title>HSSF</title>
|
||||
<p>HSSF es nuestra adaptación del formato de fichero de Microsoft Excel 97(-2002) (BIFF8) a Java puro. Soporta lectura y
|
||||
escritura. Por favor, vea <link href="../../hssf/index.html">la página del proyecto HSSF [EN]</link> para más información.</p>
|
||||
escritura. Por favor, vea <link href="../../spreadsheet/index.html">la página del proyecto HSSF [EN]</link> para más información.</p>
|
||||
</section>
|
||||
<section><title>HWPF</title>
|
||||
<p>HWPF es nuestra adaptación del formato de fichero de Microsoft Word 97 a Java puro. Soporta lectura y escritura.
|
||||
|
@ -50,7 +50,7 @@
|
||||
|
||||
<section><title>HSSF</title>
|
||||
<p>
|
||||
<link href="../../hssf/index.html">HSSF [EN]</link> es el conjunto de APIs para la lectura y
|
||||
<link href="../../spreadsheet/index.html">HSSF [EN]</link> es el conjunto de APIs para la lectura y
|
||||
escritura de hojas de cálculo de Microsoft Excel 97(-XP) utilizando (únicamente) Java.
|
||||
</p>
|
||||
</section>
|
||||
|
@ -92,7 +92,7 @@ row.getRowNum() %> </b>
|
||||
%>
|
||||
<%= "CELL col="
|
||||
|
||||
+ cell.getCellNum()
|
||||
+ cell.getColumnIndex()
|
||||
+ " VALUE=" + value %>
|
||||
<%
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
package org.apache.poi.hssf.usermodel.examples;
|
||||
|
||||
import org.apache.poi.hssf.usermodel.*;
|
||||
import org.apache.poi.hssf.util.Region;
|
||||
import org.apache.poi.ss.util.Region;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.FileOutputStream;
|
||||
|
@ -0,0 +1,138 @@
|
||||
/* ====================================================================
|
||||
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.xssf.eventusermodel.examples;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.poi.xssf.eventusermodel.XSSFReader;
|
||||
import org.apache.poi.xssf.model.SharedStringsTable;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
||||
import org.openxml4j.opc.Package;
|
||||
import org.xml.sax.Attributes;
|
||||
import org.xml.sax.ContentHandler;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xml.sax.helpers.DefaultHandler;
|
||||
import org.xml.sax.helpers.XMLReaderFactory;
|
||||
|
||||
/**
|
||||
* Various things from the how-to documentation
|
||||
*/
|
||||
public class FromHowTo {
|
||||
public void processOneSheet(String filename) throws Exception {
|
||||
Package pkg = Package.open(filename);
|
||||
XSSFReader r = new XSSFReader( pkg );
|
||||
SharedStringsTable sst = r.getSharedStringsTable();
|
||||
|
||||
XMLReader parser = fetchSheetParser(sst);
|
||||
|
||||
// rId2 found by processing the Workbook
|
||||
// Seems to either be rId# or rSheet#
|
||||
InputStream sheet2 = r.getSheet("rId2");
|
||||
InputSource sheetSource = new InputSource(sheet2);
|
||||
parser.parse(sheetSource);
|
||||
sheet2.close();
|
||||
}
|
||||
|
||||
public void processAllSheets(String filename) throws Exception {
|
||||
Package pkg = Package.open(filename);
|
||||
XSSFReader r = new XSSFReader( pkg );
|
||||
SharedStringsTable sst = r.getSharedStringsTable();
|
||||
|
||||
XMLReader parser = fetchSheetParser(sst);
|
||||
|
||||
Iterator<InputStream> sheets = r.getSheetsData();
|
||||
while(sheets.hasNext()) {
|
||||
System.out.println("Processing new sheet:\n");
|
||||
InputStream sheet = sheets.next();
|
||||
InputSource sheetSource = new InputSource(sheet);
|
||||
parser.parse(sheetSource);
|
||||
sheet.close();
|
||||
System.out.println("");
|
||||
}
|
||||
}
|
||||
|
||||
public XMLReader fetchSheetParser(SharedStringsTable sst) throws SAXException {
|
||||
XMLReader parser =
|
||||
XMLReaderFactory.createXMLReader(
|
||||
"org.apache.xerces.parsers.SAXParser"
|
||||
);
|
||||
ContentHandler handler = new SheetHandler(sst);
|
||||
parser.setContentHandler(handler);
|
||||
return parser;
|
||||
}
|
||||
|
||||
/**
|
||||
* See org.xml.sax.helpers.DefaultHandler javadocs
|
||||
*/
|
||||
private static class SheetHandler extends DefaultHandler {
|
||||
private SharedStringsTable sst;
|
||||
private String lastContents;
|
||||
private boolean nextIsString;
|
||||
|
||||
private SheetHandler(SharedStringsTable sst) {
|
||||
this.sst = sst;
|
||||
}
|
||||
|
||||
public void startElement(String uri, String localName, String name,
|
||||
Attributes attributes) throws SAXException {
|
||||
// c => cell
|
||||
if(name.equals("c")) {
|
||||
// Print the cell reference
|
||||
System.out.print(attributes.getValue("r") + " - ");
|
||||
// Figure out if the value is an index in the SST
|
||||
String cellType = attributes.getValue("t");
|
||||
if(cellType != null && cellType.equals("s")) {
|
||||
nextIsString = true;
|
||||
} else {
|
||||
nextIsString = false;
|
||||
}
|
||||
}
|
||||
// Clear contents cache
|
||||
lastContents = "";
|
||||
}
|
||||
|
||||
public void endElement(String uri, String localName, String name)
|
||||
throws SAXException {
|
||||
// Process the last contents as required.
|
||||
// Do now, as characters() may be called more than once
|
||||
if(nextIsString) {
|
||||
int idx = Integer.parseInt(lastContents);
|
||||
lastContents = new XSSFRichTextString(sst.getEntryAt(idx)).toString();
|
||||
}
|
||||
|
||||
// v => contents of a cell
|
||||
// Output after we've seen the string contents
|
||||
if(name.equals("v")) {
|
||||
System.out.println(lastContents);
|
||||
}
|
||||
}
|
||||
|
||||
public void characters(char[] ch, int start, int length)
|
||||
throws SAXException {
|
||||
lastContents += new String(ch, start, length);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
FromHowTo howto = new FromHowTo();
|
||||
howto.processOneSheet(args[0]);
|
||||
howto.processAllSheets(args[0]);
|
||||
}
|
||||
}
|
73
src/examples/src/org/apache/poi/xssf/usermodel/examples/AligningCells.java
Executable file
73
src/examples/src/org/apache/poi/xssf/usermodel/examples/AligningCells.java
Executable file
@ -0,0 +1,73 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STHorizontalAlignment;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
/**
|
||||
* Shows how various alignment options work.
|
||||
*/
|
||||
public class AligningCells {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
|
||||
Sheet sheet = wb.createSheet();
|
||||
Row row = sheet.createRow((short) 2);
|
||||
row.setHeightInPoints(30);
|
||||
for (int i = 0; i < 8; i++) {
|
||||
//column width is set in units of 1/256th of a character width
|
||||
sheet.setColumnWidth(i, 256*15);
|
||||
}
|
||||
|
||||
createCell(wb, row, (short) 0, XSSFCellStyle.ALIGN_CENTER, XSSFCellStyle.VERTICAL_BOTTOM);
|
||||
createCell(wb, row, (short) 1, XSSFCellStyle.ALIGN_CENTER_SELECTION, XSSFCellStyle.VERTICAL_BOTTOM);
|
||||
createCell(wb, row, (short) 2, XSSFCellStyle.ALIGN_FILL, XSSFCellStyle.VERTICAL_CENTER);
|
||||
createCell(wb, row, (short) 3, XSSFCellStyle.ALIGN_GENERAL, XSSFCellStyle.VERTICAL_CENTER);
|
||||
createCell(wb, row, (short) 4, XSSFCellStyle.ALIGN_JUSTIFY, XSSFCellStyle.VERTICAL_JUSTIFY);
|
||||
createCell(wb, row, (short) 5, XSSFCellStyle.ALIGN_LEFT, XSSFCellStyle.VERTICAL_TOP);
|
||||
createCell(wb, row, (short) 6, XSSFCellStyle.ALIGN_RIGHT, XSSFCellStyle.VERTICAL_TOP);
|
||||
|
||||
// Write the output to a file
|
||||
FileOutputStream fileOut = new FileOutputStream("xssf-align.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a cell and aligns it a certain way.
|
||||
*
|
||||
* @param wb the workbook
|
||||
* @param row the row to create the cell in
|
||||
* @param column the column number to create the cell in
|
||||
* @param halign the horizontal alignment for the cell.
|
||||
*/
|
||||
private static void createCell(Workbook wb, Row row, short column, short halign, short valign) {
|
||||
Cell cell = row.createCell(column);
|
||||
cell.setCellValue(new XSSFRichTextString("Align It"));
|
||||
CellStyle cellStyle = wb.createCellStyle();
|
||||
cellStyle.setAlignment(halign);
|
||||
cellStyle.setVerticalAlignment(valign);
|
||||
cell.setCellStyle(cellStyle);
|
||||
}
|
||||
|
||||
}
|
310
src/examples/src/org/apache/poi/xssf/usermodel/examples/BusinessPlan.java
Executable file
310
src/examples/src/org/apache/poi/xssf/usermodel/examples/BusinessPlan.java
Executable file
@ -0,0 +1,310 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.Date;
|
||||
import java.util.Calendar;
|
||||
import java.io.FileOutputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
/**
|
||||
* A business plan demo
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public class BusinessPlan {
|
||||
|
||||
private static SimpleDateFormat fmt = new SimpleDateFormat("dd-MMM");
|
||||
|
||||
private static final String[] days = {
|
||||
"ID", "Project Name", "Owner", "Days", "Start", "End"};
|
||||
|
||||
//sample data to fill the sheet.
|
||||
private static final String[][] data = {
|
||||
{"1.0", "Marketing Research Tactical Plan", "R. Ihrig", "70", "9-Jul", null,
|
||||
"x", "x", "x", "x", "x", "x", "x", "x", "x", "x", "x"},
|
||||
null,
|
||||
{"1.1", "Scope Definition Phase", "R. Ihrig", "10", "9-Jul", null,
|
||||
"x", "x", null, null, null, null, null, null, null, null, null},
|
||||
{"1.1.1", "Define research objectives", "R. Ihrig", "3", "9-Jul", null,
|
||||
"x", null, null, null, null, null, null, null, null, null, null},
|
||||
{"1.1.2", "Define research requirements", "S. Abbas", "7", "10-Jul", null,
|
||||
"x", "x", null, null, null, null, null, null, null, null, null},
|
||||
{"1.1.3", "Determine in-house resource or hire vendor", "R. Ihrig", "2", "15-Jul", null,
|
||||
"x", "x", null, null, null, null, null, null, null, null, null},
|
||||
null,
|
||||
{"1.2", "Vendor Selection Phase", "R. Ihrig", "19", "19-Jul", null,
|
||||
null, "x", "x", "x", "x", null, null, null, null, null, null},
|
||||
{"1.2.1", "Define vendor selection criteria", "R. Ihrig", "3", "19-Jul", null,
|
||||
null, "x", null, null, null, null, null, null, null, null, null},
|
||||
{"1.2.2", "Develop vendor selection questionnaire", "S. Abbas, T. Wang", "2", "22-Jul", null,
|
||||
null, "x", "x", null, null, null, null, null, null, null, null},
|
||||
{"1.2.3", "Develop Statement of Work", "S. Abbas", "4", "26-Jul", null,
|
||||
null, null, "x", "x", null, null, null, null, null, null, null},
|
||||
{"1.2.4", "Evaluate proposal", "R. Ihrig, S. Abbas", "4", "2-Aug", null,
|
||||
null, null, null, "x", "x", null, null, null, null, null, null},
|
||||
{"1.2.5", "Select vendor", "R. Ihrig", "1", "6-Aug", null,
|
||||
null, null, null, null, "x", null, null, null, null, null, null},
|
||||
null,
|
||||
{"1.3", "Research Phase", "Y. Li", "47", "9-Aug", null,
|
||||
null, null, null, null, "x", "x", "x", "x", "x", "x", "x"},
|
||||
{"1.3.1", "Develop market research information needs questionnaire", "Y. Li", "2", "9-Aug", null,
|
||||
null, null, null, null, "x", null, null, null, null, null, null},
|
||||
{"1.3.2", "Interview marketing group for market research needs", "Y. Li", "2", "11-Aug", null,
|
||||
null, null, null, null, "x", "x", null, null, null, null, null},
|
||||
{"1.3.3", "Document information needs", "Y. Li, S. Abbas", "1", "13-Aug", null,
|
||||
null, null, null, null, null, "x", null, null, null, null, null},
|
||||
};
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
Map<String, XSSFCellStyle> styles = createStyles(wb);
|
||||
|
||||
XSSFSheet sheet = wb.createSheet("Plan");
|
||||
|
||||
//turn off gridlines
|
||||
sheet.setDisplayGridlines(false);
|
||||
sheet.setPrintGridlines(false);
|
||||
XSSFPrintSetup printSetup = sheet.getPrintSetup();
|
||||
printSetup.setOrientation(PrintOrientation.LANDSCAPE);
|
||||
sheet.setFitToPage(true);
|
||||
sheet.setHorizontallyCenter(true);
|
||||
|
||||
//the header row: centered text in 48pt font
|
||||
XSSFRow headerRow = sheet.createRow(0);
|
||||
headerRow.setHeightInPoints(12.75f);
|
||||
for (int i = 0; i < days.length; i++) {
|
||||
XSSFCell cell = headerRow.createCell(i);
|
||||
cell.setCellValue(days[i]);
|
||||
cell.setCellStyle(styles.get("header"));
|
||||
}
|
||||
//columns for 11 weeks starting from 9-Jul
|
||||
calendar.setTime(fmt.parse("9-Jul"));
|
||||
calendar.set(Calendar.YEAR, year);
|
||||
for (int i = 0; i < 11; i++) {
|
||||
XSSFCell cell = headerRow.createCell(days.length + i);
|
||||
cell.setCellValue(calendar);
|
||||
cell.setCellStyle(styles.get("header_date"));
|
||||
calendar.roll(Calendar.WEEK_OF_YEAR, true);
|
||||
}
|
||||
|
||||
sheet.createFreezePane(0, 1);
|
||||
XSSFRow row;
|
||||
XSSFCell cell;
|
||||
|
||||
int rownum = 1;
|
||||
for (int i = 0; i < data.length; i++, rownum++) {
|
||||
row = sheet.createRow(rownum);
|
||||
if(data[i] == null) continue;
|
||||
|
||||
for (int j = 0; j < data[i].length; j++) {
|
||||
cell = row.createCell(j);
|
||||
String styleName;
|
||||
boolean isHeader = i == 0 || data[i-1] == null;
|
||||
switch(j){
|
||||
case 0:
|
||||
if(isHeader) {
|
||||
styleName = "cell_b";
|
||||
cell.setCellValue(Double.parseDouble(data[i][j]));
|
||||
} else {
|
||||
styleName = "cell_normal";
|
||||
cell.setCellValue(data[i][j]);
|
||||
}
|
||||
break;
|
||||
case 1:
|
||||
if(isHeader) {
|
||||
styleName = i == 0 ? "cell_h" : "cell_bb";
|
||||
} else {
|
||||
styleName = "cell_indented";
|
||||
}
|
||||
cell.setCellValue(data[i][j]);
|
||||
break;
|
||||
case 2:
|
||||
styleName = isHeader ? "cell_b" : "cell_normal";
|
||||
cell.setCellValue(data[i][j]);
|
||||
break;
|
||||
case 3:
|
||||
styleName = isHeader ? "cell_b_centered" : "cell_normal_centered";
|
||||
cell.setCellValue(Integer.parseInt(data[i][j]));
|
||||
break;
|
||||
case 4: {
|
||||
calendar.setTime(fmt.parse(data[i][j]));
|
||||
calendar.set(Calendar.YEAR, year);
|
||||
cell.setCellValue(calendar);
|
||||
styleName = isHeader ? "cell_b_date" : "cell_normal_date";
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
int r = rownum + 1;
|
||||
String fmla = "IF(AND(D"+r+",E"+r+"),E"+r+"+D"+r+",\"\")";
|
||||
cell.setCellFormula(fmla);
|
||||
styleName = isHeader ? "cell_bg" : "cell_g";
|
||||
break;
|
||||
}
|
||||
default:
|
||||
styleName = data[i][j] != null ? "cell_blue" : "cell_normal";
|
||||
}
|
||||
|
||||
cell.setCellStyle(styles.get(styleName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
sheet.groupRow(5, 7);
|
||||
sheet.groupRow(10, 14);
|
||||
sheet.groupRow(17, 19);
|
||||
|
||||
sheet.setColumnWidth(0, 256*6);
|
||||
sheet.setColumnWidth(1, 256*33);
|
||||
sheet.setColumnWidth(2, 256*20);
|
||||
sheet.setZoom(75);
|
||||
|
||||
|
||||
// Write the output to a file
|
||||
FileOutputStream out = new FileOutputStream("xssf-plan.xlsx");
|
||||
wb.write(out);
|
||||
out.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* cell styles used for formatting calendar sheets
|
||||
*/
|
||||
private static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb){
|
||||
Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();
|
||||
XSSFDataFormat df = wb.createDataFormat();
|
||||
|
||||
XSSFCellStyle style;
|
||||
XSSFFont headerFont = wb.createFont();
|
||||
headerFont.setBold(true);
|
||||
style = createBorderedStyle(wb);
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(204, 204, 255)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setFont(headerFont);
|
||||
styles.put("header", style);
|
||||
|
||||
style = createBorderedStyle(wb);
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(204, 204, 255)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setFont(headerFont);
|
||||
style.setDataFormat(df.getFormat("d-mmm"));
|
||||
styles.put("header_date", style);
|
||||
|
||||
XSSFFont font1 = wb.createFont();
|
||||
font1.setBold(true);
|
||||
style = createBorderedStyle(wb);
|
||||
style.setAlignment(HorizontalAlignment.LEFT);
|
||||
style.setFont(font1);
|
||||
styles.put("cell_b", style);
|
||||
|
||||
style = createBorderedStyle(wb);
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setFont(font1);
|
||||
styles.put("cell_b_centered", style);
|
||||
|
||||
style = createBorderedStyle(wb);
|
||||
style.setAlignment(HorizontalAlignment.RIGHT);
|
||||
style.setFont(font1);
|
||||
style.setDataFormat(df.getFormat("d-mmm"));
|
||||
styles.put("cell_b_date", style);
|
||||
|
||||
style = createBorderedStyle(wb);
|
||||
style.setAlignment(HorizontalAlignment.RIGHT);
|
||||
style.setFont(font1);
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(228, 228, 228)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setDataFormat(df.getFormat("d-mmm"));
|
||||
styles.put("cell_g", style);
|
||||
|
||||
XSSFFont font2 = wb.createFont();
|
||||
font2.setColor(IndexedColors.BLUE.getIndex());
|
||||
font2.setBold(true);
|
||||
style = createBorderedStyle(wb);
|
||||
style.setAlignment(HorizontalAlignment.LEFT);
|
||||
style.setFont(font2);
|
||||
styles.put("cell_bb", style);
|
||||
|
||||
style = createBorderedStyle(wb);
|
||||
style.setAlignment(HorizontalAlignment.RIGHT);
|
||||
style.setFont(font1);
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(228, 228, 228)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setDataFormat(df.getFormat("d-mmm"));
|
||||
styles.put("cell_bg", style);
|
||||
|
||||
XSSFFont font3 = wb.createFont();
|
||||
font3.setFontHeightInPoints((short)14);
|
||||
font3.setColor(IndexedColors.DARK_BLUE.getIndex());
|
||||
font3.setBold(true);
|
||||
style = createBorderedStyle(wb);
|
||||
style.setAlignment(HorizontalAlignment.LEFT);
|
||||
style.setFont(font3);
|
||||
style.setWrapText(true);
|
||||
styles.put("cell_h", style);
|
||||
|
||||
style = createBorderedStyle(wb);
|
||||
style.setAlignment(HorizontalAlignment.LEFT);
|
||||
style.setWrapText(true);
|
||||
styles.put("cell_normal", style);
|
||||
|
||||
style = createBorderedStyle(wb);
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setWrapText(true);
|
||||
styles.put("cell_normal_centered", style);
|
||||
|
||||
style = createBorderedStyle(wb);
|
||||
style.setAlignment(HorizontalAlignment.RIGHT);
|
||||
style.setWrapText(true);
|
||||
style.setDataFormat(df.getFormat("d-mmm"));
|
||||
styles.put("cell_normal_date", style);
|
||||
|
||||
style = createBorderedStyle(wb);
|
||||
style.setAlignment(HorizontalAlignment.LEFT);
|
||||
style.setIndention((short)1);
|
||||
style.setWrapText(true);
|
||||
styles.put("cell_indented", style);
|
||||
|
||||
style = createBorderedStyle(wb);
|
||||
style.setFillForegroundColor(IndexedColors.BLUE.getIndex());
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
styles.put("cell_blue", style);
|
||||
|
||||
return styles;
|
||||
}
|
||||
|
||||
private static XSSFCellStyle createBorderedStyle(XSSFWorkbook wb){
|
||||
XSSFCellStyle style = wb.createCellStyle();
|
||||
style.setBorderRight(BorderStyle.THIN);
|
||||
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
||||
style.setBorderLeft(BorderStyle.THIN);
|
||||
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
||||
style.setBorderTop(BorderStyle.THIN);
|
||||
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
||||
return style;
|
||||
}
|
||||
}
|
224
src/examples/src/org/apache/poi/xssf/usermodel/examples/CalendarDemo.java
Executable file
224
src/examples/src/org/apache/poi/xssf/usermodel/examples/CalendarDemo.java
Executable file
@ -0,0 +1,224 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.Calendar;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* A monthly calendar created using Apache POI. Each month is on a separate sheet.
|
||||
* <pre>
|
||||
* Usage:
|
||||
* CalendarDemo <year>
|
||||
* </pre>
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public class CalendarDemo {
|
||||
|
||||
private static final String[] days = {
|
||||
"Sunday", "Monday", "Tuesday",
|
||||
"Wednesday", "Thursday", "Friday", "Saturday"};
|
||||
|
||||
private static final String[] months = {
|
||||
"January", "February", "March","April", "May", "June","July", "August",
|
||||
"September","October", "November", "December"};
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
if(args.length > 0) calendar.set(Calendar.YEAR, Integer.parseInt(args[0]));
|
||||
|
||||
int year = calendar.get(Calendar.YEAR);
|
||||
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
Map<String, XSSFCellStyle> styles = createStyles(wb);
|
||||
|
||||
for (int month = 0; month < 12; month++) {
|
||||
calendar.set(Calendar.MONTH, month);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||
//create a sheet for each month
|
||||
XSSFSheet sheet = wb.createSheet(months[month]);
|
||||
|
||||
//turn off gridlines
|
||||
sheet.setDisplayGridlines(false);
|
||||
sheet.setPrintGridlines(false);
|
||||
XSSFPrintSetup printSetup = sheet.getPrintSetup();
|
||||
printSetup.setOrientation(PrintOrientation.LANDSCAPE);
|
||||
sheet.setFitToPage(true);
|
||||
sheet.setHorizontallyCenter(true);
|
||||
|
||||
//the header row: centered text in 48pt font
|
||||
XSSFRow headerRow = sheet.createRow(0);
|
||||
headerRow.setHeightInPoints(80);
|
||||
XSSFCell titleCell = headerRow.createCell(0);
|
||||
titleCell.setCellValue(months[month] + " " + year);
|
||||
titleCell.setCellStyle(styles.get("title"));
|
||||
sheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$N$1"));
|
||||
|
||||
//header with month titles
|
||||
XSSFRow monthRow = sheet.createRow(1);
|
||||
for (int i = 0; i < days.length; i++) {
|
||||
//for compatibility with HSSF we have to set column width in units of 1/256th of a character width
|
||||
sheet.setColumnWidth(i*2, 5*256); //the column is 5 characters wide
|
||||
sheet.setColumnWidth(i*2 + 1, 13*256); //the column is 13 characters wide
|
||||
sheet.addMergedRegion(new CellRangeAddress(1, 1, i*2, i*2+1));
|
||||
XSSFCell monthCell = monthRow.createCell(i*2);
|
||||
monthCell.setCellValue(days[i]);
|
||||
monthCell.setCellStyle(styles.get("month"));
|
||||
}
|
||||
|
||||
int cnt = 1, day=1;
|
||||
int rownum = 2;
|
||||
for (int j = 0; j < 6; j++) {
|
||||
XSSFRow row = sheet.createRow(rownum++);
|
||||
row.setHeightInPoints(100);
|
||||
for (int i = 0; i < days.length; i++) {
|
||||
XSSFCell dayCell_1 = row.createCell(i*2);
|
||||
XSSFCell dayCell_2 = row.createCell(i*2 + 1);
|
||||
|
||||
int day_of_week = calendar.get(Calendar.DAY_OF_WEEK);
|
||||
if(cnt >= day_of_week && calendar.get(Calendar.MONTH) == month) {
|
||||
dayCell_1.setCellValue(day);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, ++day);
|
||||
|
||||
if(i == 0 || i == days.length-1) {
|
||||
dayCell_1.setCellStyle(styles.get("weekend_left"));
|
||||
dayCell_2.setCellStyle(styles.get("weekend_right"));
|
||||
} else {
|
||||
dayCell_1.setCellStyle(styles.get("workday_left"));
|
||||
dayCell_2.setCellStyle(styles.get("workday_right"));
|
||||
}
|
||||
} else {
|
||||
dayCell_1.setCellStyle(styles.get("grey_left"));
|
||||
dayCell_2.setCellStyle(styles.get("grey_right"));
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
if(calendar.get(Calendar.MONTH) > month) break;
|
||||
}
|
||||
}
|
||||
|
||||
// Write the output to a file
|
||||
FileOutputStream out = new FileOutputStream("calendar-"+year+".xlsx");
|
||||
wb.write(out);
|
||||
out.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* cell styles used for formatting calendar sheets
|
||||
*/
|
||||
private static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb){
|
||||
Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();
|
||||
|
||||
XSSFCellStyle style;
|
||||
XSSFFont titleFont = wb.createFont();
|
||||
titleFont.setFontHeightInPoints((short)48);
|
||||
titleFont.setColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
style.setFont(titleFont);
|
||||
styles.put("title", style);
|
||||
|
||||
XSSFFont monthFont = wb.createFont();
|
||||
monthFont.setFontHeightInPoints((short)12);
|
||||
monthFont.setColor(new XSSFColor(new java.awt.Color(255, 255, 255)));
|
||||
monthFont.setBold(true);
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setFont(monthFont);
|
||||
styles.put("month", style);
|
||||
|
||||
XSSFFont dayFont = wb.createFont();
|
||||
dayFont.setFontHeightInPoints((short)14);
|
||||
dayFont.setBold(true);
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.LEFT);
|
||||
style.setVerticalAlignment(VerticalAlignment.TOP);
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(228, 232, 243)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setBorderLeft(BorderStyle.THIN);
|
||||
style.setLeftBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
style.setBottomBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
|
||||
style.setFont(dayFont);
|
||||
styles.put("weekend_left", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setVerticalAlignment(VerticalAlignment.TOP);
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(228, 232, 243)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setBorderRight(BorderStyle.THIN);
|
||||
style.setRightBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
style.setBottomBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
|
||||
styles.put("weekend_right", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.LEFT);
|
||||
style.setVerticalAlignment(VerticalAlignment.TOP);
|
||||
style.setBorderLeft(BorderStyle.THIN);
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(255, 255, 255)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setLeftBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
style.setBottomBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
|
||||
style.setFont(dayFont);
|
||||
styles.put("workday_left", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setVerticalAlignment(VerticalAlignment.TOP);
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(255, 255, 255)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setBorderRight(BorderStyle.THIN);
|
||||
style.setRightBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
style.setBottomBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
|
||||
styles.put("workday_right", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setBorderLeft(BorderStyle.THIN);
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(234, 234, 234)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
style.setBottomBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
|
||||
styles.put("grey_left", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(234, 234, 234)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setBorderRight(BorderStyle.THIN);
|
||||
style.setRightBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
style.setBottomBorderColor(new XSSFColor(new java.awt.Color(39, 51, 89)));
|
||||
styles.put("grey_right", style);
|
||||
|
||||
return styles;
|
||||
}
|
||||
}
|
81
src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java
Executable file
81
src/examples/src/org/apache/poi/xssf/usermodel/examples/CreateCell.java
Executable file
@ -0,0 +1,81 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
/**
|
||||
* Illustrates how to create cell and set values of different types.
|
||||
*/
|
||||
public class CreateCell {
|
||||
|
||||
|
||||
public static void main(String[]args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
CreationHelper creationHelper = wb.getCreationHelper();
|
||||
Sheet sheet = wb.createSheet("new sheet");
|
||||
|
||||
// Create a row and put some cells in it. Rows are 0 based.
|
||||
Row row = sheet.createRow((short)0);
|
||||
// Create a cell and put a value in it.
|
||||
Cell cell = row.createCell((short)0);
|
||||
cell.setCellValue(1);
|
||||
|
||||
//numeric value
|
||||
row.createCell(1).setCellValue(1.2);
|
||||
|
||||
//plain string value
|
||||
row.createCell(2).setCellValue("This is a string cell");
|
||||
|
||||
//rich text string
|
||||
RichTextString str = creationHelper.createRichTextString("Apache");
|
||||
Font font = wb.createFont();
|
||||
font.setItalic(true);
|
||||
font.setUnderline(Font.U_SINGLE);
|
||||
str.applyFont(font);
|
||||
row.createCell(3).setCellValue(str);
|
||||
|
||||
//boolean value
|
||||
row.createCell(4).setCellValue(true);
|
||||
|
||||
//formula
|
||||
row.createCell(5).setCellFormula("SUM(A1:B1)");
|
||||
|
||||
//date
|
||||
CellStyle style = wb.createCellStyle();
|
||||
style.setDataFormat(creationHelper.createDataFormat().getFormat("m/d/yy h:mm"));
|
||||
cell = row.createCell(6);
|
||||
cell.setCellValue(new Date());
|
||||
cell.setCellStyle(style);
|
||||
|
||||
//hyperlink
|
||||
row.createCell(7).setCellFormula("SUM(A1:B1)");
|
||||
cell.setCellFormula("HYPERLINK(\"http://google.com\",\"Google\")");
|
||||
|
||||
|
||||
// Write the output to a file
|
||||
FileOutputStream fileOut = new FileOutputStream("ooxml-cell.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.DataFormat;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
/**
|
||||
* How to set user-defined date formats
|
||||
*/
|
||||
public class CreateUserDefinedDataFormats {
|
||||
|
||||
|
||||
public static void main(String[]args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet("format sheet");
|
||||
CellStyle style;
|
||||
DataFormat format = wb.createDataFormat();
|
||||
Row row;
|
||||
Cell cell;
|
||||
short rowNum = 0;
|
||||
short colNum = 0;
|
||||
|
||||
row = sheet.createRow(rowNum++);
|
||||
cell = row.createCell(colNum);
|
||||
cell.setCellValue(11111.25);
|
||||
style = wb.createCellStyle();
|
||||
style.setDataFormat(format.getFormat("0.0"));
|
||||
cell.setCellStyle(style);
|
||||
|
||||
row = sheet.createRow(rowNum++);
|
||||
cell = row.createCell(colNum);
|
||||
cell.setCellValue(11111.25);
|
||||
style = wb.createCellStyle();
|
||||
style.setDataFormat(format.getFormat("#,##0.0000"));
|
||||
cell.setCellStyle(style);
|
||||
|
||||
FileOutputStream fileOut = new FileOutputStream("ooxml_dataFormat.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
}
|
||||
|
||||
}
|
59
src/examples/src/org/apache/poi/xssf/usermodel/examples/FillsAndColors.java
Executable file
59
src/examples/src/org/apache/poi/xssf/usermodel/examples/FillsAndColors.java
Executable file
@ -0,0 +1,59 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
/**
|
||||
* Fills and Colors
|
||||
*/
|
||||
public class FillsAndColors {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
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);
|
||||
|
||||
// Aqua background
|
||||
CellStyle style = wb.createCellStyle();
|
||||
style.setFillBackgroundColor(IndexedColors.AQUA.getIndex());
|
||||
style.setFillPattern(CellStyle.BIG_SPOTS);
|
||||
Cell cell = row.createCell((short) 1);
|
||||
cell.setCellValue(new XSSFRichTextString("X"));
|
||||
cell.setCellStyle(style);
|
||||
|
||||
// Orange "foreground", foreground being the fill foreground not the font color.
|
||||
style = wb.createCellStyle();
|
||||
style.setFillForegroundColor(IndexedColors.ORANGE.getIndex());
|
||||
style.setFillPattern(CellStyle.SOLID_FOREGROUND);
|
||||
cell = row.createCell((short) 2);
|
||||
cell.setCellValue(new XSSFRichTextString("X"));
|
||||
cell.setCellStyle(style);
|
||||
|
||||
// Write the output to a file
|
||||
FileOutputStream fileOut = new FileOutputStream("fill_colors.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.apache.poi.ss.usermodel.PrintSetup;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
public class FitSheetToOnePage {
|
||||
|
||||
|
||||
public static void main(String[]args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet("format sheet");
|
||||
PrintSetup ps = sheet.getPrintSetup();
|
||||
|
||||
sheet.setAutobreaks(true);
|
||||
|
||||
ps.setFitHeight((short) 1);
|
||||
ps.setFitWidth((short) 1);
|
||||
|
||||
// Create various cells and rows for spreadsheet.
|
||||
|
||||
FileOutputStream fileOut = new FileOutputStream("fitSheetToOnePage.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,84 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Footer;
|
||||
import org.apache.poi.ss.usermodel.Header;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
public class HeadersAndFooters {
|
||||
|
||||
|
||||
public static void main(String[]args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet("first-header - format sheet");
|
||||
sheet.createRow(0).createCell(0).setCellValue(123);
|
||||
|
||||
//set page numbers in the footer
|
||||
Footer footer = sheet.getFooter();
|
||||
//&P == current page number
|
||||
//&N == page numbers
|
||||
footer.setRight("Page &P of &N");
|
||||
|
||||
|
||||
Header firstHeader=((XSSFSheet)sheet).getFirstHeader();
|
||||
//&F == workbook file name
|
||||
firstHeader.setLeft("&F ......... first header");
|
||||
|
||||
for(int i=0;i<100;i=i+10){
|
||||
sheet.createRow(i).createCell(0).setCellValue(123);
|
||||
}
|
||||
|
||||
|
||||
XSSFSheet sheet2 = (XSSFSheet)wb.createSheet("odd header-even footer");
|
||||
Header oddHeader=sheet2.getOddHeader();
|
||||
//&B == bold
|
||||
//&E == double underline
|
||||
//&D == date
|
||||
oddHeader.setCenter("&B &E oddHeader &D ");
|
||||
|
||||
Footer evenFooter=sheet2.getEvenFooter();
|
||||
evenFooter.setRight("even footer &P");
|
||||
sheet2.createRow(10).createCell(0).setCellValue("Second sheet with an oddHeader and an evenFooter");
|
||||
|
||||
for(int i=0;i<200;i=i+10){
|
||||
sheet2.createRow(i).createCell(0).setCellValue(123);
|
||||
}
|
||||
|
||||
XSSFSheet sheet3 = (XSSFSheet)wb.createSheet("odd header- odd footer");
|
||||
sheet3.createRow(10).createCell(0).setCellValue("Third sheet with oddHeader and oddFooter");
|
||||
Header oddH=sheet3.getOddHeader();
|
||||
//&C == centered
|
||||
oddH.setCenter("centered oddHeader");
|
||||
oddH.setLeft("left ");
|
||||
oddH.setRight("right ");
|
||||
|
||||
Footer oddF=sheet3.getOddFooter();
|
||||
oddF.setLeft("Page &P");
|
||||
oddF.setRight("Pages &N ");
|
||||
|
||||
FileOutputStream fileOut = new FileOutputStream("headerFooter.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,89 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
|
||||
/**
|
||||
* Demonstrates how to create hyperlinks.
|
||||
*/
|
||||
public class HyperlinkExample {
|
||||
|
||||
|
||||
public static void main(String[]args) throws Exception{
|
||||
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
CreationHelper createHelper = wb.getCreationHelper();
|
||||
|
||||
//cell style for hyperlinks
|
||||
//by default hypelrinks are blue and underlined
|
||||
CellStyle hlink_style = wb.createCellStyle();
|
||||
Font hlink_font = wb.createFont();
|
||||
hlink_font.setUnderline(Font.U_SINGLE);
|
||||
hlink_font.setColor(IndexedColors.BLUE.getIndex());
|
||||
hlink_style.setFont(hlink_font);
|
||||
|
||||
Cell cell;
|
||||
Sheet sheet = wb.createSheet("Hyperlinks");
|
||||
//URL
|
||||
cell = sheet.createRow(0).createCell((short)0);
|
||||
cell.setCellValue("URL Link");
|
||||
|
||||
Hyperlink link = createHelper.createHyperlink(Hyperlink.LINK_URL);
|
||||
link.setAddress("http://poi.apache.org/");
|
||||
cell.setHyperlink(link);
|
||||
cell.setCellStyle(hlink_style);
|
||||
|
||||
//link to a file in the current directory
|
||||
cell = sheet.createRow(1).createCell((short)0);
|
||||
cell.setCellValue("File Link");
|
||||
link = createHelper.createHyperlink(Hyperlink.LINK_FILE);
|
||||
link.setAddress("link1.xls");
|
||||
cell.setHyperlink(link);
|
||||
cell.setCellStyle(hlink_style);
|
||||
|
||||
//e-mail link
|
||||
cell = sheet.createRow(2).createCell((short)0);
|
||||
cell.setCellValue("Email Link");
|
||||
link = createHelper.createHyperlink(Hyperlink.LINK_EMAIL);
|
||||
//note, if subject contains white spaces, make sure they are url-encoded
|
||||
link.setAddress("mailto:poi@apache.org?subject=Hyperlinks");
|
||||
cell.setHyperlink(link);
|
||||
cell.setCellStyle(hlink_style);
|
||||
|
||||
//link to a place in this workbook
|
||||
|
||||
//create a target sheet and cell
|
||||
Sheet sheet2 = wb.createSheet("Target Sheet");
|
||||
sheet2.createRow(0).createCell((short)0).setCellValue("Target Cell");
|
||||
|
||||
cell = sheet.createRow(3).createCell((short)0);
|
||||
cell.setCellValue("Worksheet Link");
|
||||
Hyperlink link2 = createHelper.createHyperlink(Hyperlink.LINK_DOCUMENT);
|
||||
link2.setAddress("'Target Sheet'!A1");
|
||||
cell.setHyperlink(link2);
|
||||
cell.setCellStyle(hlink_style);
|
||||
|
||||
FileOutputStream out = new FileOutputStream("hyperinks.xlsx");
|
||||
wb.write(out);
|
||||
out.close();
|
||||
|
||||
}
|
||||
}
|
44
src/examples/src/org/apache/poi/xssf/usermodel/examples/IterateCells.java
Executable file
44
src/examples/src/org/apache/poi/xssf/usermodel/examples/IterateCells.java
Executable file
@ -0,0 +1,44 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
|
||||
/**
|
||||
* Iterate over rows and cells
|
||||
*/
|
||||
public class IterateCells {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook(args[0]);
|
||||
for (int i = 0; i < wb.getNumberOfSheets(); i++) {
|
||||
Sheet sheet = wb.getSheetAt(i);
|
||||
System.out.println(wb.getSheetName(i));
|
||||
for (Row row : sheet) {
|
||||
System.out.println("rownum: " + row.getRowNum());
|
||||
for (Cell cell : row) {
|
||||
System.out.println(cell.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
312
src/examples/src/org/apache/poi/xssf/usermodel/examples/LoanCalculator.java
Executable file
312
src/examples/src/org/apache/poi/xssf/usermodel/examples/LoanCalculator.java
Executable file
@ -0,0 +1,312 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
/**
|
||||
* Simple Loan Calculator
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public class LoanCalculator {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
Map<String, XSSFCellStyle> styles = createStyles(wb);
|
||||
XSSFSheet sheet = wb.createSheet("Loan Calculator");
|
||||
sheet.setPrintGridlines(false);
|
||||
sheet.setDisplayGridlines(false);
|
||||
|
||||
XSSFPrintSetup printSetup = sheet.getPrintSetup();
|
||||
printSetup.setOrientation(PrintOrientation.LANDSCAPE);
|
||||
sheet.setFitToPage(true);
|
||||
sheet.setHorizontallyCenter(true);
|
||||
|
||||
sheet.setColumnWidth(0, 3*256);
|
||||
sheet.setColumnWidth(1, 3*256);
|
||||
sheet.setColumnWidth(2, 11*256);
|
||||
sheet.setColumnWidth(3, 14*256);
|
||||
sheet.setColumnWidth(4, 14*256);
|
||||
sheet.setColumnWidth(5, 14*256);
|
||||
sheet.setColumnWidth(6, 14*256);
|
||||
|
||||
createNames(wb);
|
||||
|
||||
XSSFRow titleRow = sheet.createRow(0);
|
||||
titleRow.setHeightInPoints(35);
|
||||
for (int i = 1; i <= 7; i++) {
|
||||
titleRow.createCell(i).setCellStyle(styles.get("title"));
|
||||
}
|
||||
XSSFCell titleCell = titleRow.getCell(2);
|
||||
titleCell.setCellValue("Simple Loan Calculator");
|
||||
sheet.addMergedRegion(CellRangeAddress.valueOf("$C$1:$H$1"));
|
||||
|
||||
XSSFRow row = sheet.createRow(2);
|
||||
XSSFCell cell = row.createCell(4);
|
||||
cell.setCellValue("Enter values");
|
||||
cell.setCellStyle(styles.get("item_right"));
|
||||
|
||||
row = sheet.createRow(3);
|
||||
cell = row.createCell(2);
|
||||
cell.setCellValue("Loan amount");
|
||||
cell.setCellStyle(styles.get("item_left"));
|
||||
cell = row.createCell(4);
|
||||
cell.setCellStyle(styles.get("input_$"));
|
||||
|
||||
row = sheet.createRow(4);
|
||||
cell = row.createCell(2);
|
||||
cell.setCellValue("Annual interest rate");
|
||||
cell.setCellStyle(styles.get("item_left"));
|
||||
cell = row.createCell(4);
|
||||
cell.setCellStyle(styles.get("input_%"));
|
||||
|
||||
row = sheet.createRow(5);
|
||||
cell = row.createCell(2);
|
||||
cell.setCellValue("Loan period in years");
|
||||
cell.setCellStyle(styles.get("item_left"));
|
||||
cell = row.createCell(4);
|
||||
cell.setCellStyle(styles.get("input_i"));
|
||||
|
||||
row = sheet.createRow(6);
|
||||
cell = row.createCell(2);
|
||||
cell.setCellValue("Start date of loan");
|
||||
cell.setCellStyle(styles.get("item_left"));
|
||||
cell = row.createCell(4);
|
||||
cell.setCellStyle(styles.get("input_d"));
|
||||
|
||||
row = sheet.createRow(8);
|
||||
cell = row.createCell(2);
|
||||
cell.setCellValue("Monthly payment");
|
||||
cell.setCellStyle(styles.get("item_left"));
|
||||
cell = row.createCell(4);
|
||||
cell.setCellFormula("IF(Values_Entered,Monthly_Payment,\"\")");
|
||||
cell.setCellStyle(styles.get("formula_$"));
|
||||
|
||||
row = sheet.createRow(9);
|
||||
cell = row.createCell(2);
|
||||
cell.setCellValue("Number of payments");
|
||||
cell.setCellStyle(styles.get("item_left"));
|
||||
cell = row.createCell(4);
|
||||
cell.setCellFormula("IF(Values_Entered,Loan_Years*12,\"\")");
|
||||
cell.setCellStyle(styles.get("formula_i"));
|
||||
|
||||
row = sheet.createRow(10);
|
||||
cell = row.createCell(2);
|
||||
cell.setCellValue("Total interest");
|
||||
cell.setCellStyle(styles.get("item_left"));
|
||||
cell = row.createCell(4);
|
||||
cell.setCellFormula("IF(Values_Entered,Total_Cost-Loan_Amount,\"\")");
|
||||
cell.setCellStyle(styles.get("formula_$"));
|
||||
|
||||
row = sheet.createRow(11);
|
||||
cell = row.createCell(2);
|
||||
cell.setCellValue("Total cost of loan");
|
||||
cell.setCellStyle(styles.get("item_left"));
|
||||
cell = row.createCell(4);
|
||||
cell.setCellFormula("IF(Values_Entered,Monthly_Payment*Number_of_Payments,\"\")");
|
||||
cell.setCellStyle(styles.get("formula_$"));
|
||||
|
||||
sheet.setActiveCell("E4");
|
||||
|
||||
// Write the output to a file
|
||||
FileOutputStream out = new FileOutputStream("loan-calculator.xlsx");
|
||||
wb.write(out);
|
||||
out.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* cell styles used for formatting calendar sheets
|
||||
*/
|
||||
private static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb){
|
||||
Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();
|
||||
|
||||
XSSFCellStyle style;
|
||||
XSSFFont titleFont = wb.createFont();
|
||||
titleFont.setFontHeightInPoints((short)14);
|
||||
titleFont.setFontName("Trebuchet MS");
|
||||
style = wb.createCellStyle();
|
||||
style.setFont(titleFont);
|
||||
style.setBorderBottom(BorderStyle.DOTTED);
|
||||
style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
styles.put("title", style);
|
||||
|
||||
XSSFFont itemFont = wb.createFont();
|
||||
itemFont.setFontHeightInPoints((short)9);
|
||||
itemFont.setFontName("Trebuchet MS");
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.LEFT);
|
||||
style.setFont(itemFont);
|
||||
styles.put("item_left", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.RIGHT);
|
||||
style.setFont(itemFont);
|
||||
styles.put("item_right", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.RIGHT);
|
||||
style.setFont(itemFont);
|
||||
style.setBorderRight(BorderStyle.DOTTED);
|
||||
style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setBorderBottom(BorderStyle.DOTTED);
|
||||
style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setBorderLeft(BorderStyle.DOTTED);
|
||||
style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setBorderTop(BorderStyle.DOTTED);
|
||||
style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setDataFormat(wb.createDataFormat().getFormat("_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)"));
|
||||
styles.put("input_$", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.RIGHT);
|
||||
style.setFont(itemFont);
|
||||
style.setBorderRight(BorderStyle.DOTTED);
|
||||
style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setBorderBottom(BorderStyle.DOTTED);
|
||||
style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setBorderLeft(BorderStyle.DOTTED);
|
||||
style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setBorderTop(BorderStyle.DOTTED);
|
||||
style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setDataFormat(wb.createDataFormat().getFormat("0.000%"));
|
||||
styles.put("input_%", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.RIGHT);
|
||||
style.setFont(itemFont);
|
||||
style.setBorderRight(BorderStyle.DOTTED);
|
||||
style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setBorderBottom(BorderStyle.DOTTED);
|
||||
style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setBorderLeft(BorderStyle.DOTTED);
|
||||
style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setBorderTop(BorderStyle.DOTTED);
|
||||
style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setDataFormat(wb.createDataFormat().getFormat("0"));
|
||||
styles.put("input_i", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setFont(itemFont);
|
||||
style.setDataFormat(wb.createDataFormat().getFormat("m/d/yy"));
|
||||
styles.put("input_d", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.RIGHT);
|
||||
style.setFont(itemFont);
|
||||
style.setBorderRight(BorderStyle.DOTTED);
|
||||
style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setBorderBottom(BorderStyle.DOTTED);
|
||||
style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setBorderLeft(BorderStyle.DOTTED);
|
||||
style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setBorderTop(BorderStyle.DOTTED);
|
||||
style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setDataFormat(wb.createDataFormat().getFormat("$##,##0.00"));
|
||||
style.setBorderBottom(BorderStyle.DOTTED);
|
||||
style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(234, 234, 234)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
styles.put("formula_$", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.RIGHT);
|
||||
style.setFont(itemFont);
|
||||
style.setBorderRight(BorderStyle.DOTTED);
|
||||
style.setRightBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setBorderBottom(BorderStyle.DOTTED);
|
||||
style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setBorderLeft(BorderStyle.DOTTED);
|
||||
style.setLeftBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setBorderTop(BorderStyle.DOTTED);
|
||||
style.setTopBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setDataFormat(wb.createDataFormat().getFormat("0"));
|
||||
style.setBorderBottom(BorderStyle.DOTTED);
|
||||
style.setBottomBorderColor(IndexedColors.GREY_40_PERCENT.getIndex());
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(234, 234, 234)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
styles.put("formula_i", style);
|
||||
|
||||
return styles;
|
||||
}
|
||||
|
||||
//define named ranges for the inputs and formulas
|
||||
public static void createNames(XSSFWorkbook wb){
|
||||
XSSFName name;
|
||||
|
||||
name = wb.createName();
|
||||
name.setNameName("Header_Row");
|
||||
name.setReference("ROW('Loan Calculator'!#REF!)");
|
||||
|
||||
name = wb.createName();
|
||||
name.setNameName("Interest_Rate");
|
||||
name.setReference("'Loan Calculator'!$E$5");
|
||||
|
||||
name = wb.createName();
|
||||
name.setNameName("Loan_Amount");
|
||||
name.setReference("'Loan Calculator'!$E$4");
|
||||
|
||||
name = wb.createName();
|
||||
name.setNameName("Loan_Not_Paid");
|
||||
name.setReference("F(Payment_Number<=Number_of_Payments,1,0)");
|
||||
|
||||
name = wb.createName();
|
||||
name.setNameName("Loan_Start");
|
||||
name.setReference("'Loan Calculator'!$E$7");
|
||||
|
||||
name = wb.createName();
|
||||
name.setNameName("Loan_Years");
|
||||
name.setReference("'Loan Calculator'!$E$6");
|
||||
|
||||
name = wb.createName();
|
||||
name.setNameName("Monthly_Payment");
|
||||
name.setReference("-PMT(Interest_Rate/12,Number_of_Payments,Loan_Amount)");
|
||||
|
||||
name = wb.createName();
|
||||
name.setNameName("Number_of_Payments");
|
||||
name.setReference("'Loan Calculator'!$E$10");
|
||||
|
||||
name = wb.createName();
|
||||
name.setNameName("Payment_Number");
|
||||
name.setReference("ROW()-Header_Row");
|
||||
|
||||
name = wb.createName();
|
||||
name.setNameName("Principal");
|
||||
name.setReference("-PPMT(Interest_Rate/12,Payment_Number,Number_of_Payments,Loan_Amount)");
|
||||
|
||||
name = wb.createName();
|
||||
name.setNameName("Total_Cost");
|
||||
name.setReference("'Loan Calculator'!$E$12");
|
||||
|
||||
name = wb.createName();
|
||||
name.setNameName("Total_Interest");
|
||||
name.setReference("'Loan Calculator'!$E$11");
|
||||
|
||||
name = wb.createName();
|
||||
name.setNameName("Values_Entered");
|
||||
name.setReference("IF(Loan_Amount*Interest_Rate*Loan_Years*Loan_Start>0,1,0)");
|
||||
|
||||
|
||||
}
|
||||
}
|
50
src/examples/src/org/apache/poi/xssf/usermodel/examples/MergingCells.java
Executable file
50
src/examples/src/org/apache/poi/xssf/usermodel/examples/MergingCells.java
Executable file
@ -0,0 +1,50 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
||||
import org.apache.poi.hssf.util.Region;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
/**
|
||||
* An example of how to merge regions of cells.
|
||||
*/
|
||||
public class MergingCells {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet("new sheet");
|
||||
|
||||
Row row = sheet.createRow((short) 1);
|
||||
Cell cell = row.createCell((short) 1);
|
||||
cell.setCellValue(new XSSFRichTextString("This is a test of merging"));
|
||||
|
||||
sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 2));
|
||||
|
||||
// Write the output to a file
|
||||
FileOutputStream fileOut = new FileOutputStream("merging_cells.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
|
||||
}
|
||||
}
|
57
src/examples/src/org/apache/poi/xssf/usermodel/examples/NewLinesInCells.java
Executable file
57
src/examples/src/org/apache/poi/xssf/usermodel/examples/NewLinesInCells.java
Executable file
@ -0,0 +1,57 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
/**
|
||||
* How to use newlines in cells
|
||||
*/
|
||||
public class NewLinesInCells {
|
||||
|
||||
public static void main(String[]args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet();
|
||||
|
||||
Row row = sheet.createRow(2);
|
||||
Cell cell = row.createCell(2);
|
||||
cell.setCellValue("Use \n with word wrap on to create a new line");
|
||||
|
||||
//to enable newlines you need set a cell styles with wrap=true
|
||||
CellStyle cs = wb.createCellStyle();
|
||||
cs.setWrapText(true);
|
||||
cell.setCellStyle(cs);
|
||||
|
||||
//increase row height to accomodate two lines of text
|
||||
row.setHeightInPoints((2*sheet.getDefaultRowHeightInPoints()));
|
||||
|
||||
//adjust column width to fit the content
|
||||
sheet.autoSizeColumn((short)2);
|
||||
|
||||
FileOutputStream fileOut = new FileOutputStream("ooxml-newlines.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
}
|
||||
|
||||
}
|
44
src/examples/src/org/apache/poi/xssf/usermodel/examples/SelectedSheet.java
Executable file
44
src/examples/src/org/apache/poi/xssf/usermodel/examples/SelectedSheet.java
Executable file
@ -0,0 +1,44 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
|
||||
public class SelectedSheet {
|
||||
|
||||
public static void main(String[]args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet("row sheet");
|
||||
|
||||
Sheet sheet2 = wb.createSheet("another sheet");
|
||||
Sheet sheet3 = wb.createSheet(" sheet 3 ");
|
||||
sheet3.setSelected(true);
|
||||
wb.setActiveSheet(2);
|
||||
|
||||
// Create various cells and rows for spreadsheet.
|
||||
|
||||
FileOutputStream fileOut = new FileOutputStream("selectedSheet.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
}
|
||||
|
||||
}
|
61
src/examples/src/org/apache/poi/xssf/usermodel/examples/ShiftRows.java
Executable file
61
src/examples/src/org/apache/poi/xssf/usermodel/examples/ShiftRows.java
Executable file
@ -0,0 +1,61 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
/**
|
||||
* How to shift rows up or down
|
||||
*/
|
||||
public class ShiftRows {
|
||||
|
||||
public static void main(String[]args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet("Sheet1");
|
||||
|
||||
Row row1 = sheet.createRow(1);
|
||||
row1.createCell(0).setCellValue(1);
|
||||
|
||||
Row row2 = sheet.createRow(4);
|
||||
row2.createCell(1).setCellValue(2);
|
||||
|
||||
Row row3 = sheet.createRow(5);
|
||||
row3.createCell(2).setCellValue(3);
|
||||
|
||||
Row row4 = sheet.createRow(6);
|
||||
row4.createCell(3).setCellValue(4);
|
||||
|
||||
Row row5 = sheet.createRow(9);
|
||||
row5.createCell(4).setCellValue(5);
|
||||
|
||||
// Shift rows 6 - 11 on the spreadsheet to the top (rows 0 - 5)
|
||||
sheet.shiftRows(5, 10, -4);
|
||||
|
||||
FileOutputStream fileOut = new FileOutputStream("shiftRows.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
/**
|
||||
* How to set spklit and freeze panes
|
||||
*/
|
||||
public class SplitAndFreezePanes {
|
||||
public static void main(String[]args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook();
|
||||
Sheet sheet1 = wb.createSheet("new sheet");
|
||||
Sheet sheet2 = wb.createSheet("second sheet");
|
||||
Sheet sheet3 = wb.createSheet("third sheet");
|
||||
Sheet sheet4 = wb.createSheet("fourth sheet");
|
||||
|
||||
// Freeze just one row
|
||||
sheet1.createFreezePane(0, 1, 0, 1);
|
||||
// Freeze just one column
|
||||
sheet2.createFreezePane(1, 0, 1, 0);
|
||||
// Freeze the columns and rows (forget about scrolling position of the lower right quadrant).
|
||||
sheet3.createFreezePane(2, 2);
|
||||
// Create a split with the lower left side being the active quadrant
|
||||
sheet4.createSplitPane(2000, 2000, 0, 0, Sheet.PANE_LOWER_LEFT);
|
||||
|
||||
FileOutputStream fileOut = new FileOutputStream("splitFreezePane.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
|
||||
}
|
||||
}
|
209
src/examples/src/org/apache/poi/xssf/usermodel/examples/TimesheetDemo.java
Executable file
209
src/examples/src/org/apache/poi/xssf/usermodel/examples/TimesheetDemo.java
Executable file
@ -0,0 +1,209 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
/**
|
||||
* A weekly timesheet created using Apache POI.
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public class TimesheetDemo {
|
||||
private static final String[] titles = {
|
||||
"Person", "ID", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun",
|
||||
"Total\nHrs", "Overtime\nHrs", "Regular\nHrs"
|
||||
};
|
||||
|
||||
private static Object[][] sample_data = {
|
||||
{"Yegor Kozlov", "YK", 5.0, 8.0, 10.0, 5.0, 5.0, 7.0, 6.0},
|
||||
{"Gisella Bronsetti", "GB", 4.0, 3.0, 1.0, 3.5, null, null, 4.0},
|
||||
};
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
Map<String, XSSFCellStyle> styles = createStyles(wb);
|
||||
|
||||
XSSFSheet sheet = wb.createSheet("Timesheet");
|
||||
XSSFPrintSetup printSetup = sheet.getPrintSetup();
|
||||
printSetup.setOrientation(PrintOrientation.LANDSCAPE);
|
||||
sheet.setFitToPage(true);
|
||||
sheet.setHorizontallyCenter(true);
|
||||
|
||||
//title row
|
||||
XSSFRow titleRow = sheet.createRow(0);
|
||||
titleRow.setHeightInPoints(45);
|
||||
XSSFCell titleCell = titleRow.createCell(0);
|
||||
titleCell.setCellValue("Weekly Timesheet");
|
||||
titleCell.setCellStyle(styles.get("title"));
|
||||
sheet.addMergedRegion(CellRangeAddress.valueOf("$A$1:$L$1"));
|
||||
|
||||
//header row
|
||||
XSSFRow headerRow = sheet.createRow(1);
|
||||
headerRow.setHeightInPoints(40);
|
||||
XSSFCell headerCell;
|
||||
for (int i = 0; i < titles.length; i++) {
|
||||
headerCell = headerRow.createCell(i);
|
||||
headerCell.setCellValue(titles[i]);
|
||||
headerCell.setCellStyle(styles.get("header"));
|
||||
}
|
||||
|
||||
int rownum = 2;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
XSSFRow row = sheet.createRow(rownum++);
|
||||
for (int j = 0; j < titles.length; j++) {
|
||||
XSSFCell cell = row.createCell(j);
|
||||
if(j == 9){
|
||||
//the 10th cell contains sum over week days, e.g. SUM(C3:I3)
|
||||
String ref = "C" +rownum+ ":I" + rownum;
|
||||
cell.setCellFormula("SUM("+ref+")");
|
||||
cell.setCellStyle(styles.get("formula"));
|
||||
} else if (j == 11){
|
||||
cell.setCellFormula("J" +rownum+ "-K" + rownum);
|
||||
cell.setCellStyle(styles.get("formula"));
|
||||
} else {
|
||||
cell.setCellStyle(styles.get("cell"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//row with totals below
|
||||
XSSFRow sumRow = sheet.createRow(rownum++);
|
||||
sumRow.setHeightInPoints(35);
|
||||
XSSFCell cell;
|
||||
cell = sumRow.createCell(0);
|
||||
cell.setCellStyle(styles.get("formula"));
|
||||
cell = sumRow.createCell(1);
|
||||
cell.setCellValue("Total Hrs:");
|
||||
cell.setCellStyle(styles.get("formula"));
|
||||
|
||||
for (int j = 2; j < 12; j++) {
|
||||
cell = sumRow.createCell(j);
|
||||
String ref = (char)('A' + j) + "3:" + (char)('A' + j) + "12";
|
||||
cell.setCellFormula("SUM(" + ref + ")");
|
||||
if(j >= 9) cell.setCellStyle(styles.get("formula_2"));
|
||||
else cell.setCellStyle(styles.get("formula"));
|
||||
}
|
||||
rownum++;
|
||||
sumRow = sheet.createRow(rownum++);
|
||||
sumRow.setHeightInPoints(25);
|
||||
cell = sumRow.createCell(0);
|
||||
cell.setCellValue("Total Regular Hours");
|
||||
cell.setCellStyle(styles.get("formula"));
|
||||
cell = sumRow.createCell(1);
|
||||
cell.setCellFormula("L13");
|
||||
cell.setCellStyle(styles.get("formula_2"));
|
||||
sumRow = sheet.createRow(rownum++);
|
||||
sumRow.setHeightInPoints(25);
|
||||
cell = sumRow.createCell(0);
|
||||
cell.setCellValue("Total Overtime Hours");
|
||||
cell.setCellStyle(styles.get("formula"));
|
||||
cell = sumRow.createCell(1);
|
||||
cell.setCellFormula("K13");
|
||||
cell.setCellStyle(styles.get("formula_2"));
|
||||
|
||||
//set sample data
|
||||
for (int i = 0; i < sample_data.length; i++) {
|
||||
XSSFRow row = sheet.getRow(2 + i);
|
||||
for (int j = 0; j < sample_data[i].length; j++) {
|
||||
if(sample_data[i][j] == null) continue;
|
||||
|
||||
if(sample_data[i][j] instanceof String) {
|
||||
row.getCell(j).setCellValue((String)sample_data[i][j]);
|
||||
} else {
|
||||
row.getCell(j).setCellValue((Double)sample_data[i][j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//finally set column widths
|
||||
sheet.setColumnWidth(0, 30*256);
|
||||
for (int i = 2; i < 9; i++) {
|
||||
sheet.setColumnWidth(i, 6*256);
|
||||
}
|
||||
|
||||
// Write the output to a file
|
||||
FileOutputStream out = new FileOutputStream("ooxml-timesheet.xlsx");
|
||||
wb.write(out);
|
||||
out.close();
|
||||
}
|
||||
|
||||
private static Map<String, XSSFCellStyle> createStyles(XSSFWorkbook wb){
|
||||
Map<String, XSSFCellStyle> styles = new HashMap<String, XSSFCellStyle>();
|
||||
XSSFCellStyle style;
|
||||
XSSFFont titleFont = wb.createFont();
|
||||
titleFont.setFontHeightInPoints((short)18);
|
||||
titleFont.setBold(true);
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(234, 234, 234)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setFont(titleFont);
|
||||
styles.put("title", style);
|
||||
|
||||
XSSFFont monthFont = wb.createFont();
|
||||
monthFont.setFontHeightInPoints((short)11);
|
||||
monthFont.setColor(new XSSFColor(new java.awt.Color(255, 255, 255)));
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(102, 102, 102)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setFont(monthFont);
|
||||
style.setWrapText(true);
|
||||
styles.put("header", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setWrapText(true);
|
||||
style.setBorderRight(BorderStyle.THIN);
|
||||
style.setRightBorderColor(IndexedColors.BLACK.getIndex());
|
||||
style.setBorderLeft(BorderStyle.THIN);
|
||||
style.setLeftBorderColor(IndexedColors.BLACK.getIndex());
|
||||
style.setBorderTop(BorderStyle.THIN);
|
||||
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
||||
style.setBorderBottom(BorderStyle.THIN);
|
||||
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
||||
styles.put("cell", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(234, 234, 234)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
|
||||
styles.put("formula", style);
|
||||
|
||||
style = wb.createCellStyle();
|
||||
style.setAlignment(HorizontalAlignment.CENTER);
|
||||
style.setVerticalAlignment(VerticalAlignment.CENTER);
|
||||
style.setFillForegroundColor(new XSSFColor(new java.awt.Color(192, 192, 192)));
|
||||
style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
||||
style.setDataFormat(wb.createDataFormat().getFormat("0.00"));
|
||||
styles.put("formula_2", style);
|
||||
|
||||
return styles;
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
/**
|
||||
* Working with borders
|
||||
*/
|
||||
public class WorkingWithBorders {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet("borders");
|
||||
|
||||
// Create a row and put some cells in it. Rows are 0 based.
|
||||
Row row = sheet.createRow((short) 1);
|
||||
|
||||
// Create a cell and put a value in it.
|
||||
Cell cell = row.createCell((short) 1);
|
||||
cell.setCellValue(4);
|
||||
|
||||
// Style the cell with borders all around.
|
||||
CellStyle style = wb.createCellStyle();
|
||||
style.setBorderBottom(CellStyle.BORDER_THIN);
|
||||
style.setBottomBorderColor(IndexedColors.BLACK.getIndex());
|
||||
style.setBorderLeft(CellStyle.BORDER_THIN);
|
||||
style.setLeftBorderColor(IndexedColors.GREEN.getIndex());
|
||||
style.setBorderRight(CellStyle.BORDER_THIN);
|
||||
style.setRightBorderColor(IndexedColors.BLUE.getIndex());
|
||||
style.setBorderTop(CellStyle.BORDER_MEDIUM_DASHED);
|
||||
style.setTopBorderColor(IndexedColors.BLACK.getIndex());
|
||||
cell.setCellStyle(style);
|
||||
|
||||
// Write the output to a file
|
||||
FileOutputStream fileOut = new FileOutputStream("xssf-borders.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
|
||||
}
|
||||
}
|
100
src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java
Executable file
100
src/examples/src/org/apache/poi/xssf/usermodel/examples/WorkingWithFonts.java
Executable file
@ -0,0 +1,100 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
/**
|
||||
* Working with Fonts
|
||||
*/
|
||||
public class WorkingWithFonts {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
Sheet sheet = wb.createSheet("Fonts");
|
||||
|
||||
Font font0 = wb.createFont();
|
||||
font0.setColor(IndexedColors.BROWN.getIndex());
|
||||
CellStyle style0 = wb.createCellStyle();
|
||||
style0.setFont(font0);
|
||||
|
||||
Font font1 = wb.createFont();
|
||||
font1.setFontHeightInPoints((short)14);
|
||||
font1.setFontName("Courier New");
|
||||
font1.setColor(IndexedColors.RED.getIndex());
|
||||
CellStyle style1 = wb.createCellStyle();
|
||||
style1.setFont(font1);
|
||||
|
||||
Font font2 = wb.createFont();
|
||||
font2.setFontHeightInPoints((short)16);
|
||||
font2.setFontName("Arial");
|
||||
font2.setColor(IndexedColors.GREEN.getIndex());
|
||||
CellStyle style2 = wb.createCellStyle();
|
||||
style2.setFont(font2);
|
||||
|
||||
Font font3 = wb.createFont();
|
||||
font3.setFontHeightInPoints((short)18);
|
||||
font3.setFontName("Times New Roman");
|
||||
font3.setColor(IndexedColors.LAVENDER.getIndex());
|
||||
CellStyle style3 = wb.createCellStyle();
|
||||
style3.setFont(font3);
|
||||
|
||||
Font font4 = wb.createFont();
|
||||
font4.setFontHeightInPoints((short)18);
|
||||
font4.setFontName("Wingdings");
|
||||
font4.setColor(IndexedColors.GOLD.getIndex());
|
||||
CellStyle style4 = wb.createCellStyle();
|
||||
style4.setFont(font4);
|
||||
|
||||
Font font5 = wb.createFont();
|
||||
font5.setFontName("Symbol");
|
||||
CellStyle style5 = wb.createCellStyle();
|
||||
style5.setFont(font5);
|
||||
|
||||
Cell cell0 = sheet.createRow(0).createCell(1);
|
||||
cell0.setCellValue("Default");
|
||||
cell0.setCellStyle(style0);
|
||||
|
||||
Cell cell1 = sheet.createRow(1).createCell(1);
|
||||
cell1.setCellValue("Courier");
|
||||
cell1.setCellStyle(style1);
|
||||
|
||||
Cell cell2 = sheet.createRow(2).createCell(1);
|
||||
cell2.setCellValue("Arial");
|
||||
cell2.setCellStyle(style2);
|
||||
|
||||
Cell cell3 = sheet.createRow(3).createCell(1);
|
||||
cell3.setCellValue("Times New Roman");
|
||||
cell3.setCellStyle(style3);
|
||||
|
||||
Cell cell4 = sheet.createRow(4).createCell(1);
|
||||
cell4.setCellValue("Wingdings");
|
||||
cell4.setCellStyle(style4);
|
||||
|
||||
Cell cell5 = sheet.createRow(5).createCell(1);
|
||||
cell5.setCellValue("Symbol");
|
||||
cell5.setCellStyle(style5);
|
||||
|
||||
// Write the output to a file
|
||||
FileOutputStream fileOut = new FileOutputStream("xssf-fonts.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
}
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
|
||||
/**
|
||||
* Demonstrates various settings avaiable in the Page Setup dialog
|
||||
*/
|
||||
public class WorkingWithPageSetup {
|
||||
|
||||
public static void main(String[]args) throws Exception {
|
||||
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
|
||||
/**
|
||||
* It's possible to set up repeating rows and columns in your printouts by using the setRepeatingRowsAndColumns() function in the Workbook object.
|
||||
*
|
||||
* This function Contains 5 parameters:
|
||||
* The first parameter is the index to the sheet (0 = first sheet).
|
||||
* The second and third parameters specify the range for the columns to repreat.
|
||||
* To stop the columns from repeating pass in -1 as the start and end column.
|
||||
* The fourth and fifth parameters specify the range for the rows to repeat.
|
||||
* To stop the columns from repeating pass in -1 as the start and end rows.
|
||||
*/
|
||||
Sheet sheet1 = wb.createSheet("new sheet");
|
||||
Sheet sheet2 = wb.createSheet("second sheet");
|
||||
|
||||
// Set the columns to repeat from column 0 to 2 on the first sheet
|
||||
Row row1 = sheet1.createRow(0);
|
||||
row1.createCell(0).setCellValue(1);
|
||||
row1.createCell(1).setCellValue(2);
|
||||
row1.createCell(2).setCellValue(3);
|
||||
Row row2 = sheet1.createRow(1);
|
||||
row2.createCell(1).setCellValue(4);
|
||||
row2.createCell(2).setCellValue(5);
|
||||
|
||||
|
||||
Row row3 = sheet2.createRow(1);
|
||||
row3.createCell(0).setCellValue(2.1);
|
||||
row3.createCell(4).setCellValue(2.2);
|
||||
row3.createCell(5).setCellValue(2.3);
|
||||
Row row4 = sheet2.createRow(2);
|
||||
row4.createCell(4).setCellValue(2.4);
|
||||
row4.createCell(5).setCellValue(2.5);
|
||||
|
||||
// Set the columns to repeat from column 0 to 2 on the first sheet
|
||||
wb.setRepeatingRowsAndColumns(0,0,2,-1,-1);
|
||||
// Set the the repeating rows and columns on the second sheet.
|
||||
wb.setRepeatingRowsAndColumns(1,4,5,1,2);
|
||||
|
||||
//set the print area for the first sheet
|
||||
wb.setPrintArea(0, 1, 2, 0, 3);
|
||||
|
||||
|
||||
FileOutputStream fileOut = new FileOutputStream("xssf-printsetup.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
/**
|
||||
* Demonstrates how to insert pictures in a SpreadsheetML document
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public class WorkingWithPictures {
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
//create a new workbook
|
||||
XSSFWorkbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
|
||||
//add a picture in this workbook.
|
||||
InputStream is = new FileInputStream("lilies.jpg");
|
||||
int pictureIdx = wb.addPicture(is, XSSFWorkbook.PICTURE_TYPE_JPEG);
|
||||
is.close();
|
||||
|
||||
//create sheet
|
||||
XSSFSheet sheet = wb.createSheet();
|
||||
|
||||
//create drawing
|
||||
XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
||||
|
||||
//add a picture shape
|
||||
XSSFPicture pict = drawing.createPicture(new XSSFClientAnchor(), pictureIdx);
|
||||
|
||||
//auto-size picture
|
||||
pict.resize();
|
||||
|
||||
//save workbook
|
||||
FileOutputStream fileOut = new FileOutputStream("xssf-picture.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/* ====================================================================
|
||||
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.xssf.usermodel.examples;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.*;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
|
||||
/**
|
||||
* Demonstrates how to work with rich text
|
||||
*/
|
||||
public class WorkingWithRichText {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
XSSFWorkbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
|
||||
|
||||
XSSFSheet sheet = wb.createSheet();
|
||||
XSSFRow row = sheet.createRow((short) 2);
|
||||
|
||||
XSSFCell cell = row.createCell(1);
|
||||
XSSFRichTextString rt = new XSSFRichTextString("The quick brown fox");
|
||||
|
||||
XSSFFont font1 = wb.createFont();
|
||||
font1.setBold(true);
|
||||
font1.setColor(new XSSFColor(new java.awt.Color(255, 0, 0)));
|
||||
rt.applyFont(0, 10, font1);
|
||||
|
||||
XSSFFont font2 = wb.createFont();
|
||||
font2.setItalic(true);
|
||||
font2.setUnderline(XSSFFont.U_DOUBLE);
|
||||
font2.setColor(new XSSFColor(new java.awt.Color(0, 255, 0)));
|
||||
rt.applyFont(10, 19, font2);
|
||||
|
||||
XSSFFont font3 = wb.createFont();
|
||||
font3.setColor(new XSSFColor(new java.awt.Color(0, 0, 255)));
|
||||
rt.append(" Jumped over the lazy dog", font3);
|
||||
|
||||
cell.setCellValue(rt);
|
||||
|
||||
// Write the output to a file
|
||||
FileOutputStream fileOut = new FileOutputStream("xssf-richtext.xlsx");
|
||||
wb.write(fileOut);
|
||||
fileOut.close();
|
||||
}
|
||||
|
||||
}
|
@ -19,6 +19,7 @@ package org.apache.poi;
|
||||
import org.apache.poi.hpsf.DocumentSummaryInformation;
|
||||
import org.apache.poi.hpsf.SummaryInformation;
|
||||
import org.apache.poi.hpsf.extractor.HPSFPropertiesExtractor;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
|
||||
/**
|
||||
* Common Parent for OLE2 based Text Extractors
|
||||
@ -59,4 +60,12 @@ public abstract class POIOLE2TextExtractor extends POITextExtractor {
|
||||
public POITextExtractor getMetadataTextExtractor() {
|
||||
return new HPSFPropertiesExtractor(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the underlying POIFS FileSystem of
|
||||
* this document.
|
||||
*/
|
||||
public POIFSFileSystem getFileSystem() {
|
||||
return document.filesystem;
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
package org.apache.poi.ddf;
|
||||
|
||||
import org.apache.poi.hssf.record.RecordFormatException;
|
||||
import org.apache.poi.util.RecordFormatException;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.util.HashMap;
|
||||
|
@ -18,9 +18,9 @@
|
||||
|
||||
package org.apache.poi.ddf;
|
||||
|
||||
import org.apache.poi.hssf.record.RecordFormatException;
|
||||
import org.apache.poi.util.HexDump;
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
import org.apache.poi.util.RecordFormatException;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
|
@ -18,9 +18,9 @@
|
||||
|
||||
package org.apache.poi.ddf;
|
||||
|
||||
import org.apache.poi.hssf.record.RecordFormatException;
|
||||
import org.apache.poi.util.HexDump;
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
import org.apache.poi.util.RecordFormatException;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -20,7 +20,7 @@ package org.apache.poi.ddf;
|
||||
|
||||
import org.apache.poi.util.HexDump;
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
import org.apache.poi.hssf.record.RecordFormatException;
|
||||
import org.apache.poi.util.RecordFormatException;
|
||||
|
||||
/**
|
||||
* The spgr record defines information about a shape group. Groups in escher
|
||||
|
@ -20,7 +20,7 @@ package org.apache.poi.ddf;
|
||||
|
||||
import org.apache.poi.util.HexDump;
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
import org.apache.poi.hssf.record.RecordFormatException;
|
||||
import org.apache.poi.util.RecordFormatException;
|
||||
|
||||
/**
|
||||
* A list of the most recently used colours for the drawings contained in
|
||||
|
@ -18,9 +18,9 @@
|
||||
|
||||
package org.apache.poi.ddf;
|
||||
|
||||
import org.apache.poi.hssf.record.RecordFormatException;
|
||||
import org.apache.poi.util.HexDump;
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
import org.apache.poi.util.RecordFormatException;
|
||||
|
||||
/**
|
||||
* Holds data from the parent application. Most commonly used to store
|
||||
|
@ -15,7 +15,6 @@
|
||||
limitations under the License.
|
||||
==================================================================== */
|
||||
|
||||
|
||||
package org.apache.poi.hssf.dev;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
@ -30,8 +29,9 @@ import org.apache.poi.hssf.usermodel.HSSFRichTextString;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.hssf.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
import org.apache.poi.ss.util.Region;
|
||||
|
||||
/**
|
||||
* File for HSSF testing/examples
|
||||
|
@ -20,14 +20,15 @@ package org.apache.poi.hssf.extractor;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.poi.POIOLE2TextExtractor;
|
||||
import org.apache.poi.ss.usermodel.HeaderFooter;
|
||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
||||
import org.apache.poi.hssf.usermodel.HeaderFooter;
|
||||
import org.apache.poi.hssf.usermodel.HSSFCell;
|
||||
import org.apache.poi.hssf.usermodel.HSSFComment;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
|
||||
import org.apache.poi.hssf.usermodel.HSSFRow;
|
||||
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.poifs.filesystem.DirectoryNode;
|
||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
|
||||
/**
|
||||
@ -39,7 +40,7 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||
* the XLS2CSVmra example
|
||||
* @see org.apache.poi.hssf.eventusermodel.examples.XLS2CSVmra
|
||||
*/
|
||||
public class ExcelExtractor extends POIOLE2TextExtractor {
|
||||
public class ExcelExtractor extends POIOLE2TextExtractor implements org.apache.poi.ss.extractor.ExcelExtractor {
|
||||
private HSSFWorkbook wb;
|
||||
private boolean includeSheetNames = true;
|
||||
private boolean formulasNotResults = false;
|
||||
@ -51,7 +52,10 @@ public class ExcelExtractor extends POIOLE2TextExtractor {
|
||||
this.wb = wb;
|
||||
}
|
||||
public ExcelExtractor(POIFSFileSystem fs) throws IOException {
|
||||
this(new HSSFWorkbook(fs));
|
||||
this(fs.getRoot(), fs);
|
||||
}
|
||||
public ExcelExtractor(DirectoryNode dir, POIFSFileSystem fs) throws IOException {
|
||||
this(new HSSFWorkbook(dir, fs, true));
|
||||
}
|
||||
|
||||
|
||||
@ -109,7 +113,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor {
|
||||
// Header text, if there is any
|
||||
if(sheet.getHeader() != null) {
|
||||
text.append(
|
||||
extractHeaderFooter(sheet.getHeader())
|
||||
_extractHeaderFooter(sheet.getHeader())
|
||||
);
|
||||
}
|
||||
|
||||
@ -199,7 +203,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor {
|
||||
// Finally Feader text, if there is any
|
||||
if(sheet.getFooter() != null) {
|
||||
text.append(
|
||||
extractHeaderFooter(sheet.getFooter())
|
||||
_extractHeaderFooter(sheet.getFooter())
|
||||
);
|
||||
}
|
||||
}
|
||||
@ -207,7 +211,7 @@ public class ExcelExtractor extends POIOLE2TextExtractor {
|
||||
return text.toString();
|
||||
}
|
||||
|
||||
private String extractHeaderFooter(HeaderFooter hf) {
|
||||
public static String _extractHeaderFooter(HeaderFooter hf) {
|
||||
StringBuffer text = new StringBuffer();
|
||||
|
||||
if(hf.getLeft() != null) {
|
||||
|
@ -74,7 +74,7 @@ public class CommentShape extends TextboxShape {
|
||||
private NoteRecord createNoteRecord( HSSFComment shape, int shapeId )
|
||||
{
|
||||
NoteRecord note = new NoteRecord();
|
||||
note.setColumn(shape.getColumn());
|
||||
note.setColumn((short)shape.getColumn());
|
||||
note.setRow((short)shape.getRow());
|
||||
note.setFlags(shape.isVisible() ? NoteRecord.NOTE_VISIBLE : NoteRecord.NOTE_HIDDEN);
|
||||
note.setShapeId((short)shapeId);
|
||||
|
@ -68,7 +68,7 @@ import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
|
||||
import org.apache.poi.hssf.record.aggregates.RecordAggregate.PositionTrackingVisitor;
|
||||
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
|
||||
import org.apache.poi.hssf.record.formula.FormulaShifter;
|
||||
import org.apache.poi.hssf.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.hssf.util.PaneInformation;
|
||||
import org.apache.poi.util.POILogFactory;
|
||||
import org.apache.poi.util.POILogger;
|
||||
|
@ -18,8 +18,8 @@
|
||||
package org.apache.poi.hssf.record;
|
||||
|
||||
import org.apache.poi.hssf.record.cf.CellRangeUtil;
|
||||
import org.apache.poi.hssf.util.CellRangeAddress;
|
||||
import org.apache.poi.hssf.util.CellRangeAddressList;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
|
||||
/**
|
||||
|
@ -19,8 +19,8 @@ package org.apache.poi.hssf.record;
|
||||
import org.apache.poi.hssf.record.formula.Ptg;
|
||||
import org.apache.poi.hssf.usermodel.DVConstraint;
|
||||
import org.apache.poi.hssf.usermodel.HSSFDataValidation;
|
||||
import org.apache.poi.hssf.util.CellRangeAddress;
|
||||
import org.apache.poi.hssf.util.CellRangeAddressList;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||
import org.apache.poi.ss.formula.Formula;
|
||||
import org.apache.poi.util.BitField;
|
||||
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
|
||||
|
@ -17,8 +17,8 @@
|
||||
|
||||
package org.apache.poi.hssf.record;
|
||||
|
||||
import org.apache.poi.hssf.util.CellRangeAddress;
|
||||
import org.apache.poi.hssf.util.CellRangeAddressList;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||
import org.apache.poi.util.LittleEndian;
|
||||
|
||||
/**
|
||||
|
@ -26,9 +26,9 @@ import org.apache.poi.hssf.record.formula.Ptg;
|
||||
import org.apache.poi.hssf.record.formula.Ref3DPtg;
|
||||
import org.apache.poi.hssf.record.formula.UnionPtg;
|
||||
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||
import org.apache.poi.hssf.util.AreaReference;
|
||||
import org.apache.poi.hssf.util.RangeAddress;
|
||||
import org.apache.poi.ss.formula.Formula;
|
||||
import org.apache.poi.ss.util.AreaReference;
|
||||
import org.apache.poi.util.HexDump;
|
||||
import org.apache.poi.util.LittleEndianByteArrayOutputStream;
|
||||
import org.apache.poi.util.LittleEndianInput;
|
||||
|
@ -25,7 +25,7 @@ package org.apache.poi.hssf.record;
|
||||
*/
|
||||
|
||||
public class RecordFormatException
|
||||
extends RuntimeException
|
||||
extends org.apache.poi.util.RecordFormatException
|
||||
{
|
||||
public RecordFormatException(String exception)
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ import org.apache.poi.hssf.record.formula.AreaErrPtg;
|
||||
import org.apache.poi.hssf.record.formula.AreaPtg;
|
||||
import org.apache.poi.hssf.record.formula.FormulaShifter;
|
||||
import org.apache.poi.hssf.record.formula.Ptg;
|
||||
import org.apache.poi.hssf.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
|
||||
/**
|
||||
* CFRecordsAggregate - aggregates Conditional Formatting records CFHeaderRecord
|
||||
|
@ -22,8 +22,8 @@ import java.util.List;
|
||||
|
||||
import org.apache.poi.hssf.model.RecordStream;
|
||||
import org.apache.poi.hssf.record.MergeCellsRecord;
|
||||
import org.apache.poi.hssf.util.CellRangeAddress;
|
||||
import org.apache.poi.hssf.util.CellRangeAddressList;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -21,7 +21,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.hssf.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -17,8 +17,8 @@
|
||||
|
||||
package org.apache.poi.hssf.record.formula;
|
||||
|
||||
import org.apache.poi.hssf.util.AreaReference;
|
||||
import org.apache.poi.hssf.util.CellReference;
|
||||
import org.apache.poi.ss.util.AreaReference;
|
||||
import org.apache.poi.ss.util.CellReference;
|
||||
import org.apache.poi.util.BitField;
|
||||
import org.apache.poi.util.BitFieldFactory;
|
||||
import org.apache.poi.util.LittleEndianInput;
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
package org.apache.poi.hssf.record.formula;
|
||||
|
||||
import org.apache.poi.hssf.util.CellReference;
|
||||
import org.apache.poi.ss.util.CellReference;
|
||||
import org.apache.poi.ss.formula.ExternSheetReferenceToken;
|
||||
import org.apache.poi.ss.formula.FormulaRenderingWorkbook;
|
||||
import org.apache.poi.ss.formula.WorkbookDependentFormula;
|
||||
|
@ -29,7 +29,7 @@ import org.apache.poi.hssf.record.formula.eval.OperandResolver;
|
||||
import org.apache.poi.hssf.record.formula.eval.StringEval;
|
||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
||||
import org.apache.poi.hssf.record.formula.functions.FreeRefFunction;
|
||||
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
|
||||
import org.apache.poi.ss.usermodel.DateUtil;
|
||||
import org.apache.poi.ss.formula.EvaluationWorkbook;
|
||||
/**
|
||||
* Implementation of Excel 'Analysis ToolPak' function YEARFRAC()<br/>
|
||||
@ -93,7 +93,7 @@ final class YearFrac implements FreeRefFunction {
|
||||
return dVal.doubleValue();
|
||||
}
|
||||
Calendar date = parseDate(strVal);
|
||||
return HSSFDateUtil.getExcelDate(date, false);
|
||||
return DateUtil.getExcelDate(date, false);
|
||||
}
|
||||
return OperandResolver.coerceValueToDouble(ve);
|
||||
}
|
||||
|
@ -165,7 +165,6 @@ public final class Offset implements Function {
|
||||
}
|
||||
|
||||
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) {
|
||||
|
||||
if(args.length < 3 || args.length > 5) {
|
||||
return ErrorEval.VALUE_INVALID;
|
||||
}
|
||||
@ -196,7 +195,6 @@ public final class Offset implements Function {
|
||||
|
||||
private static AreaEval createOffset(BaseRef baseRef,
|
||||
LinearOffsetRange orRow, LinearOffsetRange orCol) throws EvaluationException {
|
||||
|
||||
LinearOffsetRange absRows = orRow.normaliseAndTranslate(baseRef.getFirstRowIndex());
|
||||
LinearOffsetRange absCols = orCol.normaliseAndTranslate(baseRef.getFirstColumnIndex());
|
||||
|
||||
|
@ -49,6 +49,11 @@ import org.apache.poi.hssf.record.UnicodeString;
|
||||
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
|
||||
import org.apache.poi.hssf.record.formula.Ptg;
|
||||
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.Comment;
|
||||
import org.apache.poi.ss.usermodel.Hyperlink;
|
||||
import org.apache.poi.ss.usermodel.RichTextString;
|
||||
|
||||
/**
|
||||
* High level representation of a cell in a row of a spreadsheet.
|
||||
@ -68,8 +73,7 @@ import org.apache.poi.hssf.record.formula.eval.ErrorEval;
|
||||
* @author Yegor Kozlov cell comments support
|
||||
* @version 1.0-pre
|
||||
*/
|
||||
public final class HSSFCell {
|
||||
|
||||
public class HSSFCell implements Cell {
|
||||
/** Numeric Cell type (0) @see #setCellType(int) @see #getCellType() */
|
||||
public final static int CELL_TYPE_NUMERIC = 0;
|
||||
/** String Cell type (1) @see #setCellType(int) @see #getCellType() */
|
||||
@ -493,20 +497,16 @@ public final class HSSFCell {
|
||||
}
|
||||
|
||||
/**
|
||||
* set a string value for the cell. Please note that if you are using
|
||||
* full 16 bit unicode you should call <code>setEncoding()</code> first.
|
||||
* set a string value for the cell.
|
||||
*
|
||||
* @param value value to set the cell to. For formulas we'll set the formula
|
||||
* string, for String cells we'll set its value. For other types we will
|
||||
* @param value value to set the cell to. For formulas we'll set the formula
|
||||
* cached string result, for String cells we'll set its value. For other types we will
|
||||
* change the cell to a string cell and set its value.
|
||||
* If value is null then we will change the cell to a Blank cell.
|
||||
* @deprecated Use setCellValue(HSSFRichTextString) instead.
|
||||
*/
|
||||
|
||||
public void setCellValue(String value)
|
||||
{
|
||||
HSSFRichTextString str = new HSSFRichTextString(value);
|
||||
setCellValue(str);
|
||||
public void setCellValue(String value) {
|
||||
HSSFRichTextString str = value == null ? null : new HSSFRichTextString(value);
|
||||
setCellValue(str);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -518,11 +518,15 @@ public final class HSSFCell {
|
||||
* change the cell to a string cell and set its value.
|
||||
* If value is <code>null</code> then we will change the cell to a Blank cell.
|
||||
*/
|
||||
public void setCellValue(HSSFRichTextString value) {
|
||||
|
||||
public void setCellValue(RichTextString value)
|
||||
{
|
||||
HSSFRichTextString hvalue = (HSSFRichTextString) value;
|
||||
int row=record.getRow();
|
||||
short col=record.getColumn();
|
||||
short styleIndex=record.getXFIndex();
|
||||
if (value == null) {
|
||||
if (hvalue == null)
|
||||
{
|
||||
notifyFormulaChanging();
|
||||
setCellType(CELL_TYPE_BLANK, false, row, col, styleIndex);
|
||||
return;
|
||||
@ -531,7 +535,7 @@ public final class HSSFCell {
|
||||
// Set the 'pre-evaluated result' for the formula
|
||||
// note - formulas do not preserve text formatting.
|
||||
FormulaRecordAggregate fr = (FormulaRecordAggregate) record;
|
||||
fr.setCachedStringResult(value.getString());
|
||||
fr.setCachedStringResult(hvalue.getString());
|
||||
// Update our local cache to the un-formatted version
|
||||
stringValue = new HSSFRichTextString(value.getString());
|
||||
|
||||
@ -547,10 +551,10 @@ public final class HSSFCell {
|
||||
}
|
||||
int index = 0;
|
||||
|
||||
UnicodeString str = value.getUnicodeString();
|
||||
UnicodeString str = hvalue.getUnicodeString();
|
||||
index = book.getWorkbook().addSSTString(str);
|
||||
(( LabelSSTRecord ) record).setSSTIndex(index);
|
||||
stringValue = value;
|
||||
stringValue = hvalue;
|
||||
stringValue.setWorkbookReferences(book.getWorkbook(), (( LabelSSTRecord ) record));
|
||||
stringValue.setUnicodeString(book.getWorkbook().getSSTString(index));
|
||||
}
|
||||
@ -846,9 +850,10 @@ public final class HSSFCell {
|
||||
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createCellStyle()
|
||||
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getCellStyleAt(short)
|
||||
*/
|
||||
|
||||
public void setCellStyle(HSSFCellStyle style)
|
||||
{
|
||||
public void setCellStyle(CellStyle style) {
|
||||
setCellStyle( (HSSFCellStyle)style );
|
||||
}
|
||||
public void setCellStyle(HSSFCellStyle style) {
|
||||
// Verify it really does belong to our workbook
|
||||
style.verifyBelongsToWorkbook(book);
|
||||
|
||||
@ -947,7 +952,7 @@ public final class HSSFCell {
|
||||
*
|
||||
* @param comment comment associated with this cell
|
||||
*/
|
||||
public void setCellComment(HSSFComment comment){
|
||||
public void setCellComment(Comment comment){
|
||||
if(comment == null) {
|
||||
removeCellComment();
|
||||
return;
|
||||
@ -955,7 +960,7 @@ public final class HSSFCell {
|
||||
|
||||
comment.setRow((short)record.getRow());
|
||||
comment.setColumn(record.getColumn());
|
||||
this.comment = comment;
|
||||
this.comment = (HSSFComment)comment;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1082,7 +1087,9 @@ public final class HSSFCell {
|
||||
*
|
||||
* @param link hypelrink associated with this cell
|
||||
*/
|
||||
public void setHyperlink(HSSFHyperlink link){
|
||||
public void setHyperlink(Hyperlink hyperlink){
|
||||
HSSFHyperlink link = (HSSFHyperlink)hyperlink;
|
||||
|
||||
link.setFirstRow(record.getRow());
|
||||
link.setLastRow(record.getRow());
|
||||
link.setFirstColumn(record.getColumn());
|
||||
|
@ -23,6 +23,8 @@ import org.apache.poi.hssf.record.ExtendedFormatRecord;
|
||||
import org.apache.poi.hssf.record.FontRecord;
|
||||
import org.apache.poi.hssf.record.StyleRecord;
|
||||
import org.apache.poi.hssf.util.HSSFColor;
|
||||
import org.apache.poi.ss.usermodel.CellStyle;
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
|
||||
/**
|
||||
* High level representation of the style of a cell in a sheet of a workbook.
|
||||
@ -36,7 +38,7 @@ import org.apache.poi.hssf.util.HSSFColor;
|
||||
* @see org.apache.poi.hssf.usermodel.HSSFCell#setCellStyle(HSSFCellStyle)
|
||||
*/
|
||||
|
||||
public class HSSFCellStyle
|
||||
public class HSSFCellStyle implements CellStyle
|
||||
{
|
||||
private ExtendedFormatRecord format = null;
|
||||
private short index = 0;
|
||||
@ -307,12 +309,22 @@ public class HSSFCellStyle
|
||||
*
|
||||
* @return the format string or "General" if not found
|
||||
*/
|
||||
public String getDataFormatString(Workbook workbook) {
|
||||
HSSFDataFormat format = new HSSFDataFormat(workbook);
|
||||
public String getDataFormatString(org.apache.poi.ss.usermodel.Workbook workbook) {
|
||||
HSSFDataFormat format = new HSSFDataFormat( ((HSSFWorkbook)workbook).getWorkbook() );
|
||||
|
||||
int idx = getDataFormat();
|
||||
return idx == -1 ? "General" : format.getFormat(getDataFormat());
|
||||
}
|
||||
/**
|
||||
* Get the contents of the format string, by looking up
|
||||
* the DataFormat against the supplied low level workbook
|
||||
* @see org.apache.poi.hssf.usermodel.HSSFDataFormat
|
||||
*/
|
||||
public String getDataFormatString(org.apache.poi.hssf.model.Workbook workbook) {
|
||||
HSSFDataFormat format = new HSSFDataFormat( workbook );
|
||||
|
||||
return format.getFormat(getDataFormat());
|
||||
}
|
||||
|
||||
/**
|
||||
* set the font for this style
|
||||
@ -320,11 +332,12 @@ public class HSSFCellStyle
|
||||
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#createFont()
|
||||
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
|
||||
*/
|
||||
|
||||
public void setFont(HSSFFont font)
|
||||
{
|
||||
public void setFont(Font font) {
|
||||
setFont((HSSFFont)font);
|
||||
}
|
||||
public void setFont(HSSFFont font) {
|
||||
format.setIndentNotParentFont(true);
|
||||
short fontindex = ((HSSFFont) font).getIndex();
|
||||
short fontindex = font.getIndex();
|
||||
format.setFontIndex(fontindex);
|
||||
}
|
||||
|
||||
@ -343,7 +356,7 @@ public class HSSFCellStyle
|
||||
* @see org.apache.poi.hssf.usermodel.HSSFCellStyle#getFontIndex()
|
||||
* @see org.apache.poi.hssf.usermodel.HSSFWorkbook#getFontAt(short)
|
||||
*/
|
||||
public HSSFFont getFont(HSSFWorkbook parentWorkbook) {
|
||||
public HSSFFont getFont(org.apache.poi.ss.usermodel.Workbook parentWorkbook) {
|
||||
return ((HSSFWorkbook) parentWorkbook).getFontAt(getFontIndex());
|
||||
}
|
||||
|
||||
@ -1009,6 +1022,12 @@ public class HSSFCellStyle
|
||||
* HSSFWorkbook if you like. This allows you to
|
||||
* copy styles from one HSSFWorkbook to another.
|
||||
*/
|
||||
public void cloneStyleFrom(CellStyle source) {
|
||||
if(source instanceof HSSFCellStyle) {
|
||||
this.cloneStyleFrom((HSSFCellStyle)source);
|
||||
}
|
||||
throw new IllegalArgumentException("Can only clone from one HSSFCellStyle to another, not between HSSFCellStyle and XSSFCellStyle");
|
||||
}
|
||||
public void cloneStyleFrom(HSSFCellStyle source) {
|
||||
// First we need to clone the extended format
|
||||
// record
|
||||
|
@ -16,21 +16,17 @@
|
||||
==================================================================== */
|
||||
package org.apache.poi.hssf.usermodel;
|
||||
|
||||
import org.apache.poi.hssf.record.EscherAggregate;
|
||||
import org.apache.poi.hssf.record.NoteRecord;
|
||||
import org.apache.poi.hssf.record.TextObjectRecord;
|
||||
import org.apache.poi.ddf.*;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import org.apache.poi.ss.usermodel.Comment;
|
||||
import org.apache.poi.ss.usermodel.RichTextString;
|
||||
|
||||
/**
|
||||
* Represents a cell comment - a sticky note associated with a cell.
|
||||
*
|
||||
* @author Yegor Kozlov
|
||||
*/
|
||||
public class HSSFComment extends HSSFTextbox {
|
||||
public class HSSFComment extends HSSFTextbox implements Comment {
|
||||
|
||||
private boolean visible;
|
||||
private short col, row;
|
||||
@ -109,7 +105,7 @@ public class HSSFComment extends HSSFTextbox {
|
||||
*
|
||||
* @return the 0-based column of the cell that contains the comment
|
||||
*/
|
||||
public short getColumn(){
|
||||
public int getColumn(){
|
||||
return col;
|
||||
}
|
||||
|
||||
@ -141,18 +137,19 @@ public class HSSFComment extends HSSFTextbox {
|
||||
if(note != null) note.setAuthor(author);
|
||||
this.author = author;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets the rich text string used by this comment.
|
||||
*
|
||||
* @param string Sets the rich text string used by this object.
|
||||
*/
|
||||
public void setString( HSSFRichTextString string ) {
|
||||
public void setString( RichTextString string ) {
|
||||
HSSFRichTextString hstring = (HSSFRichTextString) string;
|
||||
//if font is not set we must set the default one
|
||||
if (string.numFormattingRuns() == 0) string.applyFont((short)0);
|
||||
if (hstring.numFormattingRuns() == 0) hstring.applyFont((short)0);
|
||||
|
||||
if (txo != null) {
|
||||
txo.setStr(string);
|
||||
txo.setStr(hstring);
|
||||
}
|
||||
super.setString(string);
|
||||
}
|
||||
|
@ -18,8 +18,8 @@ package org.apache.poi.hssf.usermodel;
|
||||
|
||||
import org.apache.poi.hssf.record.CFRuleRecord;
|
||||
import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
|
||||
import org.apache.poi.hssf.util.CellRangeAddress;
|
||||
import org.apache.poi.hssf.util.Region;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.ss.util.Region;
|
||||
|
||||
/**
|
||||
* HSSFConditionalFormatting class encapsulates all settings of Conditional Formatting.
|
||||
|
@ -0,0 +1,47 @@
|
||||
/* ====================================================================
|
||||
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.hssf.usermodel;
|
||||
|
||||
import org.apache.poi.ss.usermodel.CreationHelper;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
|
||||
public class HSSFCreationHelper implements CreationHelper {
|
||||
private HSSFWorkbook workbook;
|
||||
private HSSFDataFormat dataFormat;
|
||||
|
||||
HSSFCreationHelper(HSSFWorkbook wb) {
|
||||
workbook = wb;
|
||||
|
||||
// Create the things we only ever need one of
|
||||
dataFormat = new HSSFDataFormat(workbook.getWorkbook());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new HSSFRichTextString for you.
|
||||
*/
|
||||
public HSSFRichTextString createRichTextString(String text) {
|
||||
return new HSSFRichTextString(text);
|
||||
}
|
||||
|
||||
public HSSFDataFormat createDataFormat() {
|
||||
return dataFormat;
|
||||
}
|
||||
|
||||
public HSSFHyperlink createHyperlink(int type) {
|
||||
return new HSSFHyperlink(type);
|
||||
}
|
||||
}
|
@ -23,14 +23,15 @@
|
||||
*/
|
||||
package org.apache.poi.hssf.usermodel;
|
||||
|
||||
import org.apache.poi.hssf.model.Workbook;
|
||||
import org.apache.poi.hssf.record.FormatRecord;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.apache.poi.hssf.model.Workbook;
|
||||
import org.apache.poi.hssf.record.FormatRecord;
|
||||
import org.apache.poi.ss.usermodel.DataFormat;
|
||||
|
||||
/**
|
||||
* Utility to identify builtin formats. Now can handle user defined data formats also. The following is a list of the formats as
|
||||
* returned by this class.<P>
|
||||
@ -79,7 +80,7 @@ import java.util.Vector;
|
||||
* @author Shawn M. Laubach (slaubach at apache dot org)
|
||||
*/
|
||||
|
||||
public class HSSFDataFormat
|
||||
public class HSSFDataFormat implements DataFormat
|
||||
{
|
||||
private static List builtinFormats = createBuiltinFormats();
|
||||
|
||||
|
@ -18,7 +18,7 @@ package org.apache.poi.hssf.usermodel;
|
||||
|
||||
import org.apache.poi.hssf.record.DVRecord;
|
||||
import org.apache.poi.hssf.usermodel.DVConstraint.FormulaPair;
|
||||
import org.apache.poi.hssf.util.CellRangeAddressList;
|
||||
import org.apache.poi.ss.util.CellRangeAddressList;
|
||||
|
||||
/**
|
||||
*Utility class for creating data validation cells
|
||||
@ -232,4 +232,4 @@ public final class HSSFDataValidation {
|
||||
fp.getFormula1(), fp.getFormula2(),
|
||||
_regions);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,12 +16,17 @@
|
||||
==================================================================== */
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* DateUtil.java
|
||||
*
|
||||
* Created on January 19, 2002, 9:30 AM
|
||||
*/
|
||||
package org.apache.poi.hssf.usermodel;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.poi.ss.usermodel.DateUtil;
|
||||
|
||||
/**
|
||||
* Contains methods for dealing with Excel dates.
|
||||
@ -33,430 +38,9 @@ import java.util.regex.Pattern;
|
||||
* @author Alex Jacoby (ajacoby at gmail.com)
|
||||
* @author Pavel Krupets (pkrupets at palmtreebusiness dot com)
|
||||
*/
|
||||
public final class HSSFDateUtil {
|
||||
private HSSFDateUtil() {
|
||||
// no instances of this class
|
||||
}
|
||||
private static final int SECONDS_PER_MINUTE = 60;
|
||||
private static final int MINUTES_PER_HOUR = 60;
|
||||
private static final int HOURS_PER_DAY = 24;
|
||||
private static final int SECONDS_PER_DAY = (HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE);
|
||||
|
||||
private static final int BAD_DATE = -1; // used to specify that date is invalid
|
||||
private static final long DAY_MILLISECONDS = SECONDS_PER_DAY * 1000L;
|
||||
|
||||
private static final Pattern TIME_SEPARATOR_PATTERN = Pattern.compile(":");
|
||||
|
||||
/**
|
||||
* Given a Date, converts it into a double representing its internal Excel representation,
|
||||
* which is the number of days since 1/1/1900. Fractional days represent hours, minutes, and seconds.
|
||||
*
|
||||
* @return Excel representation of Date (-1 if error - test for error by checking for less than 0.1)
|
||||
* @param date the Date
|
||||
*/
|
||||
public static double getExcelDate(Date date) {
|
||||
return getExcelDate(date, false);
|
||||
}
|
||||
/**
|
||||
* Given a Date, converts it into a double representing its internal Excel representation,
|
||||
* which is the number of days since 1/1/1900. Fractional days represent hours, minutes, and seconds.
|
||||
*
|
||||
* @return Excel representation of Date (-1 if error - test for error by checking for less than 0.1)
|
||||
* @param date the Date
|
||||
* @param use1904windowing Should 1900 or 1904 date windowing be used?
|
||||
*/
|
||||
public static double getExcelDate(Date date, boolean use1904windowing) {
|
||||
Calendar calStart = new GregorianCalendar();
|
||||
calStart.setTime(date); // If date includes hours, minutes, and seconds, set them to 0
|
||||
return internalGetExcelDate(calStart, use1904windowing);
|
||||
}
|
||||
/**
|
||||
* Given a Date in the form of a Calendar, converts it into a double
|
||||
* representing its internal Excel representation, which is the
|
||||
* number of days since 1/1/1900. Fractional days represent hours,
|
||||
* minutes, and seconds.
|
||||
*
|
||||
* @return Excel representation of Date (-1 if error - test for error by checking for less than 0.1)
|
||||
* @param date the Calendar holding the date to convert
|
||||
* @param use1904windowing Should 1900 or 1904 date windowing be used?
|
||||
*/
|
||||
public static double getExcelDate(Calendar date, boolean use1904windowing) {
|
||||
// Don't alter the supplied Calendar as we do our work
|
||||
return internalGetExcelDate( (Calendar)date.clone(), use1904windowing );
|
||||
}
|
||||
private static double internalGetExcelDate(Calendar date, boolean use1904windowing) {
|
||||
if ((!use1904windowing && date.get(Calendar.YEAR) < 1900) ||
|
||||
(use1904windowing && date.get(Calendar.YEAR) < 1904))
|
||||
{
|
||||
return BAD_DATE;
|
||||
}
|
||||
// Because of daylight time saving we cannot use
|
||||
// date.getTime() - calStart.getTimeInMillis()
|
||||
// as the difference in milliseconds between 00:00 and 04:00
|
||||
// can be 3, 4 or 5 hours but Excel expects it to always
|
||||
// be 4 hours.
|
||||
// E.g. 2004-03-28 04:00 CEST - 2004-03-28 00:00 CET is 3 hours
|
||||
// and 2004-10-31 04:00 CET - 2004-10-31 00:00 CEST is 5 hours
|
||||
double fraction = (((date.get(Calendar.HOUR_OF_DAY) * 60
|
||||
+ date.get(Calendar.MINUTE)
|
||||
) * 60 + date.get(Calendar.SECOND)
|
||||
) * 1000 + date.get(Calendar.MILLISECOND)
|
||||
) / ( double ) DAY_MILLISECONDS;
|
||||
Calendar calStart = dayStart(date);
|
||||
|
||||
double value = fraction + absoluteDay(calStart, use1904windowing);
|
||||
|
||||
if (!use1904windowing && value >= 60) {
|
||||
value++;
|
||||
} else if (use1904windowing) {
|
||||
value--;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an Excel date with using 1900 date windowing, and
|
||||
* converts it to a java.util.Date.
|
||||
*
|
||||
* NOTE: If the default <code>TimeZone</code> in Java uses Daylight
|
||||
* Saving Time then the conversion back to an Excel date may not give
|
||||
* the same value, that is the comparison
|
||||
* <CODE>excelDate == getExcelDate(getJavaDate(excelDate,false))</CODE>
|
||||
* is not always true. For example if default timezone is
|
||||
* <code>Europe/Copenhagen</code>, on 2004-03-28 the minute after
|
||||
* 01:59 CET is 03:00 CEST, if the excel date represents a time between
|
||||
* 02:00 and 03:00 then it is converted to past 03:00 summer time
|
||||
*
|
||||
* @param date The Excel date.
|
||||
* @return Java representation of the date, or null if date is not a valid Excel date
|
||||
* @see java.util.TimeZone
|
||||
*/
|
||||
public static Date getJavaDate(double date) {
|
||||
return getJavaDate(date, false);
|
||||
}
|
||||
/**
|
||||
* Given an Excel date with either 1900 or 1904 date windowing,
|
||||
* converts it to a java.util.Date.
|
||||
*
|
||||
* NOTE: If the default <code>TimeZone</code> in Java uses Daylight
|
||||
* Saving Time then the conversion back to an Excel date may not give
|
||||
* the same value, that is the comparison
|
||||
* <CODE>excelDate == getExcelDate(getJavaDate(excelDate,false))</CODE>
|
||||
* is not always true. For example if default timezone is
|
||||
* <code>Europe/Copenhagen</code>, on 2004-03-28 the minute after
|
||||
* 01:59 CET is 03:00 CEST, if the excel date represents a time between
|
||||
* 02:00 and 03:00 then it is converted to past 03:00 summer time
|
||||
*
|
||||
* @param date The Excel date.
|
||||
* @param use1904windowing true if date uses 1904 windowing,
|
||||
* or false if using 1900 date windowing.
|
||||
* @return Java representation of the date, or null if date is not a valid Excel date
|
||||
* @see java.util.TimeZone
|
||||
*/
|
||||
public static Date getJavaDate(double date, boolean use1904windowing) {
|
||||
if (!isValidExcelDate(date)) {
|
||||
return null;
|
||||
}
|
||||
int wholeDays = (int)Math.floor(date);
|
||||
int millisecondsInDay = (int)((date - wholeDays) * DAY_MILLISECONDS + 0.5);
|
||||
Calendar calendar = new GregorianCalendar(); // using default time-zone
|
||||
setCalendar(calendar, wholeDays, millisecondsInDay, use1904windowing);
|
||||
return calendar.getTime();
|
||||
}
|
||||
public static void setCalendar(Calendar calendar, int wholeDays, int millisecondsInDay,
|
||||
boolean use1904windowing) {
|
||||
int startYear = 1900;
|
||||
int dayAdjust = -1; // Excel thinks 2/29/1900 is a valid date, which it isn't
|
||||
if (use1904windowing) {
|
||||
startYear = 1904;
|
||||
dayAdjust = 1; // 1904 date windowing uses 1/2/1904 as the first day
|
||||
}
|
||||
else if (wholeDays < 61) {
|
||||
// Date is prior to 3/1/1900, so adjust because Excel thinks 2/29/1900 exists
|
||||
// If Excel date == 2/29/1900, will become 3/1/1900 in Java representation
|
||||
dayAdjust = 0;
|
||||
}
|
||||
calendar.set(startYear,0, wholeDays + dayAdjust, 0, 0, 0);
|
||||
calendar.set(GregorianCalendar.MILLISECOND, millisecondsInDay);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a format ID and its format String, will check to see if the
|
||||
* format represents a date format or not.
|
||||
* Firstly, it will check to see if the format ID corresponds to an
|
||||
* internal excel date format (eg most US date formats)
|
||||
* If not, it will check to see if the format string only contains
|
||||
* date formatting characters (ymd-/), which covers most
|
||||
* non US date formats.
|
||||
*
|
||||
* @param formatIndex The index of the format, eg from ExtendedFormatRecord.getFormatIndex
|
||||
* @param formatString The format string, eg from FormatRecord.getFormatString
|
||||
* @see #isInternalDateFormat(int)
|
||||
*/
|
||||
public static boolean isADateFormat(int formatIndex, String formatString) {
|
||||
// First up, is this an internal date format?
|
||||
if(isInternalDateFormat(formatIndex)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If we didn't get a real string, it can't be
|
||||
if(formatString == null || formatString.length() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String fs = formatString;
|
||||
|
||||
// Translate \- into just -, before matching
|
||||
fs = fs.replaceAll("\\\\-","-");
|
||||
// And \, into ,
|
||||
fs = fs.replaceAll("\\\\,",",");
|
||||
// And '\ ' into ' '
|
||||
fs = fs.replaceAll("\\\\ "," ");
|
||||
|
||||
// If it end in ;@, that's some crazy dd/mm vs mm/dd
|
||||
// switching stuff, which we can ignore
|
||||
fs = fs.replaceAll(";@", "");
|
||||
|
||||
// If it starts with [$-...], then could be a date, but
|
||||
// who knows what that starting bit is all about
|
||||
fs = fs.replaceAll("^\\[\\$\\-.*?\\]", "");
|
||||
|
||||
// If it starts with something like [Black] or [Yellow],
|
||||
// then it could be a date
|
||||
fs = fs.replaceAll("^\\[[a-zA-Z]+\\]", "");
|
||||
|
||||
// Otherwise, check it's only made up, in any case, of:
|
||||
// y m d h s - / , . :
|
||||
// optionally followed by AM/PM
|
||||
if(fs.matches("^[yYmMdDhHsS\\-/,. :]+[ampAMP/]*$")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a format ID this will check whether the format represents
|
||||
* an internal excel date format or not.
|
||||
* @see #isADateFormat(int, java.lang.String)
|
||||
*/
|
||||
public static boolean isInternalDateFormat(int format) {
|
||||
switch(format) {
|
||||
// Internal Date Formats as described on page 427 in
|
||||
// Microsoft Excel Dev's Kit...
|
||||
case 0x0e:
|
||||
case 0x0f:
|
||||
case 0x10:
|
||||
case 0x11:
|
||||
case 0x12:
|
||||
case 0x13:
|
||||
case 0x14:
|
||||
case 0x15:
|
||||
case 0x16:
|
||||
case 0x2d:
|
||||
case 0x2e:
|
||||
case 0x2f:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a cell contains a date
|
||||
* Since dates are stored internally in Excel as double values
|
||||
* we infer it is a date if it is formatted as such.
|
||||
* @see #isADateFormat(int, String)
|
||||
* @see #isInternalDateFormat(int)
|
||||
*/
|
||||
public static boolean isCellDateFormatted(HSSFCell cell) {
|
||||
if (cell == null) return false;
|
||||
boolean bDate = false;
|
||||
|
||||
double d = cell.getNumericCellValue();
|
||||
if ( HSSFDateUtil.isValidExcelDate(d) ) {
|
||||
HSSFCellStyle style = cell.getCellStyle();
|
||||
int i = style.getDataFormat();
|
||||
String f = style.getDataFormatString(cell.getBoundWorkbook());
|
||||
bDate = isADateFormat(i, f);
|
||||
}
|
||||
return bDate;
|
||||
}
|
||||
/**
|
||||
* Check if a cell contains a date, checking only for internal
|
||||
* excel date formats.
|
||||
* As Excel stores a great many of its dates in "non-internal"
|
||||
* date formats, you will not normally want to use this method.
|
||||
* @see #isADateFormat(int,String)
|
||||
* @see #isInternalDateFormat(int)
|
||||
*/
|
||||
public static boolean isCellInternalDateFormatted(HSSFCell cell) {
|
||||
if (cell == null) return false;
|
||||
boolean bDate = false;
|
||||
|
||||
double d = cell.getNumericCellValue();
|
||||
if ( HSSFDateUtil.isValidExcelDate(d) ) {
|
||||
HSSFCellStyle style = cell.getCellStyle();
|
||||
int i = style.getDataFormat();
|
||||
bDate = isInternalDateFormat(i);
|
||||
}
|
||||
return bDate;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given a double, checks if it is a valid Excel date.
|
||||
*
|
||||
* @return true if valid
|
||||
* @param value the double value
|
||||
*/
|
||||
|
||||
public static boolean isValidExcelDate(double value)
|
||||
{
|
||||
return (value > -Double.MIN_VALUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a Calendar, return the number of days since 1900/12/31.
|
||||
*
|
||||
* @return days number of days since 1900/12/31
|
||||
* @param cal the Calendar
|
||||
* @exception IllegalArgumentException if date is invalid
|
||||
*/
|
||||
|
||||
static int absoluteDay(Calendar cal, boolean use1904windowing)
|
||||
{
|
||||
return cal.get(Calendar.DAY_OF_YEAR)
|
||||
+ daysInPriorYears(cal.get(Calendar.YEAR), use1904windowing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of days in prior years since 1900
|
||||
*
|
||||
* @return days number of days in years prior to yr.
|
||||
* @param yr a year (1900 < yr < 4000)
|
||||
* @param use1904windowing
|
||||
* @exception IllegalArgumentException if year is outside of range.
|
||||
*/
|
||||
|
||||
private static int daysInPriorYears(int yr, boolean use1904windowing)
|
||||
{
|
||||
if ((!use1904windowing && yr < 1900) || (use1904windowing && yr < 1900)) {
|
||||
throw new IllegalArgumentException("'year' must be 1900 or greater");
|
||||
}
|
||||
|
||||
int yr1 = yr - 1;
|
||||
int leapDays = yr1 / 4 // plus julian leap days in prior years
|
||||
- yr1 / 100 // minus prior century years
|
||||
+ yr1 / 400 // plus years divisible by 400
|
||||
- 460; // leap days in previous 1900 years
|
||||
|
||||
return 365 * (yr - (use1904windowing ? 1904 : 1900)) + leapDays;
|
||||
}
|
||||
|
||||
// set HH:MM:SS fields of cal to 00:00:00:000
|
||||
private static Calendar dayStart(final Calendar cal)
|
||||
{
|
||||
cal.get(Calendar
|
||||
.HOUR_OF_DAY); // force recalculation of internal fields
|
||||
cal.set(Calendar.HOUR_OF_DAY, 0);
|
||||
cal.set(Calendar.MINUTE, 0);
|
||||
cal.set(Calendar.SECOND, 0);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
cal.get(Calendar
|
||||
.HOUR_OF_DAY); // force recalculation of internal fields
|
||||
return cal;
|
||||
}
|
||||
|
||||
|
||||
private static final class FormatException extends Exception {
|
||||
public FormatException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a string of format "HH:MM" or "HH:MM:SS" to its (Excel) numeric equivalent
|
||||
*
|
||||
* @return a double between 0 and 1 representing the fraction of the day
|
||||
*/
|
||||
public static double convertTime(String timeStr) {
|
||||
try {
|
||||
return convertTimeInternal(timeStr);
|
||||
} catch (FormatException e) {
|
||||
String msg = "Bad time format '" + timeStr
|
||||
+ "' expected 'HH:MM' or 'HH:MM:SS' - " + e.getMessage();
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
}
|
||||
private static double convertTimeInternal(String timeStr) throws FormatException {
|
||||
int len = timeStr.length();
|
||||
if (len < 4 || len > 8) {
|
||||
throw new FormatException("Bad length");
|
||||
}
|
||||
String[] parts = TIME_SEPARATOR_PATTERN.split(timeStr);
|
||||
|
||||
String secStr;
|
||||
switch (parts.length) {
|
||||
case 2: secStr = "00"; break;
|
||||
case 3: secStr = parts[2]; break;
|
||||
default:
|
||||
throw new FormatException("Expected 2 or 3 fields but got (" + parts.length + ")");
|
||||
}
|
||||
String hourStr = parts[0];
|
||||
String minStr = parts[1];
|
||||
int hours = parseInt(hourStr, "hour", HOURS_PER_DAY);
|
||||
int minutes = parseInt(minStr, "minute", MINUTES_PER_HOUR);
|
||||
int seconds = parseInt(secStr, "second", SECONDS_PER_MINUTE);
|
||||
|
||||
double totalSeconds = seconds + (minutes + (hours) * 60) * 60;
|
||||
return totalSeconds / (SECONDS_PER_DAY);
|
||||
}
|
||||
/**
|
||||
* Converts a string of format "YYYY/MM/DD" to its (Excel) numeric equivalent
|
||||
*
|
||||
* @return a double representing the (integer) number of days since the start of the Excel epoch
|
||||
*/
|
||||
public static Date parseYYYYMMDDDate(String dateStr) {
|
||||
try {
|
||||
return parseYYYYMMDDDateInternal(dateStr);
|
||||
} catch (FormatException e) {
|
||||
String msg = "Bad time format " + dateStr
|
||||
+ " expected 'YYYY/MM/DD' - " + e.getMessage();
|
||||
throw new IllegalArgumentException(msg);
|
||||
}
|
||||
}
|
||||
private static Date parseYYYYMMDDDateInternal(String timeStr) throws FormatException {
|
||||
if(timeStr.length() != 10) {
|
||||
throw new FormatException("Bad length");
|
||||
}
|
||||
|
||||
String yearStr = timeStr.substring(0, 4);
|
||||
String monthStr = timeStr.substring(5, 7);
|
||||
String dayStr = timeStr.substring(8, 10);
|
||||
int year = parseInt(yearStr, "year", Short.MIN_VALUE, Short.MAX_VALUE);
|
||||
int month = parseInt(monthStr, "month", 1, 12);
|
||||
int day = parseInt(dayStr, "day", 1, 31);
|
||||
|
||||
Calendar cal = new GregorianCalendar(year, month-1, day, 0, 0, 0);
|
||||
cal.set(Calendar.MILLISECOND, 0);
|
||||
return cal.getTime();
|
||||
}
|
||||
private static int parseInt(String strVal, String fieldName, int rangeMax) throws FormatException {
|
||||
return parseInt(strVal, fieldName, 0, rangeMax-1);
|
||||
}
|
||||
|
||||
private static int parseInt(String strVal, String fieldName, int lowerLimit, int upperLimit) throws FormatException {
|
||||
int result;
|
||||
try {
|
||||
result = Integer.parseInt(strVal);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new FormatException("Bad int format '" + strVal + "' for " + fieldName + " field");
|
||||
}
|
||||
if (result < lowerLimit || result > upperLimit) {
|
||||
throw new FormatException(fieldName + " value (" + result
|
||||
+ ") is outside the allowable range(0.." + upperLimit + ")");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public class HSSFDateUtil extends DateUtil {
|
||||
protected static int absoluteDay(Calendar cal, boolean use1904windowing) {
|
||||
return DateUtil.absoluteDay(cal, use1904windowing);
|
||||
}
|
||||
}
|
||||
|
@ -16,67 +16,12 @@
|
||||
==================================================================== */
|
||||
|
||||
package org.apache.poi.hssf.usermodel;
|
||||
import org.apache.poi.ss.usermodel.ErrorConstants;
|
||||
|
||||
/**
|
||||
* Contains raw Excel error codes (as defined in OOO's excelfileformat.pdf (2.5.6)
|
||||
*
|
||||
* @author Michael Harhen
|
||||
*/
|
||||
public final class HSSFErrorConstants {
|
||||
private HSSFErrorConstants() {
|
||||
// no instances of this class
|
||||
}
|
||||
|
||||
/** <b>#NULL!</b> - Intersection of two cell ranges is empty */
|
||||
public static final int ERROR_NULL = 0x00;
|
||||
/** <b>#DIV/0!</b> - Division by zero */
|
||||
public static final int ERROR_DIV_0 = 0x07;
|
||||
/** <b>#VALUE!</b> - Wrong type of operand */
|
||||
public static final int ERROR_VALUE = 0x0F;
|
||||
/** <b>#REF!</b> - Illegal or deleted cell reference */
|
||||
public static final int ERROR_REF = 0x17;
|
||||
/** <b>#NAME?</b> - Wrong function or range name */
|
||||
public static final int ERROR_NAME = 0x1D;
|
||||
/** <b>#NUM!</b> - Value range overflow */
|
||||
public static final int ERROR_NUM = 0x24;
|
||||
/** <b>#N/A</b> - Argument or function not available */
|
||||
public static final int ERROR_NA = 0x2A;
|
||||
|
||||
|
||||
/**
|
||||
* @return Standard Excel error literal for the specified error code.
|
||||
* @throws IllegalArgumentException if the specified error code is not one of the 7
|
||||
* standard error codes
|
||||
*/
|
||||
public static final String getText(int errorCode) {
|
||||
switch(errorCode) {
|
||||
case ERROR_NULL: return "#NULL!";
|
||||
case ERROR_DIV_0: return "#DIV/0!";
|
||||
case ERROR_VALUE: return "#VALUE!";
|
||||
case ERROR_REF: return "#REF!";
|
||||
case ERROR_NAME: return "#NAME?";
|
||||
case ERROR_NUM: return "#NUM!";
|
||||
case ERROR_NA: return "#N/A";
|
||||
}
|
||||
throw new IllegalArgumentException("Bad error code (" + errorCode + ")");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return <code>true</code> if the specified error code is a standard Excel error code.
|
||||
*/
|
||||
public static final boolean isValidCode(int errorCode) {
|
||||
// This method exists because it would be bad to force clients to catch
|
||||
// IllegalArgumentException if there were potential for passing an invalid error code.
|
||||
switch(errorCode) {
|
||||
case ERROR_NULL:
|
||||
case ERROR_DIV_0:
|
||||
case ERROR_VALUE:
|
||||
case ERROR_REF:
|
||||
case ERROR_NAME:
|
||||
case ERROR_NUM:
|
||||
case ERROR_NA:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public final class HSSFErrorConstants extends ErrorConstants {
|
||||
}
|
||||
|
@ -24,6 +24,7 @@
|
||||
package org.apache.poi.hssf.usermodel;
|
||||
|
||||
import org.apache.poi.hssf.record.FontRecord;
|
||||
import org.apache.poi.ss.usermodel.Font;
|
||||
|
||||
/**
|
||||
* Represents a Font used in a workbook.
|
||||
@ -35,103 +36,9 @@ import org.apache.poi.hssf.record.FontRecord;
|
||||
* @see org.apache.poi.hssf.usermodel.HSSFCellStyle#setFont(HSSFFont)
|
||||
*/
|
||||
|
||||
public class HSSFFont
|
||||
public class HSSFFont implements Font
|
||||
{
|
||||
|
||||
/**
|
||||
* Arial font
|
||||
*/
|
||||
|
||||
public final static String FONT_ARIAL = "Arial";
|
||||
|
||||
/**
|
||||
* Normal boldness (not bold)
|
||||
*/
|
||||
|
||||
public final static short BOLDWEIGHT_NORMAL = 0x190;
|
||||
|
||||
/**
|
||||
* Bold boldness (bold)
|
||||
*/
|
||||
|
||||
public final static short BOLDWEIGHT_BOLD = 0x2bc;
|
||||
|
||||
/**
|
||||
* normal type of black color.
|
||||
*/
|
||||
|
||||
public final static short COLOR_NORMAL = 0x7fff;
|
||||
|
||||
/**
|
||||
* Dark Red color
|
||||
*/
|
||||
|
||||
public final static short COLOR_RED = 0xa;
|
||||
|
||||
/**
|
||||
* no type offsetting (not super or subscript)
|
||||
*/
|
||||
|
||||
public final static short SS_NONE = 0;
|
||||
|
||||
/**
|
||||
* superscript
|
||||
*/
|
||||
|
||||
public final static short SS_SUPER = 1;
|
||||
|
||||
/**
|
||||
* subscript
|
||||
*/
|
||||
|
||||
public final static short SS_SUB = 2;
|
||||
|
||||
/**
|
||||
* not underlined
|
||||
*/
|
||||
|
||||
public final static byte U_NONE = 0;
|
||||
|
||||
/**
|
||||
* single (normal) underline
|
||||
*/
|
||||
|
||||
public final static byte U_SINGLE = 1;
|
||||
|
||||
/**
|
||||
* double underlined
|
||||
*/
|
||||
|
||||
public final static byte U_DOUBLE = 2;
|
||||
|
||||
/**
|
||||
* accounting style single underline
|
||||
*/
|
||||
|
||||
public final static byte U_SINGLE_ACCOUNTING = 0x21;
|
||||
|
||||
/**
|
||||
* accounting style double underline
|
||||
*/
|
||||
|
||||
public final static byte U_DOUBLE_ACCOUNTING = 0x22;
|
||||
|
||||
/**
|
||||
* ANSI character set
|
||||
*/
|
||||
public final static byte ANSI_CHARSET = 0;
|
||||
|
||||
/**
|
||||
* Default character set.
|
||||
*/
|
||||
public final static byte DEFAULT_CHARSET = 1;
|
||||
|
||||
/**
|
||||
* Symbol character set
|
||||
*/
|
||||
public final static byte SYMBOL_CHARSET = 2;
|
||||
|
||||
|
||||
|
||||
private FontRecord font;
|
||||
private short index;
|
||||
|
@ -19,6 +19,7 @@
|
||||
package org.apache.poi.hssf.usermodel;
|
||||
|
||||
import org.apache.poi.hssf.record.FooterRecord;
|
||||
import org.apache.poi.ss.usermodel.Footer;
|
||||
|
||||
/**
|
||||
* Class to read and manipulate the footer.
|
||||
@ -32,7 +33,7 @@ import org.apache.poi.hssf.record.FooterRecord;
|
||||
* <P>
|
||||
* @author Shawn Laubach (slaubach at apache dot org)
|
||||
*/
|
||||
public class HSSFFooter extends HeaderFooter {
|
||||
public class HSSFFooter extends HeaderFooter implements Footer {
|
||||
private FooterRecord footerRecord;
|
||||
|
||||
/**
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user