mirror of
https://github.com/apache/poi.git
synced 2025-03-08 18:29:57 +00:00
more cleanup and refactoring of the ooxml code:1. removed deprecated methods from xssf and interfaces
2. minimized the accessibility of internal constructors 3. more javadocs git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@707839 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
67412a0678
commit
db877653b7
@ -20,6 +20,7 @@ import org.apache.poi.ss.usermodel.Workbook;
|
|||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
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.XSSFWorkbook;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
||||||
import org.apache.poi.hssf.util.Region;
|
import org.apache.poi.hssf.util.Region;
|
||||||
@ -38,7 +39,7 @@ public class MergingCells {
|
|||||||
Cell cell = row.createCell((short) 1);
|
Cell cell = row.createCell((short) 1);
|
||||||
cell.setCellValue(new XSSFRichTextString("This is a test of merging"));
|
cell.setCellValue(new XSSFRichTextString("This is a test of merging"));
|
||||||
|
|
||||||
sheet.addMergedRegion(new Region(1,(short)1,1,(short)2));
|
sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 2));
|
||||||
|
|
||||||
// Write the output to a file
|
// Write the output to a file
|
||||||
FileOutputStream fileOut = new FileOutputStream("merging_cells.xlsx");
|
FileOutputStream fileOut = new FileOutputStream("merging_cells.xlsx");
|
||||||
|
@ -50,4 +50,21 @@ public class CellRangeAddress extends CellRangeAddressBase {
|
|||||||
public static int getEncodedSize(int numberOfItems) {
|
public static int getEncodedSize(int numberOfItems) {
|
||||||
return numberOfItems * ENCODED_SIZE;
|
return numberOfItems * ENCODED_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String formatAsString() {
|
||||||
|
StringBuffer sb = new StringBuffer();
|
||||||
|
CellReference cellRefFrom = new CellReference(getFirstRow(), getFirstColumn());
|
||||||
|
CellReference cellRefTo = new CellReference(getLastRow(), getLastColumn());
|
||||||
|
sb.append(cellRefFrom.formatAsString());
|
||||||
|
sb.append(':');
|
||||||
|
sb.append(cellRefTo.formatAsString());
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CellRangeAddress valueOf(String ref) {
|
||||||
|
int sep = ref.indexOf(":");
|
||||||
|
CellReference cellFrom = new CellReference(ref.substring(0, sep));
|
||||||
|
CellReference cellTo = new CellReference(ref.substring(sep + 1));
|
||||||
|
return new CellRangeAddress(cellFrom.getRow(), cellTo.getRow(), cellFrom.getCol(), cellTo.getCol());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ import java.util.Iterator;
|
|||||||
|
|
||||||
import org.apache.poi.hssf.util.PaneInformation;
|
import org.apache.poi.hssf.util.PaneInformation;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.ss.util.Region;
|
|
||||||
|
|
||||||
public interface Sheet extends Iterable<Row> {
|
public interface Sheet extends Iterable<Row> {
|
||||||
|
|
||||||
@ -197,11 +196,6 @@ public interface Sheet extends Iterable<Row> {
|
|||||||
*/
|
*/
|
||||||
int addMergedRegion(CellRangeAddress region);
|
int addMergedRegion(CellRangeAddress region);
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated (Aug-2008) use {@link #addMergedRegion(CellRangeAddress)}
|
|
||||||
*/
|
|
||||||
int addMergedRegion(Region region);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* determines whether the output is vertically centered on the page.
|
* determines whether the output is vertically centered on the page.
|
||||||
* @param value true to vertically center, false otherwise.
|
* @param value true to vertically center, false otherwise.
|
||||||
@ -236,14 +230,6 @@ public interface Sheet extends Iterable<Row> {
|
|||||||
|
|
||||||
int getNumMergedRegions();
|
int getNumMergedRegions();
|
||||||
|
|
||||||
/**
|
|
||||||
* gets the region at a particular index
|
|
||||||
* @param index of the region to fetch
|
|
||||||
* @return the merged region (simple eh?)
|
|
||||||
*/
|
|
||||||
|
|
||||||
Region getMergedRegionAt(int index);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return an iterator of the PHYSICAL rows. Meaning the 3rd element may not
|
* @return an iterator of the PHYSICAL rows. Meaning the 3rd element may not
|
||||||
* be the third row if say for instance the second row is undefined.
|
* be the third row if say for instance the second row is undefined.
|
||||||
@ -300,20 +286,6 @@ public interface Sheet extends Iterable<Row> {
|
|||||||
|
|
||||||
void setRowSumsRight(boolean b);
|
void setRowSumsRight(boolean b);
|
||||||
|
|
||||||
/**
|
|
||||||
* whether alternate expression evaluation is on
|
|
||||||
* @return alternative expression evaluation or not
|
|
||||||
*/
|
|
||||||
|
|
||||||
boolean getAlternateExpression();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* whether alternative formula entry is on
|
|
||||||
* @return alternative formulas or not
|
|
||||||
*/
|
|
||||||
|
|
||||||
boolean getAlternateFormula();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* show automatic page breaks or not
|
* show automatic page breaks or not
|
||||||
* @return whether to show auto page breaks
|
* @return whether to show auto page breaks
|
||||||
@ -411,29 +383,12 @@ public interface Sheet extends Iterable<Row> {
|
|||||||
*/
|
*/
|
||||||
boolean getProtect();
|
boolean getProtect();
|
||||||
|
|
||||||
/**
|
|
||||||
* @return hashed password
|
|
||||||
*/
|
|
||||||
short getPassword();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Answer whether object protection is enabled or disabled
|
|
||||||
* @return true => protection enabled; false => protection disabled
|
|
||||||
*/
|
|
||||||
boolean getObjectProtect();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Answer whether scenario protection is enabled or disabled
|
* Answer whether scenario protection is enabled or disabled
|
||||||
* @return true => protection enabled; false => protection disabled
|
* @return true => protection enabled; false => protection disabled
|
||||||
*/
|
*/
|
||||||
boolean getScenarioProtect();
|
boolean getScenarioProtect();
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the protection enabled as well as the password
|
|
||||||
* @param password to set for protection
|
|
||||||
*/
|
|
||||||
void protectSheet(String password);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the zoom magnication for the sheet. The zoom is expressed as a
|
* Sets the zoom magnication for the sheet. The zoom is expressed as a
|
||||||
* fraction. For example to express a zoom of 75% use 3 for the numerator
|
* fraction. For example to express a zoom of 75% use 3 for the numerator
|
||||||
|
@ -375,13 +375,6 @@ public interface Workbook {
|
|||||||
*/
|
*/
|
||||||
List getAllPictures();
|
List getAllPictures();
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets all embedded OLE2 objects from the Workbook.
|
|
||||||
*
|
|
||||||
* @return the list of embedded objects
|
|
||||||
*/
|
|
||||||
List getAllEmbeddedObjects();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an object that handles instantiating concrete
|
* Returns an object that handles instantiating concrete
|
||||||
* classes of the various instances one needs for
|
* classes of the various instances one needs for
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package org.apache.poi;
|
package org.apache.poi;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.poi.poifs.common.POIFSConstants;
|
import org.apache.poi.poifs.common.POIFSConstants;
|
||||||
@ -48,19 +47,9 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart{
|
|||||||
*/
|
*/
|
||||||
private POIXMLProperties properties;
|
private POIXMLProperties properties;
|
||||||
|
|
||||||
protected POIXMLDocument() {
|
protected POIXMLDocument(Package pkg) {
|
||||||
super(null, null);
|
super(pkg);
|
||||||
try {
|
this.pkg = pkg;
|
||||||
Package pkg = newPackage();
|
|
||||||
initialize(pkg);
|
|
||||||
} catch (IOException e){
|
|
||||||
throw new POIXMLException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected POIXMLDocument(Package pkg) throws IOException {
|
|
||||||
super(null, null);
|
|
||||||
initialize(pkg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -76,36 +65,12 @@ public abstract class POIXMLDocument extends POIXMLDocumentPart{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initialize(Package pkg) throws IOException {
|
|
||||||
try {
|
|
||||||
this.pkg = pkg;
|
|
||||||
|
|
||||||
PackageRelationship coreDocRelationship = this.pkg.getRelationshipsByType(
|
|
||||||
PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);
|
|
||||||
|
|
||||||
// Get core part
|
|
||||||
this.packagePart = this.pkg.getPart(coreDocRelationship);
|
|
||||||
this.packageRel = coreDocRelationship;
|
|
||||||
|
|
||||||
// Verify it's there
|
|
||||||
if(this.packagePart == null) {
|
|
||||||
throw new IllegalArgumentException("No core part found for this document! Nothing with " + coreDocRelationship.getRelationshipType() + " present as a relation.");
|
|
||||||
}
|
|
||||||
} catch (OpenXML4JException e) {
|
|
||||||
throw new IOException(e.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Package newPackage() throws IOException {
|
|
||||||
throw new POIXMLException("Must be overridden");
|
|
||||||
}
|
|
||||||
|
|
||||||
public Package getPackage() {
|
public Package getPackage() {
|
||||||
return this.pkg;
|
return this.pkg;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PackagePart getCorePart() {
|
protected PackagePart getCorePart() {
|
||||||
return this.packagePart;
|
return getPackagePart();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,6 +25,7 @@ import org.apache.poi.util.POILogger;
|
|||||||
import org.apache.poi.util.POILogFactory;
|
import org.apache.poi.util.POILogFactory;
|
||||||
import org.openxml4j.exceptions.OpenXML4JException;
|
import org.openxml4j.exceptions.OpenXML4JException;
|
||||||
import org.openxml4j.opc.*;
|
import org.openxml4j.opc.*;
|
||||||
|
import org.openxml4j.opc.Package;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an entry of a OOXML package.
|
* Represents an entry of a OOXML package.
|
||||||
@ -38,7 +39,7 @@ import org.openxml4j.opc.*;
|
|||||||
public class POIXMLDocumentPart {
|
public class POIXMLDocumentPart {
|
||||||
private static POILogger logger = POILogFactory.getLogger(POIXMLDocumentPart.class);
|
private static POILogger logger = POILogFactory.getLogger(POIXMLDocumentPart.class);
|
||||||
|
|
||||||
public static XmlOptions DEFAULT_XML_OPTIONS;
|
public static final XmlOptions DEFAULT_XML_OPTIONS;
|
||||||
static {
|
static {
|
||||||
DEFAULT_XML_OPTIONS = new XmlOptions();
|
DEFAULT_XML_OPTIONS = new XmlOptions();
|
||||||
DEFAULT_XML_OPTIONS.setSaveOuter();
|
DEFAULT_XML_OPTIONS.setSaveOuter();
|
||||||
@ -46,14 +47,46 @@ public class POIXMLDocumentPart {
|
|||||||
DEFAULT_XML_OPTIONS.setSaveAggressiveNamespaces();
|
DEFAULT_XML_OPTIONS.setSaveAggressiveNamespaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PackagePart packagePart;
|
private PackagePart packagePart;
|
||||||
protected PackageRelationship packageRel;
|
private PackageRelationship packageRel;
|
||||||
protected POIXMLDocumentPart parent;
|
private POIXMLDocumentPart parent;
|
||||||
|
private List<POIXMLDocumentPart> relations;
|
||||||
|
|
||||||
protected List<POIXMLDocumentPart> relations;
|
/**
|
||||||
|
* Construct POIXMLDocumentPart representing a "core document" package part.
|
||||||
|
*/
|
||||||
|
public POIXMLDocumentPart(Package pkg) {
|
||||||
|
try {
|
||||||
|
PackageRelationship coreRel = pkg.getRelationshipsByType(
|
||||||
|
PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);
|
||||||
|
|
||||||
|
this.relations = new LinkedList<POIXMLDocumentPart>();
|
||||||
|
this.packagePart = pkg.getPart(coreRel);
|
||||||
|
this.packageRel = coreRel;
|
||||||
|
} catch (OpenXML4JException e){
|
||||||
|
throw new POIXMLException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new POIXMLDocumentPart - called by client code to create new parts from scratch.
|
||||||
|
*
|
||||||
|
* @see #createRelationship(POIXMLRelation, POIXMLFactory, int, boolean)
|
||||||
|
*/
|
||||||
|
public POIXMLDocumentPart(){
|
||||||
|
this.relations = new LinkedList<POIXMLDocumentPart>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an POIXMLDocumentPart representing the given package part and relationship.
|
||||||
|
* Called by {@link #read(POIXMLFactory)} when reading in an exisiting file.
|
||||||
|
*
|
||||||
|
* @param part - The package part that holds xml data represenring this sheet.
|
||||||
|
* @param rel - the relationship of the given package part
|
||||||
|
* @see #read(POIXMLFactory)
|
||||||
|
*/
|
||||||
public POIXMLDocumentPart(PackagePart part, PackageRelationship rel){
|
public POIXMLDocumentPart(PackagePart part, PackageRelationship rel){
|
||||||
relations = new LinkedList<POIXMLDocumentPart>();
|
this.relations = new LinkedList<POIXMLDocumentPart>();
|
||||||
this.packagePart = part;
|
this.packagePart = part;
|
||||||
this.packageRel = rel;
|
this.packageRel = rel;
|
||||||
}
|
}
|
||||||
@ -63,7 +96,7 @@ public class POIXMLDocumentPart {
|
|||||||
*
|
*
|
||||||
* @return the underlying PackagePart
|
* @return the underlying PackagePart
|
||||||
*/
|
*/
|
||||||
public PackagePart getPackagePart(){
|
public final PackagePart getPackagePart(){
|
||||||
return packagePart;
|
return packagePart;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +105,7 @@ public class POIXMLDocumentPart {
|
|||||||
*
|
*
|
||||||
* @return the PackageRelationship that identifies this POIXMLDocumentPart
|
* @return the PackageRelationship that identifies this POIXMLDocumentPart
|
||||||
*/
|
*/
|
||||||
public PackageRelationship getPackageRelationship(){
|
public final PackageRelationship getPackageRelationship(){
|
||||||
return packageRel;
|
return packageRel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +114,7 @@ public class POIXMLDocumentPart {
|
|||||||
*
|
*
|
||||||
* @return child relations
|
* @return child relations
|
||||||
*/
|
*/
|
||||||
public List<POIXMLDocumentPart> getRelations(){
|
public final List<POIXMLDocumentPart> getRelations(){
|
||||||
return relations;
|
return relations;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +123,7 @@ public class POIXMLDocumentPart {
|
|||||||
*
|
*
|
||||||
* @param part the child to add
|
* @param part the child to add
|
||||||
*/
|
*/
|
||||||
protected void addRelation(POIXMLDocumentPart part){
|
protected final void addRelation(POIXMLDocumentPart part){
|
||||||
relations.add(part);
|
relations.add(part);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +132,7 @@ public class POIXMLDocumentPart {
|
|||||||
*
|
*
|
||||||
* @return the parent POIXMLDocumentPart or <code>null</code> for the root element.
|
* @return the parent POIXMLDocumentPart or <code>null</code> for the root element.
|
||||||
*/
|
*/
|
||||||
public POIXMLDocumentPart getParent(){
|
public final POIXMLDocumentPart getParent(){
|
||||||
return parent;
|
return parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -132,11 +165,12 @@ public class POIXMLDocumentPart {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Save changes in the underlying OOXML package.
|
* Save changes in the underlying OOXML package.
|
||||||
|
* Recursively fires {@link #commit()} for each package part
|
||||||
*/
|
*/
|
||||||
protected void save() throws IOException{
|
protected final void onSave() throws IOException{
|
||||||
commit();
|
commit();
|
||||||
for(POIXMLDocumentPart p : relations){
|
for(POIXMLDocumentPart p : relations){
|
||||||
p.save();
|
p.onSave();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,11 +181,11 @@ public class POIXMLDocumentPart {
|
|||||||
* @param factory the factory that will create an instance of the requested relation
|
* @param factory the factory that will create an instance of the requested relation
|
||||||
* @return the created child POIXMLDocumentPart
|
* @return the created child POIXMLDocumentPart
|
||||||
*/
|
*/
|
||||||
protected POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory){
|
protected final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory){
|
||||||
return createRelationship(descriptor, factory, -1, false);
|
return createRelationship(descriptor, factory, -1, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx){
|
protected final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx){
|
||||||
return createRelationship(descriptor, factory, idx, false);
|
return createRelationship(descriptor, factory, idx, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,7 +198,7 @@ public class POIXMLDocumentPart {
|
|||||||
* @param noRelation if true, then no relationship is added.
|
* @param noRelation if true, then no relationship is added.
|
||||||
* @return the created child POIXMLDocumentPart
|
* @return the created child POIXMLDocumentPart
|
||||||
*/
|
*/
|
||||||
protected POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, boolean noRelation){
|
protected final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, boolean noRelation){
|
||||||
try {
|
try {
|
||||||
|
|
||||||
PackagePartName ppName = PackagingURIHelper.createPartName(descriptor.getFileName(idx));
|
PackagePartName ppName = PackagingURIHelper.createPartName(descriptor.getFileName(idx));
|
||||||
@ -176,7 +210,6 @@ public class POIXMLDocumentPart {
|
|||||||
doc.packageRel = rel;
|
doc.packageRel = rel;
|
||||||
doc.packagePart = part;
|
doc.packagePart = part;
|
||||||
doc.parent = this;
|
doc.parent = this;
|
||||||
doc.onDocumentCreate();
|
|
||||||
addRelation(doc);
|
addRelation(doc);
|
||||||
return doc;
|
return doc;
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
@ -190,7 +223,7 @@ public class POIXMLDocumentPart {
|
|||||||
*
|
*
|
||||||
* @param factory the factory object that creates POIXMLFactory instances
|
* @param factory the factory object that creates POIXMLFactory instances
|
||||||
*/
|
*/
|
||||||
protected void read(POIXMLFactory factory) throws OpenXML4JException {
|
protected final void read(POIXMLFactory factory) throws OpenXML4JException {
|
||||||
PackageRelationshipCollection rels = packagePart.getRelationships();
|
PackageRelationshipCollection rels = packagePart.getRelationships();
|
||||||
for (PackageRelationship rel : rels) {
|
for (PackageRelationship rel : rels) {
|
||||||
if(rel.getTargetMode() == TargetMode.INTERNAL){
|
if(rel.getTargetMode() == TargetMode.INTERNAL){
|
||||||
@ -202,7 +235,6 @@ public class POIXMLDocumentPart {
|
|||||||
}
|
}
|
||||||
POIXMLDocumentPart childPart = factory.createDocumentPart(rel, p);
|
POIXMLDocumentPart childPart = factory.createDocumentPart(rel, p);
|
||||||
childPart.parent = this;
|
childPart.parent = this;
|
||||||
childPart.onDocumentRead();
|
|
||||||
addRelation(childPart);
|
addRelation(childPart);
|
||||||
|
|
||||||
if(p.hasRelationships()) childPart.read(factory);
|
if(p.hasRelationships()) childPart.read(factory);
|
||||||
@ -210,17 +242,19 @@ public class POIXMLDocumentPart {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fired when a new package part is created
|
* Fired when a new package part is created
|
||||||
*/
|
*/
|
||||||
protected void onDocumentCreate(){
|
protected void onDocumentCreate() throws IOException {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fired when a package part is read
|
* Fired when a package part is read
|
||||||
*/
|
*/
|
||||||
protected void onDocumentRead(){
|
protected void onDocumentRead() throws IOException{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -34,11 +34,11 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CommentsDocument;
|
|||||||
import org.openxml4j.opc.PackagePart;
|
import org.openxml4j.opc.PackagePart;
|
||||||
import org.openxml4j.opc.PackageRelationship;
|
import org.openxml4j.opc.PackageRelationship;
|
||||||
|
|
||||||
public class CommentsTable extends POIXMLDocumentPart implements CommentsSource {
|
public class CommentsTable extends POIXMLDocumentPart {
|
||||||
protected CTComments comments;
|
protected CTComments comments;
|
||||||
|
|
||||||
public CommentsTable() {
|
public CommentsTable() {
|
||||||
super(null, null);
|
super();
|
||||||
comments = CTComments.Factory.newInstance();
|
comments = CTComments.Factory.newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,16 +56,9 @@ public class CommentsTable extends POIXMLDocumentPart implements CommentsSource
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void writeTo(OutputStream out) throws IOException {
|
public void writeTo(OutputStream out) throws IOException {
|
||||||
XmlOptions options = new XmlOptions();
|
CommentsDocument doc = CommentsDocument.Factory.newInstance();
|
||||||
options.setSaveOuter();
|
|
||||||
options.setUseDefaultNamespace();
|
|
||||||
|
|
||||||
// Requests use of whitespace for easier reading
|
|
||||||
//options.setSavePrettyPrint();
|
|
||||||
|
|
||||||
CommentsDocument doc = CommentsDocument.Factory.newInstance(options);
|
|
||||||
doc.setComments(comments);
|
doc.setComments(comments);
|
||||||
doc.save(out, options);
|
doc.save(out, DEFAULT_XML_OPTIONS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -86,7 +86,7 @@ public class SharedStringsTable extends POIXMLDocumentPart {
|
|||||||
private int uniqueCount;
|
private int uniqueCount;
|
||||||
|
|
||||||
public SharedStringsTable() {
|
public SharedStringsTable() {
|
||||||
super(null, null);
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SharedStringsTable(PackagePart part, PackageRelationship rel) throws IOException {
|
public SharedStringsTable(PackagePart part, PackageRelationship rel) throws IOException {
|
||||||
|
@ -64,8 +64,8 @@ import org.openxml4j.opc.PackageRelationship;
|
|||||||
*
|
*
|
||||||
* @author ugo
|
* @author ugo
|
||||||
*/
|
*/
|
||||||
public class StylesTable extends POIXMLDocumentPart implements StylesSource {
|
public class StylesTable extends POIXMLDocumentPart {
|
||||||
private final Hashtable<Long,String> numberFormats = new Hashtable<Long,String>();
|
private final Hashtable<Integer, String> numberFormats = new Hashtable<Integer,String>();
|
||||||
private final List<XSSFFont> fonts = new ArrayList<XSSFFont>();
|
private final List<XSSFFont> fonts = new ArrayList<XSSFFont>();
|
||||||
private final List<XSSFCellFill> fills = new ArrayList<XSSFCellFill>();
|
private final List<XSSFCellFill> fills = new ArrayList<XSSFCellFill>();
|
||||||
private final List<XSSFCellBorder> borders = new ArrayList<XSSFCellBorder>();
|
private final List<XSSFCellBorder> borders = new ArrayList<XSSFCellBorder>();
|
||||||
@ -77,7 +77,7 @@ public class StylesTable extends POIXMLDocumentPart implements StylesSource {
|
|||||||
/**
|
/**
|
||||||
* The first style id available for use as a custom style
|
* The first style id available for use as a custom style
|
||||||
*/
|
*/
|
||||||
public static final long FIRST_CUSTOM_STYLE_ID = 165;
|
public static final int FIRST_CUSTOM_STYLE_ID = 165;
|
||||||
|
|
||||||
private StyleSheetDocument doc;
|
private StyleSheetDocument doc;
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ public class StylesTable extends POIXMLDocumentPart implements StylesSource {
|
|||||||
* Create a new, empty StylesTable
|
* Create a new, empty StylesTable
|
||||||
*/
|
*/
|
||||||
public StylesTable() {
|
public StylesTable() {
|
||||||
super(null, null);
|
super();
|
||||||
doc = StyleSheetDocument.Factory.newInstance();
|
doc = StyleSheetDocument.Factory.newInstance();
|
||||||
doc.addNewStyleSheet();
|
doc.addNewStyleSheet();
|
||||||
// Initialization required in order to make the document readable by MSExcel
|
// Initialization required in order to make the document readable by MSExcel
|
||||||
@ -109,7 +109,7 @@ public class StylesTable extends POIXMLDocumentPart implements StylesSource {
|
|||||||
// Grab all the different bits we care about
|
// Grab all the different bits we care about
|
||||||
if(doc.getStyleSheet().getNumFmts() != null)
|
if(doc.getStyleSheet().getNumFmts() != null)
|
||||||
for (CTNumFmt nfmt : doc.getStyleSheet().getNumFmts().getNumFmtArray()) {
|
for (CTNumFmt nfmt : doc.getStyleSheet().getNumFmts().getNumFmtArray()) {
|
||||||
numberFormats.put(nfmt.getNumFmtId(), nfmt.getFormatCode());
|
numberFormats.put((int)nfmt.getNumFmtId(), nfmt.getFormatCode());
|
||||||
}
|
}
|
||||||
if(doc.getStyleSheet().getFonts() != null){
|
if(doc.getStyleSheet().getFonts() != null){
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
@ -150,14 +150,14 @@ public class StylesTable extends POIXMLDocumentPart implements StylesSource {
|
|||||||
// Start of style related getters and setters
|
// Start of style related getters and setters
|
||||||
// ===========================================================
|
// ===========================================================
|
||||||
|
|
||||||
public String getNumberFormatAt(long idx) {
|
public String getNumberFormatAt(int idx) {
|
||||||
return numberFormats.get(idx);
|
return numberFormats.get(idx);
|
||||||
}
|
}
|
||||||
public synchronized long putNumberFormat(String fmt) {
|
public synchronized int putNumberFormat(String fmt) {
|
||||||
if (numberFormats.containsValue(fmt)) {
|
if (numberFormats.containsValue(fmt)) {
|
||||||
// Find the key, and return that
|
// Find the key, and return that
|
||||||
for(Enumeration<Long> keys = numberFormats.keys(); keys.hasMoreElements();) {
|
for(Enumeration<Integer> keys = numberFormats.keys(); keys.hasMoreElements();) {
|
||||||
Long key = keys.nextElement();
|
int key = keys.nextElement();
|
||||||
if(numberFormats.get(key).equals(fmt)) {
|
if(numberFormats.get(key).equals(fmt)) {
|
||||||
return key;
|
return key;
|
||||||
}
|
}
|
||||||
@ -166,7 +166,7 @@ public class StylesTable extends POIXMLDocumentPart implements StylesSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find a spare key, and add that
|
// Find a spare key, and add that
|
||||||
long newKey = FIRST_CUSTOM_STYLE_ID;
|
int newKey = FIRST_CUSTOM_STYLE_ID;
|
||||||
while(numberFormats.containsKey(newKey)) {
|
while(numberFormats.containsKey(newKey)) {
|
||||||
newKey++;
|
newKey++;
|
||||||
}
|
}
|
||||||
@ -174,11 +174,11 @@ public class StylesTable extends POIXMLDocumentPart implements StylesSource {
|
|||||||
return newKey;
|
return newKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
public XSSFFont getFontAt(long idx) {
|
public XSSFFont getFontAt(int idx) {
|
||||||
return fonts.get((int)idx);
|
return fonts.get((int)idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long putFont(Font font) {
|
public int putFont(Font font) {
|
||||||
int idx = fonts.indexOf(font);
|
int idx = fonts.indexOf(font);
|
||||||
if (idx != -1) {
|
if (idx != -1) {
|
||||||
return idx;
|
return idx;
|
||||||
@ -187,7 +187,7 @@ public class StylesTable extends POIXMLDocumentPart implements StylesSource {
|
|||||||
return fonts.size() - 1;
|
return fonts.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public XSSFCellStyle getStyleAt(long idx) {
|
public XSSFCellStyle getStyleAt(int idx) {
|
||||||
int styleXfId = 0;
|
int styleXfId = 0;
|
||||||
|
|
||||||
// 0 is the empty default
|
// 0 is the empty default
|
||||||
@ -197,7 +197,7 @@ public class StylesTable extends POIXMLDocumentPart implements StylesSource {
|
|||||||
|
|
||||||
return new XSSFCellStyle((int) idx, styleXfId, this);
|
return new XSSFCellStyle((int) idx, styleXfId, this);
|
||||||
}
|
}
|
||||||
public synchronized long putStyle(CellStyle style) {
|
public synchronized int putStyle(CellStyle style) {
|
||||||
XSSFCellStyle xStyle = (XSSFCellStyle)style;
|
XSSFCellStyle xStyle = (XSSFCellStyle)style;
|
||||||
CTXf mainXF = xStyle.getCoreXf();
|
CTXf mainXF = xStyle.getCoreXf();
|
||||||
|
|
||||||
@ -241,7 +241,7 @@ public class StylesTable extends POIXMLDocumentPart implements StylesSource {
|
|||||||
return fills.size() - 1;
|
return fills.size() - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CTXf getCellXfAt(long idx) {
|
public CTXf getCellXfAt(int idx) {
|
||||||
return xfs.get((int) idx);
|
return xfs.get((int) idx);
|
||||||
}
|
}
|
||||||
public int putCellXf(CTXf cellXf) {
|
public int putCellXf(CTXf cellXf) {
|
||||||
@ -249,7 +249,7 @@ public class StylesTable extends POIXMLDocumentPart implements StylesSource {
|
|||||||
return xfs.size();
|
return xfs.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CTXf getCellStyleXfAt(long idx) {
|
public CTXf getCellStyleXfAt(int idx) {
|
||||||
return styleXfs.get((int) idx);
|
return styleXfs.get((int) idx);
|
||||||
}
|
}
|
||||||
public int putCellStyleXf(CTXf cellStyleXf) {
|
public int putCellStyleXf(CTXf cellStyleXf) {
|
||||||
@ -328,7 +328,7 @@ public class StylesTable extends POIXMLDocumentPart implements StylesSource {
|
|||||||
// Formats
|
// Formats
|
||||||
CTNumFmts formats = CTNumFmts.Factory.newInstance();
|
CTNumFmts formats = CTNumFmts.Factory.newInstance();
|
||||||
formats.setCount(numberFormats.size());
|
formats.setCount(numberFormats.size());
|
||||||
for (Entry<Long, String> fmt : numberFormats.entrySet()) {
|
for (Entry<Integer, String> fmt : numberFormats.entrySet()) {
|
||||||
CTNumFmt ctFmt = formats.addNewNumFmt();
|
CTNumFmt ctFmt = formats.addNewNumFmt();
|
||||||
ctFmt.setNumFmtId(fmt.getKey());
|
ctFmt.setNumFmtId(fmt.getKey());
|
||||||
ctFmt.setFormatCode(fmt.getValue());
|
ctFmt.setFormatCode(fmt.getValue());
|
||||||
@ -460,14 +460,14 @@ public class StylesTable extends POIXMLDocumentPart implements StylesSource {
|
|||||||
return xssfFont;
|
return xssfFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CTDxf getDxf(long idx) {
|
public CTDxf getDxf(int idx) {
|
||||||
if(dxfs.size()==0)
|
if(dxfs.size()==0)
|
||||||
return CTDxf.Factory.newInstance();
|
return CTDxf.Factory.newInstance();
|
||||||
else
|
else
|
||||||
return dxfs.get((int) idx);
|
return dxfs.get((int) idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long putDxf(CTDxf dxf) {
|
public int putDxf(CTDxf dxf) {
|
||||||
this.dxfs.add(dxf);
|
this.dxfs.add(dxf);
|
||||||
return this.dxfs.size();
|
return this.dxfs.size();
|
||||||
}
|
}
|
||||||
|
@ -383,7 +383,7 @@ public final class XSSFCell implements Cell {
|
|||||||
*/
|
*/
|
||||||
public XSSFCellStyle getCellStyle() {
|
public XSSFCellStyle getCellStyle() {
|
||||||
long idx = cell.isSetS() ? cell.getS() : 0;
|
long idx = cell.isSetS() ? cell.getS() : 0;
|
||||||
return stylesSource.getStyleAt(idx);
|
return stylesSource.getStyleAt((int)idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,7 +77,7 @@ public class XSSFCellStyle implements CellStyle, Cloneable {
|
|||||||
/**
|
/**
|
||||||
* Creates an empty Cell Style
|
* Creates an empty Cell Style
|
||||||
*/
|
*/
|
||||||
public XSSFCellStyle(StylesSource stylesSource) {
|
public XSSFCellStyle(StylesTable stylesSource) {
|
||||||
this.stylesSource = (StylesTable)stylesSource;
|
this.stylesSource = (StylesTable)stylesSource;
|
||||||
// We need a new CTXf for the main styles
|
// We need a new CTXf for the main styles
|
||||||
// TODO decide on a style ctxf
|
// TODO decide on a style ctxf
|
||||||
@ -94,7 +94,7 @@ public class XSSFCellStyle implements CellStyle, Cloneable {
|
|||||||
* workbook (if they're not, it won't work)
|
* workbook (if they're not, it won't work)
|
||||||
* @throws IllegalArgumentException if there's a workbook mis-match
|
* @throws IllegalArgumentException if there's a workbook mis-match
|
||||||
*/
|
*/
|
||||||
public void verifyBelongsToStylesSource(StylesSource src) {
|
public void verifyBelongsToStylesSource(StylesTable src) {
|
||||||
if(this.stylesSource != src) {
|
if(this.stylesSource != src) {
|
||||||
throw new IllegalArgumentException("This Style does not belong to the supplied Workbook Stlyes Source. Are you trying to assign a style from one workbook to the cell of a differnt workbook?");
|
throw new IllegalArgumentException("This Style does not belong to the supplied Workbook Stlyes Source. Are you trying to assign a style from one workbook to the cell of a differnt workbook?");
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@ import org.apache.poi.ss.usermodel.Comment;
|
|||||||
import org.apache.poi.ss.usermodel.CommentsSource;
|
import org.apache.poi.ss.usermodel.CommentsSource;
|
||||||
import org.apache.poi.ss.usermodel.RichTextString;
|
import org.apache.poi.ss.usermodel.RichTextString;
|
||||||
import org.apache.poi.xssf.usermodel.helpers.RichTextStringHelper;
|
import org.apache.poi.xssf.usermodel.helpers.RichTextStringHelper;
|
||||||
|
import org.apache.poi.xssf.model.CommentsTable;
|
||||||
import org.apache.poi.ss.util.CellReference;
|
import org.apache.poi.ss.util.CellReference;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
|
||||||
@ -27,7 +28,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
|
|||||||
public class XSSFComment implements Comment {
|
public class XSSFComment implements Comment {
|
||||||
|
|
||||||
private CTComment comment;
|
private CTComment comment;
|
||||||
private CommentsSource comments;
|
private CommentsTable comments;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new XSSFComment, associated with a given
|
* Creates a new XSSFComment, associated with a given
|
||||||
@ -35,13 +36,13 @@ public class XSSFComment implements Comment {
|
|||||||
* If, as an end user, you want a new XSSFComment
|
* If, as an end user, you want a new XSSFComment
|
||||||
* object, the please ask your sheet for one.
|
* object, the please ask your sheet for one.
|
||||||
*/
|
*/
|
||||||
public XSSFComment(CommentsSource comments, CTComment comment) {
|
public XSSFComment(CommentsTable comments, CTComment comment) {
|
||||||
this.comment = comment;
|
this.comment = comment;
|
||||||
this.comments = comments;
|
this.comments = comments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthor() {
|
public String getAuthor() {
|
||||||
return comments.getAuthor(comment.getAuthorId());
|
return comments.getAuthor((int)comment.getAuthorId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColumn() {
|
public int getColumn() {
|
||||||
|
@ -18,14 +18,16 @@ package org.apache.poi.xssf.usermodel;
|
|||||||
|
|
||||||
import org.apache.poi.ss.usermodel.DataFormat;
|
import org.apache.poi.ss.usermodel.DataFormat;
|
||||||
import org.apache.poi.ss.usermodel.StylesSource;
|
import org.apache.poi.ss.usermodel.StylesSource;
|
||||||
|
import org.apache.poi.xssf.model.StylesTable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles data formats for XSSF.
|
* Handles data formats for XSSF.
|
||||||
* TODO Figure out if there are build in formats too
|
* TODO Figure out if there are build in formats too
|
||||||
*/
|
*/
|
||||||
public class XSSFDataFormat implements DataFormat {
|
public class XSSFDataFormat implements DataFormat {
|
||||||
private StylesSource stylesSource;
|
private StylesTable stylesSource;
|
||||||
public XSSFDataFormat(StylesSource stylesSource) {
|
|
||||||
|
protected XSSFDataFormat(StylesTable stylesSource) {
|
||||||
this.stylesSource = stylesSource;
|
this.stylesSource = stylesSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,6 +36,6 @@ public class XSSFDataFormat implements DataFormat {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getFormat(short index) {
|
public String getFormat(short index) {
|
||||||
return stylesSource.getNumberFormatAt((long)index);
|
return stylesSource.getNumberFormatAt(index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ package org.apache.poi.xssf.usermodel;
|
|||||||
|
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.POIXMLException;
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
||||||
import org.openxml4j.opc.PackagePart;
|
import org.openxml4j.opc.PackagePart;
|
||||||
@ -26,13 +27,14 @@ import org.openxml4j.opc.PackageRelationship;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
|
//YK: TODO: this is only a prototype
|
||||||
public class XSSFDialogsheet extends XSSFSheet implements Sheet{
|
public class XSSFDialogsheet extends XSSFSheet implements Sheet{
|
||||||
protected CTDialogsheet dialogsheet;
|
protected CTDialogsheet dialogsheet;
|
||||||
|
|
||||||
public XSSFDialogsheet(XSSFSheet sheet) {
|
protected XSSFDialogsheet(XSSFSheet sheet) {
|
||||||
this.packagePart = sheet.getPackagePart();
|
super(sheet.getPackagePart(), sheet.getPackageRelationship());
|
||||||
this.packageRel = sheet.getPackageRelationship();
|
|
||||||
this.dialogsheet = CTDialogsheet.Factory.newInstance();
|
this.dialogsheet = CTDialogsheet.Factory.newInstance();
|
||||||
|
this.worksheet = CTWorksheet.Factory.newInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public XSSFRow createRow(int rowNum) {
|
public XSSFRow createRow(int rowNum) {
|
||||||
|
@ -19,7 +19,6 @@ package org.apache.poi.xssf.usermodel;
|
|||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
import org.apache.xmlbeans.XmlObject;
|
|
||||||
import org.openxml4j.opc.*;
|
import org.openxml4j.opc.*;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*;
|
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*;
|
||||||
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
||||||
@ -29,8 +28,6 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a SpreadsheetML drawing
|
* Represents a SpreadsheetML drawing
|
||||||
@ -48,8 +45,8 @@ public class XSSFDrawing extends POIXMLDocumentPart {
|
|||||||
*
|
*
|
||||||
* @see org.apache.poi.xssf.usermodel.XSSFSheet#createDrawingPatriarch()
|
* @see org.apache.poi.xssf.usermodel.XSSFSheet#createDrawingPatriarch()
|
||||||
*/
|
*/
|
||||||
public XSSFDrawing() {
|
protected XSSFDrawing() {
|
||||||
super(null, null);
|
super();
|
||||||
drawing = newDrawing();
|
drawing = newDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +58,7 @@ public class XSSFDrawing extends POIXMLDocumentPart {
|
|||||||
* @param rel the package relationship holding this drawing,
|
* @param rel the package relationship holding this drawing,
|
||||||
* the relationship type must be http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing
|
* the relationship type must be http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing
|
||||||
*/
|
*/
|
||||||
public XSSFDrawing(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
|
protected XSSFDrawing(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
|
||||||
super(part, rel);
|
super(part, rel);
|
||||||
drawing = CTDrawing.Factory.parse(part.getInputStream());
|
drawing = CTDrawing.Factory.parse(part.getInputStream());
|
||||||
}
|
}
|
||||||
@ -157,7 +154,7 @@ public class XSSFDrawing extends POIXMLDocumentPart {
|
|||||||
XSSFWorkbook wb = (XSSFWorkbook)getParent().getParent();
|
XSSFWorkbook wb = (XSSFWorkbook)getParent().getParent();
|
||||||
XSSFPictureData data = wb.getAllPictures().get(pictureIndex);
|
XSSFPictureData data = wb.getAllPictures().get(pictureIndex);
|
||||||
PackagePartName ppName = data.getPackagePart().getPartName();
|
PackagePartName ppName = data.getPackagePart().getPartName();
|
||||||
PackageRelationship rel = packagePart.addRelationship(ppName, TargetMode.INTERNAL, XSSFRelation.IMAGES.getRelation());
|
PackageRelationship rel = getPackagePart().addRelationship(ppName, TargetMode.INTERNAL, XSSFRelation.IMAGES.getRelation());
|
||||||
addRelation(new XSSFPictureData(data.getPackagePart(), rel));
|
addRelation(new XSSFPictureData(data.getPackagePart(), rel));
|
||||||
return rel;
|
return rel;
|
||||||
}
|
}
|
||||||
|
@ -39,8 +39,10 @@ public class XSSFFactory extends POIXMLFactory {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static final XSSFFactory inst = new XSSFFactory();
|
||||||
|
|
||||||
public static XSSFFactory getInstance(){
|
public static XSSFFactory getInstance(){
|
||||||
return new XSSFFactory();
|
return inst;
|
||||||
}
|
}
|
||||||
|
|
||||||
public POIXMLDocumentPart createDocumentPart(PackageRelationship rel, PackagePart part){
|
public POIXMLDocumentPart createDocumentPart(PackageRelationship rel, PackagePart part){
|
||||||
@ -52,7 +54,7 @@ public class XSSFFactory extends POIXMLFactory {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Class cls = descriptor.getRelationClass();
|
Class cls = descriptor.getRelationClass();
|
||||||
Constructor<? extends POIXMLDocumentPart> constructor = cls.getConstructor(PackagePart.class, PackageRelationship.class);
|
Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(PackagePart.class, PackageRelationship.class);
|
||||||
return constructor.newInstance(part, rel);
|
return constructor.newInstance(part, rel);
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
throw new POIXMLException(e);
|
throw new POIXMLException(e);
|
||||||
@ -62,7 +64,7 @@ public class XSSFFactory extends POIXMLFactory {
|
|||||||
public POIXMLDocumentPart newDocumentPart(POIXMLRelation descriptor){
|
public POIXMLDocumentPart newDocumentPart(POIXMLRelation descriptor){
|
||||||
try {
|
try {
|
||||||
Class cls = descriptor.getRelationClass();
|
Class cls = descriptor.getRelationClass();
|
||||||
Constructor<? extends POIXMLDocumentPart> constructor = cls.getConstructor();
|
Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor();
|
||||||
return constructor.newInstance();
|
return constructor.newInstance();
|
||||||
} catch (Exception e){
|
} catch (Exception e){
|
||||||
throw new POIXMLException(e);
|
throw new POIXMLException(e);
|
||||||
|
@ -23,7 +23,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
|
|||||||
|
|
||||||
public class XSSFFirstFooter extends XSSFHeaderFooter implements Footer{
|
public class XSSFFirstFooter extends XSSFHeaderFooter implements Footer{
|
||||||
|
|
||||||
public XSSFFirstFooter(CTHeaderFooter headerFooter) {
|
protected XSSFFirstFooter(CTHeaderFooter headerFooter) {
|
||||||
super(headerFooter);
|
super(headerFooter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
|
|||||||
|
|
||||||
public class XSSFFirstHeader extends XSSFHeaderFooter implements Header{
|
public class XSSFFirstHeader extends XSSFHeaderFooter implements Header{
|
||||||
|
|
||||||
public XSSFFirstHeader(CTHeaderFooter headerFooter) {
|
protected XSSFFirstHeader(CTHeaderFooter headerFooter) {
|
||||||
super(headerFooter);
|
super(headerFooter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
|
|||||||
|
|
||||||
public class XSSFOddHeader extends XSSFHeaderFooter implements Header{
|
public class XSSFOddHeader extends XSSFHeaderFooter implements Header{
|
||||||
|
|
||||||
public XSSFOddHeader(CTHeaderFooter headerFooter) {
|
protected XSSFOddHeader(CTHeaderFooter headerFooter) {
|
||||||
super(headerFooter);
|
super(headerFooter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,8 +52,8 @@ public class XSSFPictureData extends POIXMLDocumentPart implements PictureData {
|
|||||||
*
|
*
|
||||||
* @see org.apache.poi.xssf.usermodel.XSSFWorkbook#addPicture(byte[], int)
|
* @see org.apache.poi.xssf.usermodel.XSSFWorkbook#addPicture(byte[], int)
|
||||||
*/
|
*/
|
||||||
public XSSFPictureData() {
|
protected XSSFPictureData() {
|
||||||
super(null, null);
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,7 +63,7 @@ public class XSSFPictureData extends POIXMLDocumentPart implements PictureData {
|
|||||||
* @param rel the package relationship holding this drawing,
|
* @param rel the package relationship holding this drawing,
|
||||||
* the relationship type must be http://schemas.openxmlformats.org/officeDocument/2006/relationships/image
|
* the relationship type must be http://schemas.openxmlformats.org/officeDocument/2006/relationships/image
|
||||||
*/
|
*/
|
||||||
public XSSFPictureData(PackagePart part, PackageRelationship rel) {
|
protected XSSFPictureData(PackagePart part, PackageRelationship rel) {
|
||||||
super(part, rel);
|
super(part, rel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ public class XSSFPrintSetup implements PrintSetup {
|
|||||||
private CTPageMargins pageMargins;
|
private CTPageMargins pageMargins;
|
||||||
|
|
||||||
|
|
||||||
public XSSFPrintSetup(CTWorksheet worksheet) {
|
protected XSSFPrintSetup(CTWorksheet worksheet) {
|
||||||
this.ctWorksheet = worksheet;
|
this.ctWorksheet = worksheet;
|
||||||
this.pageSetup = ctWorksheet.getPageSetup() == null ? ctWorksheet.addNewPageSetup() : ctWorksheet.getPageSetup();
|
this.pageSetup = ctWorksheet.getPageSetup() == null ? ctWorksheet.addNewPageSetup() : ctWorksheet.getPageSetup();
|
||||||
this.pageMargins = ctWorksheet.getPageMargins() == null ? ctWorksheet.addNewPageMargins() : ctWorksheet.getPageMargins();
|
this.pageMargins = ctWorksheet.getPageMargins() == null ? ctWorksheet.addNewPageMargins() : ctWorksheet.getPageMargins();
|
||||||
|
@ -16,11 +16,6 @@
|
|||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xssf.usermodel;
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
import org.apache.xmlbeans.XmlObject;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTAbsoluteAnchor;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTOneCellAnchor;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.chartDrawing.CTGroupShape;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -18,11 +18,7 @@ package org.apache.poi.xssf.usermodel;
|
|||||||
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*;
|
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
||||||
import org.openxml4j.opc.PackagePartName;
|
|
||||||
import org.openxml4j.opc.PackageRelationship;
|
import org.openxml4j.opc.PackageRelationship;
|
||||||
import org.openxml4j.opc.TargetMode;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This object specifies a group shape that represents many shapes grouped together. This shape is to be treated
|
* This object specifies a group shape that represents many shapes grouped together. This shape is to be treated
|
||||||
@ -43,7 +39,7 @@ public class XSSFShapeGroup extends XSSFShape {
|
|||||||
* @param drawing the XSSFDrawing that owns this shape
|
* @param drawing the XSSFDrawing that owns this shape
|
||||||
* @param ctGroup the XML bean that stores this group content
|
* @param ctGroup the XML bean that stores this group content
|
||||||
*/
|
*/
|
||||||
public XSSFShapeGroup(XSSFDrawing drawing, CTGroupShape ctGroup) {
|
protected XSSFShapeGroup(XSSFDrawing drawing, CTGroupShape ctGroup) {
|
||||||
this.drawing = drawing;
|
this.drawing = drawing;
|
||||||
this.ctGroup = ctGroup;
|
this.ctGroup = ctGroup;
|
||||||
}
|
}
|
||||||
|
@ -24,16 +24,13 @@ import javax.xml.namespace.QName;
|
|||||||
|
|
||||||
import org.apache.poi.hssf.util.PaneInformation;
|
import org.apache.poi.hssf.util.PaneInformation;
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
import org.apache.poi.ss.usermodel.CellStyle;
|
||||||
import org.apache.poi.ss.usermodel.CommentsSource;
|
|
||||||
import org.apache.poi.ss.usermodel.Footer;
|
import org.apache.poi.ss.usermodel.Footer;
|
||||||
import org.apache.poi.ss.usermodel.Header;
|
import org.apache.poi.ss.usermodel.Header;
|
||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.ss.util.CellReference;
|
import org.apache.poi.ss.util.CellReference;
|
||||||
import org.apache.poi.ss.util.Region;
|
|
||||||
import org.apache.poi.xssf.model.CommentsTable;
|
import org.apache.poi.xssf.model.CommentsTable;
|
||||||
import org.apache.poi.xssf.model.Control;
|
|
||||||
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
|
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
|
||||||
import org.apache.poi.POIXMLDocumentPart;
|
import org.apache.poi.POIXMLDocumentPart;
|
||||||
import org.apache.poi.POIXMLException;
|
import org.apache.poi.POIXMLException;
|
||||||
@ -44,6 +41,7 @@ import org.apache.xmlbeans.XmlException;
|
|||||||
import org.openxml4j.opc.PackagePart;
|
import org.openxml4j.opc.PackagePart;
|
||||||
import org.openxml4j.opc.PackageRelationship;
|
import org.openxml4j.opc.PackageRelationship;
|
||||||
import org.openxml4j.opc.PackageRelationshipCollection;
|
import org.openxml4j.opc.PackageRelationshipCollection;
|
||||||
|
import org.openxml4j.exceptions.InvalidFormatException;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
||||||
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
|
||||||
|
|
||||||
@ -71,20 +69,30 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
|
|
||||||
protected CTSheet sheet;
|
protected CTSheet sheet;
|
||||||
protected CTWorksheet worksheet;
|
protected CTWorksheet worksheet;
|
||||||
protected TreeMap<Integer, Row> rows;
|
private TreeMap<Integer, Row> rows;
|
||||||
protected List<XSSFHyperlink> hyperlinks;
|
private List<XSSFHyperlink> hyperlinks;
|
||||||
protected ColumnHelper columnHelper;
|
private ColumnHelper columnHelper;
|
||||||
private CommentsSource sheetComments;
|
private CommentsTable sheetComments;
|
||||||
|
|
||||||
public XSSFSheet() {
|
/**
|
||||||
super(null, null);
|
* Creates new XSSFSheet - called by XSSFWorkbook to create a sheet from scratch.
|
||||||
this.worksheet = newSheet();
|
*
|
||||||
initialize();
|
* @see org.apache.poi.xssf.usermodel.XSSFWorkbook#createSheet()
|
||||||
|
*/
|
||||||
|
protected XSSFSheet() {
|
||||||
|
super();
|
||||||
|
onDocumentCreate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public XSSFSheet(PackagePart part, PackageRelationship rel) throws IOException, XmlException {
|
/**
|
||||||
|
* Creates an XSSFSheet representing the given package part and relationship.
|
||||||
|
* Should only be called by XSSFWorkbook when reading in an exisiting file.
|
||||||
|
*
|
||||||
|
* @param part - The package part that holds xml data represenring this sheet.
|
||||||
|
* @param rel - the relationship of the given package part in the underlying OPC package
|
||||||
|
*/
|
||||||
|
protected XSSFSheet(PackagePart part, PackageRelationship rel) {
|
||||||
super(part, rel);
|
super(part, rel);
|
||||||
worksheet = WorksheetDocument.Factory.parse(part.getInputStream()).getWorksheet();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -96,25 +104,81 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
return (XSSFWorkbook)getParent();
|
return (XSSFWorkbook)getParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initialize(){
|
/**
|
||||||
if (this.worksheet.getSheetData() == null) {
|
* Initialize worksheet data when reading in an exisiting file.
|
||||||
this.worksheet.addNewSheetData();
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onDocumentRead() {
|
||||||
|
try {
|
||||||
|
worksheet = WorksheetDocument.Factory.parse(getPackagePart().getInputStream()).getWorksheet();
|
||||||
|
} catch (XmlException e){
|
||||||
|
throw new POIXMLException(e);
|
||||||
|
} catch (IOException e){
|
||||||
|
throw new POIXMLException(e);
|
||||||
}
|
}
|
||||||
initRows(this.worksheet);
|
|
||||||
initColumns(this.worksheet);
|
initRows(worksheet);
|
||||||
|
columnHelper = new ColumnHelper(worksheet);
|
||||||
|
|
||||||
for(POIXMLDocumentPart p : getRelations()){
|
for(POIXMLDocumentPart p : getRelations()){
|
||||||
if(p instanceof CommentsTable) sheetComments = (CommentsTable)p;
|
if(p instanceof CommentsTable) sheetComments = (CommentsTable)p;
|
||||||
}
|
}
|
||||||
hyperlinks = new ArrayList<XSSFHyperlink>();
|
// Process external hyperlinks for the sheet, if there are any
|
||||||
|
initHyperlinks();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new CTWorksheet instance and setup default values
|
* Initialize worksheet data when creating a new sheet.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void onDocumentCreate(){
|
||||||
|
worksheet = newSheet();
|
||||||
|
initRows(worksheet);
|
||||||
|
columnHelper = new ColumnHelper(worksheet);
|
||||||
|
hyperlinks = new ArrayList<XSSFHyperlink>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initRows(CTWorksheet worksheet) {
|
||||||
|
rows = new TreeMap<Integer, Row>();
|
||||||
|
for (CTRow row : worksheet.getSheetData().getRowArray()) {
|
||||||
|
XSSFRow r = new XSSFRow(row, this);
|
||||||
|
rows.put(r.getRowNum(), r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read hyperlink relations, link them with CTHyperlink beans in this worksheet
|
||||||
|
* and initialize the internal array of XSSFHyperlink objects
|
||||||
|
*/
|
||||||
|
private void initHyperlinks() {
|
||||||
|
hyperlinks = new ArrayList<XSSFHyperlink>();
|
||||||
|
|
||||||
|
if(!worksheet.isSetHyperlinks()) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
PackageRelationshipCollection hyperRels =
|
||||||
|
getPackagePart().getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation());
|
||||||
|
|
||||||
|
// Turn each one into a XSSFHyperlink
|
||||||
|
for(CTHyperlink hyperlink : worksheet.getHyperlinks().getHyperlinkArray()) {
|
||||||
|
PackageRelationship hyperRel = null;
|
||||||
|
if(hyperlink.getId() != null) {
|
||||||
|
hyperRel = hyperRels.getRelationshipByID(hyperlink.getId());
|
||||||
|
}
|
||||||
|
|
||||||
|
hyperlinks.add( new XSSFHyperlink(hyperlink, hyperRel) );
|
||||||
|
}
|
||||||
|
} catch (InvalidFormatException e){
|
||||||
|
throw new POIXMLException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new CTWorksheet instance with all values set to defaults
|
||||||
*
|
*
|
||||||
* @return a new instance
|
* @return a new instance
|
||||||
*/
|
*/
|
||||||
protected static CTWorksheet newSheet(){
|
private static CTWorksheet newSheet(){
|
||||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||||
CTSheetFormatPr ctFormat = worksheet.addNewSheetFormatPr();
|
CTSheetFormatPr ctFormat = worksheet.addNewSheetFormatPr();
|
||||||
ctFormat.setDefaultRowHeight(15.0);
|
ctFormat.setDefaultRowHeight(15.0);
|
||||||
@ -137,17 +201,12 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
return worksheet;
|
return worksheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Control> getControls()
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide access to the underlying XML bean
|
* Provide access to the CTWorksheet bean holding this sheet's data
|
||||||
*
|
*
|
||||||
* @return the underlying CTWorksheet bean
|
* @return the CTWorksheet bean holding this sheet's data
|
||||||
*/
|
*/
|
||||||
public CTWorksheet getWorksheet() {
|
public CTWorksheet getCTWorksheet() {
|
||||||
return this.worksheet;
|
return this.worksheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,48 +214,16 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
return columnHelper;
|
return columnHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void initRows(CTWorksheet worksheet) {
|
/**
|
||||||
this.rows = new TreeMap<Integer, Row>();
|
* Sdds a merged region of cells (hence those cells form one)
|
||||||
for (CTRow row : worksheet.getSheetData().getRowArray()) {
|
*
|
||||||
XSSFRow r = new XSSFRow(row, this);
|
* @param cra (rowfrom/colfrom-rowto/colto) to merge
|
||||||
this.rows.put(r.getRowNum(), r);
|
* @return index of this region
|
||||||
}
|
*/
|
||||||
}
|
|
||||||
|
|
||||||
protected void initColumns(CTWorksheet worksheet) {
|
|
||||||
columnHelper = new ColumnHelper(worksheet);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initHyperlinks(PackageRelationshipCollection hyperRels) {
|
|
||||||
if(worksheet.getHyperlinks() == null) return;
|
|
||||||
|
|
||||||
// Turn each one into a XSSFHyperlink
|
|
||||||
for(CTHyperlink hyperlink : worksheet.getHyperlinks().getHyperlinkArray()) {
|
|
||||||
PackageRelationship hyperRel = null;
|
|
||||||
if(hyperlink.getId() != null) {
|
|
||||||
hyperRel = hyperRels.getRelationshipByID(hyperlink.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
hyperlinks.add(
|
|
||||||
new XSSFHyperlink(hyperlink, hyperRel)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected CTSheet getSheet() {
|
|
||||||
return this.sheet;
|
|
||||||
}
|
|
||||||
public int addMergedRegion(CellRangeAddress cra) {
|
public int addMergedRegion(CellRangeAddress cra) {
|
||||||
Region r = new Region(cra.getFirstRow(), (short)cra.getFirstColumn(),
|
|
||||||
cra.getLastRow(), (short)cra.getLastColumn());
|
|
||||||
return addMergedRegion(r);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public int addMergedRegion(Region region) {
|
|
||||||
CTMergeCells ctMergeCells = worksheet.isSetMergeCells() ? worksheet.getMergeCells() : worksheet.addNewMergeCells();
|
CTMergeCells ctMergeCells = worksheet.isSetMergeCells() ? worksheet.getMergeCells() : worksheet.addNewMergeCells();
|
||||||
CTMergeCell ctMergeCell = ctMergeCells.addNewMergeCell();
|
CTMergeCell ctMergeCell = ctMergeCells.addNewMergeCell();
|
||||||
ctMergeCell.setRef(region.getRegionRef());
|
ctMergeCell.setRef(cra.formatAsString());
|
||||||
return ctMergeCells.sizeOfMergeCellArray();
|
return ctMergeCells.sizeOfMergeCellArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -215,11 +242,11 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Adjusts the column width to fit the contents.
|
* Adjusts the column width to fit the contents.
|
||||||
*
|
* <p>
|
||||||
* This process can be relatively slow on large sheets, so this should
|
* This process can be relatively slow on large sheets, so this should
|
||||||
* normally only be called once per column, at the end of your
|
* normally only be called once per column, at the end of your
|
||||||
* processing.
|
* processing.
|
||||||
*
|
* </p>
|
||||||
* You can specify whether the content of merged cells should be considered or ignored.
|
* You can specify whether the content of merged cells should be considered or ignored.
|
||||||
* Default is to ignore merged cells.
|
* Default is to ignore merged cells.
|
||||||
*
|
*
|
||||||
@ -305,7 +332,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
if (sheetComments == null) {
|
if (sheetComments == null) {
|
||||||
sheetComments = (CommentsTable)createRelationship(XSSFRelation.SHEET_COMMENTS, XSSFFactory.getInstance(), (int)sheet.getSheetId());
|
sheetComments = (CommentsTable)createRelationship(XSSFRelation.SHEET_COMMENTS, XSSFFactory.getInstance(), (int)sheet.getSheetId());
|
||||||
}
|
}
|
||||||
return (XSSFComment)sheetComments.addComment();
|
return sheetComments.addComment();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -341,19 +368,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
getPane().setActivePane(STPane.Enum.forInt(activePane));
|
getPane().setActivePane(STPane.Enum.forInt(activePane));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getAlternateExpression() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean getAlternateFormula() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public XSSFComment getCellComment(int row, int column) {
|
public XSSFComment getCellComment(int row, int column) {
|
||||||
if (sheetComments == null) return null;
|
if (sheetComments == null) return null;
|
||||||
else return (XSSFComment)sheetComments.findCellComment(row, column);
|
else return sheetComments.findCellComment(row, column);
|
||||||
}
|
}
|
||||||
|
|
||||||
public XSSFHyperlink getHyperlink(int row, int column) {
|
public XSSFHyperlink getHyperlink(int row, int column) {
|
||||||
@ -480,13 +497,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* @return the number of the first logical row on the sheet, zero based
|
* @return the number of the first logical row on the sheet, zero based
|
||||||
*/
|
*/
|
||||||
public int getFirstRowNum() {
|
public int getFirstRowNum() {
|
||||||
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
|
return rows.size() == 0 ? -1 : rows.firstKey();
|
||||||
Row row = it.next();
|
|
||||||
if (row != null) {
|
|
||||||
return row.getRowNum();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -602,14 +613,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getLastRowNum() {
|
public int getLastRowNum() {
|
||||||
int lastRowNum = -1;
|
return rows.size() == 0 ? -1 : rows.lastKey();
|
||||||
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
|
|
||||||
Row row = it.next();
|
|
||||||
if (row != null) {
|
|
||||||
lastRowNum = row.getRowNum();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return lastRowNum;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getLeftCol() {
|
public short getLeftCol() {
|
||||||
@ -618,8 +622,22 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
return cellReference.getCol();
|
return cellReference.getCol();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the size of the margin in inches.
|
||||||
|
*
|
||||||
|
* @param margin which margin to get
|
||||||
|
* @return the size of the margin
|
||||||
|
* @see Sheet#LeftMargin
|
||||||
|
* @see Sheet#RightMargin
|
||||||
|
* @see Sheet#TopMargin
|
||||||
|
* @see Sheet#BottomMargin
|
||||||
|
* @see Sheet#HeaderMargin
|
||||||
|
* @see Sheet#FooterMargin
|
||||||
|
*/
|
||||||
public double getMargin(short margin) {
|
public double getMargin(short margin) {
|
||||||
CTPageMargins pageMargins = getSheetTypePageMargins();
|
if (!worksheet.isSetPageMargins()) return 0;
|
||||||
|
|
||||||
|
CTPageMargins pageMargins = worksheet.getPageMargins();
|
||||||
switch (margin) {
|
switch (margin) {
|
||||||
case LeftMargin:
|
case LeftMargin:
|
||||||
return pageMargins.getLeft();
|
return pageMargins.getLeft();
|
||||||
@ -634,27 +652,44 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
case FooterMargin:
|
case FooterMargin:
|
||||||
return pageMargins.getFooter();
|
return pageMargins.getFooter();
|
||||||
default :
|
default :
|
||||||
throw new POIXMLException( "Unknown margin constant: " + margin );
|
throw new POIXMLException("Unknown margin constant: " + margin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CTPageMargins getSheetTypePageMargins() {
|
/**
|
||||||
if (worksheet.getPageMargins() == null) {
|
* Sets the size of the margin in inches.
|
||||||
worksheet.setPageMargins(CTPageMargins.Factory.newInstance());
|
*
|
||||||
|
* @param margin which margin to get
|
||||||
|
* @param size the size of the margin
|
||||||
|
* @see Sheet#LeftMargin
|
||||||
|
* @see Sheet#RightMargin
|
||||||
|
* @see Sheet#TopMargin
|
||||||
|
* @see Sheet#BottomMargin
|
||||||
|
* @see Sheet#HeaderMargin
|
||||||
|
* @see Sheet#FooterMargin
|
||||||
|
*/
|
||||||
|
public void setMargin(short margin, double size) {
|
||||||
|
CTPageMargins pageMargins = worksheet.isSetPageMargins() ?
|
||||||
|
worksheet.getPageMargins() : worksheet.addNewPageMargins();
|
||||||
|
switch (margin) {
|
||||||
|
case LeftMargin:
|
||||||
|
pageMargins.setLeft(size);
|
||||||
|
case RightMargin:
|
||||||
|
pageMargins.setRight(size);
|
||||||
|
case TopMargin:
|
||||||
|
pageMargins.setTop(size);
|
||||||
|
case BottomMargin:
|
||||||
|
pageMargins.setBottom(size);
|
||||||
|
case HeaderMargin:
|
||||||
|
pageMargins.setHeader(size);
|
||||||
|
case FooterMargin:
|
||||||
|
pageMargins.setFooter(size);
|
||||||
}
|
}
|
||||||
return worksheet.getPageMargins();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Region getMergedRegionAt(int index) {
|
|
||||||
CTMergeCells ctMergeCells = worksheet.getMergeCells();
|
|
||||||
if(ctMergeCells == null) throw new IllegalStateException("This worksheet does not contain merged regions");
|
|
||||||
|
|
||||||
CTMergeCell ctMergeCell = ctMergeCells.getMergeCellArray(index);
|
|
||||||
return new Region(ctMergeCell.getRef());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the merged region at the specified index
|
* @return the merged region at the specified index
|
||||||
|
* @throws IllegalStateException if this worksheet does not contain merged regions
|
||||||
*/
|
*/
|
||||||
public CellRangeAddress getMergedRegion(int index) {
|
public CellRangeAddress getMergedRegion(int index) {
|
||||||
CTMergeCells ctMergeCells = worksheet.getMergeCells();
|
CTMergeCells ctMergeCells = worksheet.getMergeCells();
|
||||||
@ -667,6 +702,11 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
return new CellRangeAddress(cell1.getRow(), cell2.getRow(), cell1.getCol(), cell2.getCol());
|
return new CellRangeAddress(cell1.getRow(), cell2.getRow(), cell1.getCol(), cell2.getCol());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the number of merged regions defined in this worksheet
|
||||||
|
*
|
||||||
|
* @return number of merged regions in this worksheet
|
||||||
|
*/
|
||||||
public int getNumMergedRegions() {
|
public int getNumMergedRegions() {
|
||||||
CTMergeCells ctMergeCells = worksheet.getMergeCells();
|
CTMergeCells ctMergeCells = worksheet.getMergeCells();
|
||||||
return ctMergeCells == null ? 0 : ctMergeCells.sizeOfMergeCellArray();
|
return ctMergeCells == null ? 0 : ctMergeCells.sizeOfMergeCellArray();
|
||||||
@ -676,38 +716,36 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
return hyperlinks.size();
|
return hyperlinks.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean getObjectProtect() {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public PaneInformation getPaneInformation() {
|
public PaneInformation getPaneInformation() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public short getPassword() {
|
/**
|
||||||
// TODO Auto-generated method stub
|
* Returns the number of phsyically defined rows (NOT the number of rows in the sheet)
|
||||||
return 0;
|
*
|
||||||
}
|
* @return the number of phsyically defined rows
|
||||||
|
*/
|
||||||
public int getPhysicalNumberOfRows() {
|
public int getPhysicalNumberOfRows() {
|
||||||
int counter = 0;
|
return rows.size();
|
||||||
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
|
|
||||||
if (it.next() != null) {
|
|
||||||
counter++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return counter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the print setup object.
|
||||||
|
*
|
||||||
|
* @return The user model for the print setup object.
|
||||||
|
*/
|
||||||
public XSSFPrintSetup getPrintSetup() {
|
public XSSFPrintSetup getPrintSetup() {
|
||||||
return new XSSFPrintSetup(getWorksheet());
|
return new XSSFPrintSetup(worksheet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Answer whether protection is enabled or disabled
|
||||||
|
*
|
||||||
|
* @return true => protection enabled; false => protection disabled
|
||||||
|
*/
|
||||||
public boolean getProtect() {
|
public boolean getProtect() {
|
||||||
// TODO Auto-generated method stub
|
return worksheet.isSetSheetProtection() && worksheet.getSheetProtection().getSheet();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -757,8 +795,8 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
public boolean getRowSumsBelow() {
|
public boolean getRowSumsBelow() {
|
||||||
CTSheetPr sheetPr = worksheet.getSheetPr();
|
CTSheetPr sheetPr = worksheet.getSheetPr();
|
||||||
CTOutlinePr outlinePr = (sheetPr != null && sheetPr.isSetOutlinePr())
|
CTOutlinePr outlinePr = (sheetPr != null && sheetPr.isSetOutlinePr())
|
||||||
? sheetPr.getOutlinePr() : CTOutlinePr.Factory.newInstance();
|
? sheetPr.getOutlinePr() : null;
|
||||||
return outlinePr.getSummaryBelow();
|
return outlinePr == null || outlinePr.getSummaryBelow();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -821,8 +859,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
*/
|
*/
|
||||||
private CTOutlinePr ensureOutlinePr(){
|
private CTOutlinePr ensureOutlinePr(){
|
||||||
CTSheetPr sheetPr = worksheet.isSetSheetPr() ? worksheet.getSheetPr() : worksheet.addNewSheetPr();
|
CTSheetPr sheetPr = worksheet.isSetSheetPr() ? worksheet.getSheetPr() : worksheet.addNewSheetPr();
|
||||||
CTOutlinePr outlinePr = sheetPr.isSetOutlinePr() ? sheetPr.getOutlinePr() : sheetPr.addNewOutlinePr();
|
return sheetPr.isSetOutlinePr() ? sheetPr.getOutlinePr() : sheetPr.addNewOutlinePr();
|
||||||
return outlinePr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -831,14 +868,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* @return true => protection enabled; false => protection disabled
|
* @return true => protection enabled; false => protection disabled
|
||||||
*/
|
*/
|
||||||
public boolean getScenarioProtect() {
|
public boolean getScenarioProtect() {
|
||||||
return getSheetTypeProtection().getScenarios();
|
return worksheet.isSetSheetProtection() && worksheet.getSheetProtection().getScenarios();
|
||||||
}
|
|
||||||
|
|
||||||
protected CTSheetProtection getSheetTypeProtection() {
|
|
||||||
if (worksheet.getSheetProtection() == null) {
|
|
||||||
worksheet.setSheetProtection(CTSheetProtection.Factory.newInstance());
|
|
||||||
}
|
|
||||||
return worksheet.getSheetProtection();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1015,11 +1045,6 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void protectSheet(String password) {
|
|
||||||
// TODO Auto-generated method stub
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a merged region of cells (hence letting them free)
|
* Removes a merged region of cells (hence letting them free)
|
||||||
*
|
*
|
||||||
@ -1040,8 +1065,12 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
ctMergeCells.setMergeCellArray(mergeCellsArray);
|
ctMergeCells.setMergeCellArray(mergeCellsArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove a row from this sheet. All cells contained in the row are removed as well
|
||||||
|
*
|
||||||
|
* @param row the row to remove.
|
||||||
|
*/
|
||||||
public void removeRow(Row row) {
|
public void removeRow(Row row) {
|
||||||
|
|
||||||
rows.remove(row.getRowNum());
|
rows.remove(row.getRowNum());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1227,24 +1256,6 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
getSheetTypePrintOptions().setHorizontalCentered(value);
|
getSheetTypePrintOptions().setHorizontalCentered(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMargin(short margin, double size) {
|
|
||||||
CTPageMargins pageMargins = getSheetTypePageMargins();
|
|
||||||
switch (margin) {
|
|
||||||
case LeftMargin:
|
|
||||||
pageMargins.setLeft(size);
|
|
||||||
case RightMargin:
|
|
||||||
pageMargins.setRight(size);
|
|
||||||
case TopMargin:
|
|
||||||
pageMargins.setTop(size);
|
|
||||||
case BottomMargin:
|
|
||||||
pageMargins.setBottom(size);
|
|
||||||
case HeaderMargin:
|
|
||||||
pageMargins.setHeader(size);
|
|
||||||
case FooterMargin:
|
|
||||||
pageMargins.setFooter(size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPrintGridlines(boolean newPrintGridlines) {
|
public void setPrintGridlines(boolean newPrintGridlines) {
|
||||||
getSheetTypePrintOptions().setGridLines(newPrintGridlines);
|
getSheetTypePrintOptions().setGridLines(newPrintGridlines);
|
||||||
}
|
}
|
||||||
@ -1474,7 +1485,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
getSheetTypeSheetFormatPr().setOutlineLevelCol(maxLevelCol);
|
getSheetTypeSheetFormatPr().setOutlineLevelCol(maxLevelCol);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected CTSheetViews getSheetTypeSheetViews() {
|
private CTSheetViews getSheetTypeSheetViews() {
|
||||||
if (worksheet.getSheetViews() == null) {
|
if (worksheet.getSheetViews() == null) {
|
||||||
worksheet.setSheetViews(CTSheetViews.Factory.newInstance());
|
worksheet.setSheetViews(CTSheetViews.Factory.newInstance());
|
||||||
worksheet.getSheetViews().addNewSheetView();
|
worksheet.getSheetViews().addNewSheetView();
|
||||||
@ -1560,6 +1571,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
if(sheetComments == null) { return false; }
|
if(sheetComments == null) { return false; }
|
||||||
return (sheetComments.getNumberOfComments() > 0);
|
return (sheetComments.getNumberOfComments() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getNumberOfComments() {
|
protected int getNumberOfComments() {
|
||||||
if(sheetComments == null) { return 0; }
|
if(sheetComments == null) { return 0; }
|
||||||
return sheetComments.getNumberOfComments();
|
return sheetComments.getNumberOfComments();
|
||||||
@ -1593,7 +1605,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
|
|||||||
* Returns the sheet's comments object if there is one,
|
* Returns the sheet's comments object if there is one,
|
||||||
* or null if not
|
* or null if not
|
||||||
*/
|
*/
|
||||||
protected CommentsSource getCommentsSourceIfExists() {
|
protected CommentsTable getCommentsSourceIfExists() {
|
||||||
return sheetComments;
|
return sheetComments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
package org.apache.poi.xssf.usermodel;
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*;
|
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a text box in a SpreadsheetML drawing.
|
* Represents a text box in a SpreadsheetML drawing.
|
||||||
|
@ -37,8 +37,8 @@ import org.apache.poi.xssf.model.*;
|
|||||||
import org.apache.poi.POIXMLException;
|
import org.apache.poi.POIXMLException;
|
||||||
import org.apache.xmlbeans.XmlObject;
|
import org.apache.xmlbeans.XmlObject;
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.openxml4j.exceptions.OpenXML4JException;
|
import org.openxml4j.exceptions.OpenXML4JException;
|
||||||
import org.openxml4j.exceptions.InvalidFormatException;
|
|
||||||
import org.openxml4j.opc.*;
|
import org.openxml4j.opc.*;
|
||||||
import org.openxml4j.opc.Package;
|
import org.openxml4j.opc.Package;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
||||||
@ -104,26 +104,12 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
|
|
||||||
private static POILogger log = POILogFactory.getLogger(XSSFWorkbook.class);
|
private static POILogger log = POILogFactory.getLogger(XSSFWorkbook.class);
|
||||||
|
|
||||||
/**
|
|
||||||
* The embedded OLE2 files in the OPC package
|
|
||||||
*/
|
|
||||||
private List<PackagePart> embedds;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new SpreadsheetML workbook.
|
* Create a new SpreadsheetML workbook.
|
||||||
*/
|
*/
|
||||||
public XSSFWorkbook() {
|
public XSSFWorkbook() {
|
||||||
super();
|
super(newPackage());
|
||||||
onDocumentCreate();
|
onWorkbookCreate();
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs a XSSFWorkbook object given a file name.
|
|
||||||
*
|
|
||||||
* @param path the file name.
|
|
||||||
*/
|
|
||||||
public XSSFWorkbook(String path) throws IOException {
|
|
||||||
this(openPackage(path));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,9 +120,25 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
*/
|
*/
|
||||||
public XSSFWorkbook(Package pkg) throws IOException {
|
public XSSFWorkbook(Package pkg) throws IOException {
|
||||||
super(ensureWriteAccess(pkg));
|
super(ensureWriteAccess(pkg));
|
||||||
|
|
||||||
|
//build a tree of POIXMLDocumentParts, this workbook being the root
|
||||||
|
try {
|
||||||
|
read(XSSFFactory.getInstance());
|
||||||
|
} catch (OpenXML4JException e){
|
||||||
|
throw new POIXMLException(e);
|
||||||
|
}
|
||||||
onDocumentRead();
|
onDocumentRead();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs a XSSFWorkbook object given a file name.
|
||||||
|
*
|
||||||
|
* @param path the file name.
|
||||||
|
*/
|
||||||
|
public XSSFWorkbook(String path) throws IOException {
|
||||||
|
this(openPackage(path));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* YK: current implementation of OpenXML4J is funny.
|
* YK: current implementation of OpenXML4J is funny.
|
||||||
* Packages opened by Package.open(InputStream is) are read-only,
|
* Packages opened by Package.open(InputStream is) are read-only,
|
||||||
@ -154,19 +156,13 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
return pkg;
|
return pkg;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize this workbook from the specified Package
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDocumentRead() {
|
protected void onDocumentRead() throws IOException {
|
||||||
try {
|
try {
|
||||||
//build the POIXMLDocumentPart tree, this workbook is the root
|
|
||||||
read(XSSFFactory.getInstance());
|
|
||||||
|
|
||||||
WorkbookDocument doc = WorkbookDocument.Factory.parse(getPackagePart().getInputStream());
|
WorkbookDocument doc = WorkbookDocument.Factory.parse(getPackagePart().getInputStream());
|
||||||
this.workbook = doc.getWorkbook();
|
this.workbook = doc.getWorkbook();
|
||||||
|
|
||||||
HashMap<String, XSSFSheet> shIdMap = new HashMap<String, XSSFSheet>();
|
Map<String, XSSFSheet> shIdMap = new HashMap<String, XSSFSheet>();
|
||||||
for(POIXMLDocumentPart p : getRelations()){
|
for(POIXMLDocumentPart p : getRelations()){
|
||||||
if(p instanceof SharedStringsTable) sharedStringSource = (SharedStringsTable)p;
|
if(p instanceof SharedStringsTable) sharedStringSource = (SharedStringsTable)p;
|
||||||
else if(p instanceof StylesTable) stylesSource = (StylesTable)p;
|
else if(p instanceof StylesTable) stylesSource = (StylesTable)p;
|
||||||
@ -175,34 +171,16 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load individual sheets
|
// Load individual sheets. The order of sheets is defined by the order of CTSheet beans in the workbook
|
||||||
sheets = new LinkedList<XSSFSheet>();
|
sheets = new ArrayList<XSSFSheet>(shIdMap.size());
|
||||||
embedds = new LinkedList<PackagePart>();
|
|
||||||
for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) {
|
for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) {
|
||||||
String id = ctSheet.getId();
|
XSSFSheet sh = shIdMap.get(ctSheet.getId());
|
||||||
XSSFSheet sh = shIdMap.get(id);
|
|
||||||
sh.sheet = ctSheet;
|
|
||||||
if(sh == null) {
|
if(sh == null) {
|
||||||
log.log(POILogger.WARN, "Sheet with name " + ctSheet.getName() + " and r:id " + ctSheet.getId()+ " was defined, but didn't exist in package, skipping");
|
log.log(POILogger.WARN, "Sheet with name " + ctSheet.getName() + " and r:id " + ctSheet.getId()+ " was defined, but didn't exist in package, skipping");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//initialize internal arrays of rows and columns
|
sh.sheet = ctSheet;
|
||||||
sh.initialize();
|
sh.onDocumentRead();
|
||||||
|
|
||||||
PackagePart sheetPart = sh.getPackagePart();
|
|
||||||
// Process external hyperlinks for the sheet,
|
|
||||||
// if there are any
|
|
||||||
PackageRelationshipCollection hyperlinkRels =
|
|
||||||
sheetPart.getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation());
|
|
||||||
sh.initHyperlinks(hyperlinkRels);
|
|
||||||
|
|
||||||
// Get the embeddings for the workbook
|
|
||||||
for(PackageRelationship rel : sheetPart.getRelationshipsByType(XSSFRelation.OLEEMBEDDINGS.getRelation()))
|
|
||||||
embedds.add(getTargetPart(rel)); // TODO: Add this reference to each sheet as well
|
|
||||||
|
|
||||||
for(PackageRelationship rel : sheetPart.getRelationshipsByType(XSSFRelation.PACKEMBEDDINGS.getRelation()))
|
|
||||||
embedds.add(getTargetPart(rel));
|
|
||||||
|
|
||||||
sheets.add(sh);
|
sheets.add(sh);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,20 +190,22 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process the named ranges
|
// Process the named ranges
|
||||||
namedRanges = new LinkedList<XSSFName>();
|
namedRanges = new ArrayList<XSSFName>();
|
||||||
if(workbook.getDefinedNames() != null) {
|
if(workbook.getDefinedNames() != null) {
|
||||||
for(CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameArray()) {
|
for(CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameArray()) {
|
||||||
namedRanges.add(new XSSFName(ctName, this));
|
namedRanges.add(new XSSFName(ctName, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (XmlException e) {
|
||||||
throw new POIXMLException(e);
|
throw new POIXMLException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
protected void onDocumentCreate() {
|
* Create a new CTWorkbook with all values set to default
|
||||||
|
*/
|
||||||
|
private void onWorkbookCreate() {
|
||||||
workbook = CTWorkbook.Factory.newInstance();
|
workbook = CTWorkbook.Factory.newInstance();
|
||||||
CTBookViews bvs = workbook.addNewBookViews();
|
CTBookViews bvs = workbook.addNewBookViews();
|
||||||
CTBookView bv = bvs.addNewWorkbookView();
|
CTBookView bv = bvs.addNewWorkbookView();
|
||||||
@ -235,15 +215,14 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
sharedStringSource = (SharedStringsTable)createRelationship(XSSFRelation.SHARED_STRINGS, XSSFFactory.getInstance());
|
sharedStringSource = (SharedStringsTable)createRelationship(XSSFRelation.SHARED_STRINGS, XSSFFactory.getInstance());
|
||||||
stylesSource = (StylesTable)createRelationship(XSSFRelation.STYLES, XSSFFactory.getInstance());
|
stylesSource = (StylesTable)createRelationship(XSSFRelation.STYLES, XSSFFactory.getInstance());
|
||||||
|
|
||||||
namedRanges = new LinkedList<XSSFName>();
|
namedRanges = new ArrayList<XSSFName>();
|
||||||
sheets = new LinkedList<XSSFSheet>();
|
sheets = new ArrayList<XSSFSheet>();
|
||||||
embedds = new LinkedList<PackagePart>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new SpreadsheetML package and setup the default minimal content
|
* Create a new SpreadsheetML package and setup the default minimal content
|
||||||
*/
|
*/
|
||||||
protected Package newPackage() throws IOException {
|
protected static Package newPackage() {
|
||||||
try {
|
try {
|
||||||
Package pkg = Package.create(PackageHelper.createTempFile());
|
Package pkg = Package.create(PackageHelper.createTempFile());
|
||||||
// Main part
|
// Main part
|
||||||
@ -256,7 +235,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
pkg.getPackageProperties().setCreatorProperty("Apache POI");
|
pkg.getPackageProperties().setCreatorProperty("Apache POI");
|
||||||
|
|
||||||
return pkg;
|
return pkg;
|
||||||
} catch (InvalidFormatException e){
|
} catch (Exception e){
|
||||||
throw new POIXMLException(e);
|
throw new POIXMLException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -266,7 +245,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
*
|
*
|
||||||
* @return the underlying CTWorkbook bean
|
* @return the underlying CTWorkbook bean
|
||||||
*/
|
*/
|
||||||
public CTWorkbook getWorkbook() {
|
public CTWorkbook getCTWorkbook() {
|
||||||
return this.workbook;
|
return this.workbook;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -345,7 +324,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
}
|
}
|
||||||
|
|
||||||
XSSFSheet clonedSheet = createSheet(name);
|
XSSFSheet clonedSheet = createSheet(name);
|
||||||
clonedSheet.worksheet.set(srcSheet.worksheet);
|
clonedSheet.getCTWorksheet().set(srcSheet.getCTWorksheet());
|
||||||
return clonedSheet;
|
return clonedSheet;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -380,7 +359,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create a new Font and add it to the workbook's font table
|
* Create a new Font and add it to the workbook's font table
|
||||||
*
|
*
|
||||||
* @return new font object
|
* @return new font object
|
||||||
*/
|
*/
|
||||||
@ -391,7 +370,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new named range and add it to the model
|
* Create a new named range and add it to the workbook's names table
|
||||||
*
|
*
|
||||||
* @return named range high level
|
* @return named range high level
|
||||||
*/
|
*/
|
||||||
@ -402,7 +381,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create an XSSFSheet for this workbook, adds it to the sheets and returns
|
* Create an XSSFSheet for this workbook, adds it to the sheets and returns
|
||||||
* the high level representation. Use this to create new sheets.
|
* the high level representation. Use this to create new sheets.
|
||||||
*
|
*
|
||||||
* @return XSSFSheet representing the new sheet.
|
* @return XSSFSheet representing the new sheet.
|
||||||
@ -413,25 +392,26 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* create an XSSFSheet for this workbook, adds it to the sheets and returns
|
* Create an XSSFSheet for this workbook, adds it to the sheets and returns
|
||||||
* the high level representation. Use this to create new sheets.
|
* the high level representation. Use this to create new sheets.
|
||||||
*
|
*
|
||||||
* @param sheetname sheetname to set for the sheet, can't be duplicate, greater than 31 chars or contain /\?*[]
|
* @param sheetname sheetname to set for the sheet, can't be duplicate, greater than 31 chars or contain /\?*[]
|
||||||
* @return XSSFSheet representing the new sheet.
|
* @return XSSFSheet representing the new sheet.
|
||||||
|
* @throws IllegalArgumentException if the sheetname is invalid or the workbook already contains a sheet of this name
|
||||||
*/
|
*/
|
||||||
public XSSFSheet createSheet(String sheetname) {
|
public XSSFSheet createSheet(String sheetname) {
|
||||||
if (containsSheet( sheetname, sheets.size() ))
|
if (containsSheet( sheetname, sheets.size() ))
|
||||||
throw new IllegalArgumentException( "The workbook already contains a sheet of this name" );
|
throw new IllegalArgumentException( "The workbook already contains a sheet of this name" );
|
||||||
|
|
||||||
|
CTSheet sheet = addSheet(sheetname);
|
||||||
|
|
||||||
int sheetNumber = getNumberOfSheets() + 1;
|
int sheetNumber = getNumberOfSheets() + 1;
|
||||||
XSSFSheet wrapper = (XSSFSheet)createRelationship(XSSFRelation.WORKSHEET, XSSFFactory.getInstance(), sheetNumber);
|
XSSFSheet wrapper = (XSSFSheet)createRelationship(XSSFRelation.WORKSHEET, XSSFFactory.getInstance(), sheetNumber);
|
||||||
|
|
||||||
CTSheet sheet = addSheet(sheetname);
|
|
||||||
wrapper.sheet = sheet;
|
wrapper.sheet = sheet;
|
||||||
sheet.setId(wrapper.getPackageRelationship().getId());
|
sheet.setId(wrapper.getPackageRelationship().getId());
|
||||||
sheet.setSheetId(sheetNumber);
|
sheet.setSheetId(sheetNumber);
|
||||||
if(sheets.size() == 0) wrapper.setSelected(true);
|
if(sheets.size() == 0) wrapper.setSelected(true);
|
||||||
this.sheets.add(wrapper);
|
sheets.add(wrapper);
|
||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -479,23 +459,14 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
public int getActiveSheetIndex() {
|
public int getActiveSheetIndex() {
|
||||||
//activeTab (Active Sheet Index) Specifies an unsignedInt
|
//activeTab (Active Sheet Index) Specifies an unsignedInt
|
||||||
//that contains the index to the active sheet in this book view.
|
//that contains the index to the active sheet in this book view.
|
||||||
Long index = workbook.getBookViews().getWorkbookViewArray(0).getActiveTab();
|
return (int)workbook.getBookViews().getWorkbookViewArray(0).getActiveTab();
|
||||||
return index.intValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets all embedded OLE2 objects from the Workbook.
|
|
||||||
*
|
|
||||||
* @return the list of embedded objects (a list of {@link org.openxml4j.opc.PackagePart} objects.)
|
|
||||||
*/
|
|
||||||
public List getAllEmbeddedObjects() {
|
|
||||||
return embedds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets all pictures from the Workbook.
|
* Gets all pictures from the Workbook.
|
||||||
*
|
*
|
||||||
* @return the list of pictures (a list of {@link XSSFPictureData} objects.)
|
* @return the list of pictures (a list of {@link XSSFPictureData} objects.)
|
||||||
|
* @see #addPicture(byte[], int)
|
||||||
*/
|
*/
|
||||||
public List<XSSFPictureData> getAllPictures() {
|
public List<XSSFPictureData> getAllPictures() {
|
||||||
if(pictures == null) {
|
if(pictures == null) {
|
||||||
@ -642,10 +613,10 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
* @return XSSFSheet with the name provided or <code>null</code> if it does not exist
|
* @return XSSFSheet with the name provided or <code>null</code> if it does not exist
|
||||||
*/
|
*/
|
||||||
public XSSFSheet getSheet(String name) {
|
public XSSFSheet getSheet(String name) {
|
||||||
CTSheet[] sheets = this.workbook.getSheets().getSheetArray();
|
CTSheet[] ctSheets = this.workbook.getSheets().getSheetArray();
|
||||||
for (int i = 0 ; i < sheets.length ; ++i) {
|
for (int i = 0 ; i < ctSheets.length ; ++i) {
|
||||||
if (name.equals(sheets[i].getName())) {
|
if (name.equalsIgnoreCase(ctSheets[i].getName())) {
|
||||||
return this.sheets.get(i);
|
return sheets.get(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@ -656,22 +627,24 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
*
|
*
|
||||||
* @param index of the sheet number (0-based physical & logical)
|
* @param index of the sheet number (0-based physical & logical)
|
||||||
* @return XSSFSheet at the provided index
|
* @return XSSFSheet at the provided index
|
||||||
|
* @throws IllegalArgumentException if the index is out of range (index
|
||||||
|
* < 0 || index >= getNumberOfSheets()).
|
||||||
*/
|
*/
|
||||||
public XSSFSheet getSheetAt(int index) {
|
public XSSFSheet getSheetAt(int index) {
|
||||||
validateSheetIndex(index);
|
validateSheetIndex(index);
|
||||||
return this.sheets.get(index);
|
return sheets.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the index of the sheet by his name
|
* Returns the index of the sheet by his name (case insensitive match)
|
||||||
*
|
*
|
||||||
* @param name the sheet name
|
* @param name the sheet name
|
||||||
* @return index of the sheet (0 based)
|
* @return index of the sheet (0 based) or <tt>-1</tt if not found
|
||||||
*/
|
*/
|
||||||
public int getSheetIndex(String name) {
|
public int getSheetIndex(String name) {
|
||||||
CTSheet[] sheets = this.workbook.getSheets().getSheetArray();
|
CTSheet[] sheets = this.workbook.getSheets().getSheetArray();
|
||||||
for (int i = 0 ; i < sheets.length ; ++i) {
|
for (int i = 0 ; i < sheets.length ; ++i) {
|
||||||
if (name.equals(sheets[i].getName())) {
|
if (name.equalsIgnoreCase(sheets[i].getName())) {
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1034,7 +1007,7 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
*/
|
*/
|
||||||
public void write(OutputStream stream) throws IOException {
|
public void write(OutputStream stream) throws IOException {
|
||||||
//force all children to commit their changes into the underlying OOXML Package
|
//force all children to commit their changes into the underlying OOXML Package
|
||||||
save();
|
onSave();
|
||||||
|
|
||||||
getPackage().save(stream);
|
getPackage().save(stream);
|
||||||
}
|
}
|
||||||
@ -1147,6 +1120,17 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
|
|||||||
* Get the document's embedded files.
|
* Get the document's embedded files.
|
||||||
*/
|
*/
|
||||||
public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
|
public List<PackagePart> getAllEmbedds() throws OpenXML4JException {
|
||||||
|
List<PackagePart> embedds = new LinkedList<PackagePart>();
|
||||||
|
|
||||||
|
for(XSSFSheet sheet : sheets){
|
||||||
|
// Get the embeddings for the workbook
|
||||||
|
for(PackageRelationship rel : sheet.getPackagePart().getRelationshipsByType(XSSFRelation.OLEEMBEDDINGS.getRelation()))
|
||||||
|
embedds.add(getTargetPart(rel));
|
||||||
|
|
||||||
|
for(PackageRelationship rel : sheet.getPackagePart().getRelationshipsByType(XSSFRelation.PACKEMBEDDINGS.getRelation()))
|
||||||
|
embedds.add(getTargetPart(rel));
|
||||||
|
|
||||||
|
}
|
||||||
return embedds;
|
return embedds;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,8 +118,8 @@ public class TestStylesTable extends TestCase {
|
|||||||
assertEquals(1, st._getStyleXfsSize());
|
assertEquals(1, st._getStyleXfsSize());
|
||||||
assertEquals(0, st._getNumberFormatSize());
|
assertEquals(0, st._getNumberFormatSize());
|
||||||
|
|
||||||
long nf1 = st.putNumberFormat("yyyy-mm-dd");
|
int nf1 = st.putNumberFormat("yyyy-mm-dd");
|
||||||
long nf2 = st.putNumberFormat("yyyy-mm-DD");
|
int nf2 = st.putNumberFormat("yyyy-mm-DD");
|
||||||
assertEquals(nf1, st.putNumberFormat("yyyy-mm-dd"));
|
assertEquals(nf1, st.putNumberFormat("yyyy-mm-dd"));
|
||||||
|
|
||||||
st.putStyle(new XSSFCellStyle(st));
|
st.putStyle(new XSSFCellStyle(st));
|
||||||
@ -146,8 +146,8 @@ public class TestStylesTable extends TestCase {
|
|||||||
assertEquals(1, st._getStyleXfsSize());
|
assertEquals(1, st._getStyleXfsSize());
|
||||||
assertEquals(8, st._getNumberFormatSize());
|
assertEquals(8, st._getNumberFormatSize());
|
||||||
|
|
||||||
long nf1 = st.putNumberFormat("YYYY-mm-dd");
|
int nf1 = st.putNumberFormat("YYYY-mm-dd");
|
||||||
long nf2 = st.putNumberFormat("YYYY-mm-DD");
|
int nf2 = st.putNumberFormat("YYYY-mm-DD");
|
||||||
assertEquals(nf1, st.putNumberFormat("YYYY-mm-dd"));
|
assertEquals(nf1, st.putNumberFormat("YYYY-mm-dd"));
|
||||||
|
|
||||||
st = XSSFTestDataSamples.writeOutAndReadBack(workbook).getStylesSource();
|
st = XSSFTestDataSamples.writeOutAndReadBack(workbook).getStylesSource();
|
||||||
|
@ -369,7 +369,7 @@ public final class TestXSSFCell extends TestCase {
|
|||||||
Cell cell = sheet.createRow(0).createCell((short)0);
|
Cell cell = sheet.createRow(0).createCell((short)0);
|
||||||
cell.setAsActiveCell();
|
cell.setAsActiveCell();
|
||||||
|
|
||||||
assertEquals("A1", sheet.getWorksheet().getSheetViews().getSheetViewArray(0).getSelectionArray(0).getActiveCell());
|
assertEquals("A1", sheet.getCTWorksheet().getSheetViews().getSheetViewArray(0).getSelectionArray(0).getActiveCell());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -22,7 +22,6 @@ import junit.framework.TestCase;
|
|||||||
import org.apache.poi.ss.usermodel.Row;
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
|
||||||
|
|
||||||
|
|
||||||
public class TestXSSFDialogSheet extends TestCase {
|
public class TestXSSFDialogSheet extends TestCase {
|
||||||
@ -51,7 +50,7 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
|
|
||||||
public void testGetSetAutoBreaks() {
|
public void testGetSetAutoBreaks() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertTrue(sheet.getAutobreaks());
|
assertTrue(sheet.getAutobreaks());
|
||||||
sheet.setAutobreaks(false);
|
sheet.setAutobreaks(false);
|
||||||
assertFalse(sheet.getAutobreaks());
|
assertFalse(sheet.getAutobreaks());
|
||||||
@ -59,7 +58,7 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
|
|
||||||
public void testIsSetFitToPage() {
|
public void testIsSetFitToPage() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertFalse(sheet.getFitToPage());
|
assertFalse(sheet.getFitToPage());
|
||||||
sheet.setFitToPage(true);
|
sheet.setFitToPage(true);
|
||||||
assertTrue(sheet.getFitToPage());
|
assertTrue(sheet.getFitToPage());
|
||||||
@ -69,7 +68,7 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
|
|
||||||
public void testGetSetMargin() {
|
public void testGetSetMargin() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertEquals((double) 0, sheet.getMargin((short) 0));
|
assertEquals((double) 0, sheet.getMargin((short) 0));
|
||||||
sheet.setMargin((short) 0, 10);
|
sheet.setMargin((short) 0, 10);
|
||||||
assertEquals((double) 10, sheet.getMargin((short) 0));
|
assertEquals((double) 10, sheet.getMargin((short) 0));
|
||||||
@ -111,7 +110,7 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
|
|
||||||
public void testGetFooter() {
|
public void testGetFooter() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertNotNull(sheet.getFooter());
|
assertNotNull(sheet.getFooter());
|
||||||
sheet.getFooter().setCenter("test center footer");
|
sheet.getFooter().setCenter("test center footer");
|
||||||
assertEquals("test center footer", sheet.getFooter().getCenter());
|
assertEquals("test center footer", sheet.getFooter().getCenter());
|
||||||
@ -119,7 +118,7 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
|
|
||||||
public void testGetAllHeadersFooters() {
|
public void testGetAllHeadersFooters() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertNotNull(sheet);
|
assertNotNull(sheet);
|
||||||
assertNotNull(sheet.getOddFooter());
|
assertNotNull(sheet.getOddFooter());
|
||||||
assertNotNull(sheet.getEvenFooter());
|
assertNotNull(sheet.getEvenFooter());
|
||||||
@ -156,7 +155,7 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
|
|
||||||
public void testGetSetHorizontallyCentered() {
|
public void testGetSetHorizontallyCentered() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertFalse(sheet.getHorizontallyCenter());
|
assertFalse(sheet.getHorizontallyCenter());
|
||||||
sheet.setHorizontallyCenter(true);
|
sheet.setHorizontallyCenter(true);
|
||||||
assertTrue(sheet.getHorizontallyCenter());
|
assertTrue(sheet.getHorizontallyCenter());
|
||||||
@ -166,7 +165,7 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
|
|
||||||
public void testGetSetVerticallyCentered() {
|
public void testGetSetVerticallyCentered() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertFalse(sheet.getVerticallyCenter());
|
assertFalse(sheet.getVerticallyCenter());
|
||||||
sheet.setVerticallyCenter(true);
|
sheet.setVerticallyCenter(true);
|
||||||
assertTrue(sheet.getVerticallyCenter());
|
assertTrue(sheet.getVerticallyCenter());
|
||||||
@ -176,7 +175,7 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
|
|
||||||
public void testIsSetPrintGridlines() {
|
public void testIsSetPrintGridlines() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertFalse(sheet.isPrintGridlines());
|
assertFalse(sheet.isPrintGridlines());
|
||||||
sheet.setPrintGridlines(true);
|
sheet.setPrintGridlines(true);
|
||||||
assertTrue(sheet.isPrintGridlines());
|
assertTrue(sheet.isPrintGridlines());
|
||||||
@ -184,7 +183,7 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
|
|
||||||
public void testIsSetDisplayFormulas() {
|
public void testIsSetDisplayFormulas() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertFalse(sheet.isDisplayFormulas());
|
assertFalse(sheet.isDisplayFormulas());
|
||||||
sheet.setDisplayFormulas(true);
|
sheet.setDisplayFormulas(true);
|
||||||
assertTrue(sheet.isDisplayFormulas());
|
assertTrue(sheet.isDisplayFormulas());
|
||||||
@ -192,7 +191,7 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
|
|
||||||
public void testIsSetDisplayGridLines() {
|
public void testIsSetDisplayGridLines() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertTrue(sheet.isDisplayGridlines());
|
assertTrue(sheet.isDisplayGridlines());
|
||||||
sheet.setDisplayGridlines(false);
|
sheet.setDisplayGridlines(false);
|
||||||
assertFalse(sheet.isDisplayGridlines());
|
assertFalse(sheet.isDisplayGridlines());
|
||||||
@ -200,7 +199,7 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
|
|
||||||
public void testIsSetDisplayRowColHeadings() {
|
public void testIsSetDisplayRowColHeadings() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertTrue(sheet.isDisplayRowColHeadings());
|
assertTrue(sheet.isDisplayRowColHeadings());
|
||||||
sheet.setDisplayRowColHeadings(false);
|
sheet.setDisplayRowColHeadings(false);
|
||||||
assertFalse(sheet.isDisplayRowColHeadings());
|
assertFalse(sheet.isDisplayRowColHeadings());
|
||||||
@ -208,7 +207,7 @@ public class TestXSSFDialogSheet extends TestCase {
|
|||||||
|
|
||||||
public void testGetScenarioProtect() {
|
public void testGetScenarioProtect() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
|
XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
|
||||||
assertFalse(sheet.getScenarioProtect());
|
assertFalse(sheet.getScenarioProtect());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,8 +42,8 @@ public class TestXSSFDrawing extends TestCase {
|
|||||||
String drawingId = drawing.getPackageRelationship().getId();
|
String drawingId = drawing.getPackageRelationship().getId();
|
||||||
|
|
||||||
//there should be a relation to this drawing in the worksheet
|
//there should be a relation to this drawing in the worksheet
|
||||||
assertTrue(sheet.getWorksheet().isSetDrawing());
|
assertTrue(sheet.getCTWorksheet().isSetDrawing());
|
||||||
assertEquals(drawingId, sheet.getWorksheet().getDrawing().getId());
|
assertEquals(drawingId, sheet.getCTWorksheet().getDrawing().getId());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,8 +63,8 @@ public class TestXSSFDrawing extends TestCase {
|
|||||||
String drawingId = drawing.getPackageRelationship().getId();
|
String drawingId = drawing.getPackageRelationship().getId();
|
||||||
|
|
||||||
//there should be a relation to this drawing in the worksheet
|
//there should be a relation to this drawing in the worksheet
|
||||||
assertTrue(sheet.getWorksheet().isSetDrawing());
|
assertTrue(sheet.getCTWorksheet().isSetDrawing());
|
||||||
assertEquals(drawingId, sheet.getWorksheet().getDrawing().getId());
|
assertEquals(drawingId, sheet.getCTWorksheet().getDrawing().getId());
|
||||||
|
|
||||||
}
|
}
|
||||||
public void testMultipleDrawings(){
|
public void testMultipleDrawings(){
|
||||||
|
@ -25,6 +25,7 @@ import org.apache.poi.ss.usermodel.Row;
|
|||||||
import org.apache.poi.ss.usermodel.Sheet;
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
import org.apache.poi.ss.usermodel.Workbook;
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
import org.apache.poi.ss.util.Region;
|
import org.apache.poi.ss.util.Region;
|
||||||
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.xssf.model.CommentsTable;
|
import org.apache.poi.xssf.model.CommentsTable;
|
||||||
import org.apache.poi.xssf.model.StylesTable;
|
import org.apache.poi.xssf.model.StylesTable;
|
||||||
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
|
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
|
||||||
@ -404,7 +405,7 @@ public class TestXSSFSheet extends TestCase {
|
|||||||
// Now check the low level stuff, and check that's all
|
// Now check the low level stuff, and check that's all
|
||||||
// been set correctly
|
// been set correctly
|
||||||
XSSFSheet xs = sheet;
|
XSSFSheet xs = sheet;
|
||||||
CTWorksheet cts = xs.getWorksheet();
|
CTWorksheet cts = xs.getCTWorksheet();
|
||||||
|
|
||||||
CTCols[] cols_s = cts.getColsArray();
|
CTCols[] cols_s = cts.getColsArray();
|
||||||
assertEquals(1, cols_s.length);
|
assertEquals(1, cols_s.length);
|
||||||
@ -621,7 +622,7 @@ public class TestXSSFSheet extends TestCase {
|
|||||||
sheet.setCellComment("A1", comment);
|
sheet.setCellComment("A1", comment);
|
||||||
assertEquals("A1", ctComments.getCommentList().getCommentArray(0).getRef());
|
assertEquals("A1", ctComments.getCommentList().getCommentArray(0).getRef());
|
||||||
comment.setAuthor("test A1 author");
|
comment.setAuthor("test A1 author");
|
||||||
assertEquals("test A1 author", comments.getAuthor(ctComments.getCommentList().getCommentArray(0).getAuthorId()));
|
assertEquals("test A1 author", comments.getAuthor((int)ctComments.getCommentList().getCommentArray(0).getAuthorId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetActiveCell() {
|
public void testGetActiveCell() {
|
||||||
@ -636,7 +637,7 @@ public class TestXSSFSheet extends TestCase {
|
|||||||
public void testCreateFreezePane() {
|
public void testCreateFreezePane() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFSheet sheet = workbook.createSheet();
|
XSSFSheet sheet = workbook.createSheet();
|
||||||
CTWorksheet ctWorksheet = sheet.getWorksheet();
|
CTWorksheet ctWorksheet = sheet.getCTWorksheet();
|
||||||
|
|
||||||
sheet.createFreezePane(2, 4);
|
sheet.createFreezePane(2, 4);
|
||||||
assertEquals((double)2, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getXSplit());
|
assertEquals((double)2, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getXSplit());
|
||||||
@ -653,17 +654,16 @@ public class TestXSSFSheet extends TestCase {
|
|||||||
public void testNewMergedRegionAt() {
|
public void testNewMergedRegionAt() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFSheet sheet = workbook.createSheet();
|
XSSFSheet sheet = workbook.createSheet();
|
||||||
Region region = new Region("B2:D4");
|
CellRangeAddress region = CellRangeAddress.valueOf("B2:D4");
|
||||||
sheet.addMergedRegion(region);
|
sheet.addMergedRegion(region);
|
||||||
assertEquals("B2:D4", sheet.getMergedRegionAt(0).getRegionRef());
|
assertEquals("B2:D4", sheet.getMergedRegion(0).formatAsString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetNumMergedRegions() {
|
public void testGetNumMergedRegions() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFSheet sheet = workbook.createSheet();
|
XSSFSheet sheet = workbook.createSheet();
|
||||||
CTWorksheet ctWorksheet = sheet.getWorksheet();
|
|
||||||
assertEquals(0, sheet.getNumMergedRegions());
|
assertEquals(0, sheet.getNumMergedRegions());
|
||||||
Region region = new Region("B2:D4");
|
CellRangeAddress region = CellRangeAddress.valueOf("B2:D4");
|
||||||
sheet.addMergedRegion(region);
|
sheet.addMergedRegion(region);
|
||||||
assertEquals(1, sheet.getNumMergedRegions());
|
assertEquals(1, sheet.getNumMergedRegions());
|
||||||
}
|
}
|
||||||
@ -671,10 +671,10 @@ public class TestXSSFSheet extends TestCase {
|
|||||||
public void testRemoveMergedRegion() {
|
public void testRemoveMergedRegion() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFSheet sheet = workbook.createSheet();
|
XSSFSheet sheet = workbook.createSheet();
|
||||||
CTWorksheet ctWorksheet = sheet.getWorksheet();
|
CTWorksheet ctWorksheet = sheet.getCTWorksheet();
|
||||||
Region region_1 = new Region("A1:B2");
|
CellRangeAddress region_1 = CellRangeAddress.valueOf("A1:B2");
|
||||||
Region region_2 = new Region("C3:D4");
|
CellRangeAddress region_2 = CellRangeAddress.valueOf("C3:D4");
|
||||||
Region region_3 = new Region("E5:F6");
|
CellRangeAddress region_3 = CellRangeAddress.valueOf("E5:F6");
|
||||||
sheet.addMergedRegion(region_1);
|
sheet.addMergedRegion(region_1);
|
||||||
sheet.addMergedRegion(region_2);
|
sheet.addMergedRegion(region_2);
|
||||||
sheet.addMergedRegion(region_3);
|
sheet.addMergedRegion(region_3);
|
||||||
@ -691,7 +691,7 @@ public class TestXSSFSheet extends TestCase {
|
|||||||
public void testSetDefaultColumnStyle() {
|
public void testSetDefaultColumnStyle() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFSheet sheet = workbook.createSheet();
|
XSSFSheet sheet = workbook.createSheet();
|
||||||
CTWorksheet ctWorksheet = sheet.getWorksheet();
|
CTWorksheet ctWorksheet = sheet.getCTWorksheet();
|
||||||
StylesTable stylesTable = workbook.getStylesSource();
|
StylesTable stylesTable = workbook.getStylesSource();
|
||||||
XSSFFont font = new XSSFFont();
|
XSSFFont font = new XSSFFont();
|
||||||
font.setFontName("Cambria");
|
font.setFontName("Cambria");
|
||||||
@ -750,7 +750,7 @@ public class TestXSSFSheet extends TestCase {
|
|||||||
//one level
|
//one level
|
||||||
sheet.groupColumn((short)2,(short)7);
|
sheet.groupColumn((short)2,(short)7);
|
||||||
sheet.groupColumn((short)10,(short)11);
|
sheet.groupColumn((short)10,(short)11);
|
||||||
CTCols cols=sheet.getWorksheet().getColsArray(0);
|
CTCols cols=sheet.getCTWorksheet().getColsArray(0);
|
||||||
assertEquals(2,cols.sizeOfColArray());
|
assertEquals(2,cols.sizeOfColArray());
|
||||||
CTCol[]colArray=cols.getColArray();
|
CTCol[]colArray=cols.getColArray();
|
||||||
assertNotNull(colArray);
|
assertNotNull(colArray);
|
||||||
@ -760,7 +760,7 @@ public class TestXSSFSheet extends TestCase {
|
|||||||
|
|
||||||
//two level
|
//two level
|
||||||
sheet.groupColumn((short)1,(short)2);
|
sheet.groupColumn((short)1,(short)2);
|
||||||
cols=sheet.getWorksheet().getColsArray(0);
|
cols=sheet.getCTWorksheet().getColsArray(0);
|
||||||
assertEquals(4,cols.sizeOfColArray());
|
assertEquals(4,cols.sizeOfColArray());
|
||||||
colArray=cols.getColArray();
|
colArray=cols.getColArray();
|
||||||
assertEquals(2, colArray[1].getOutlineLevel());
|
assertEquals(2, colArray[1].getOutlineLevel());
|
||||||
@ -768,7 +768,7 @@ public class TestXSSFSheet extends TestCase {
|
|||||||
//three level
|
//three level
|
||||||
sheet.groupColumn((short)6,(short)8);
|
sheet.groupColumn((short)6,(short)8);
|
||||||
sheet.groupColumn((short)2,(short)3);
|
sheet.groupColumn((short)2,(short)3);
|
||||||
cols=sheet.getWorksheet().getColsArray(0);
|
cols=sheet.getCTWorksheet().getColsArray(0);
|
||||||
assertEquals(7,cols.sizeOfColArray());
|
assertEquals(7,cols.sizeOfColArray());
|
||||||
colArray=cols.getColArray();
|
colArray=cols.getColArray();
|
||||||
assertEquals(3, colArray[1].getOutlineLevel());
|
assertEquals(3, colArray[1].getOutlineLevel());
|
||||||
@ -792,7 +792,7 @@ public class TestXSSFSheet extends TestCase {
|
|||||||
|
|
||||||
//one level
|
//one level
|
||||||
sheet.groupRow(9,10);
|
sheet.groupRow(9,10);
|
||||||
assertEquals(2,sheet.rows.size());
|
assertEquals(2,sheet.getPhysicalNumberOfRows());
|
||||||
CTRow ctrow = sheet.getRow(8).getCTRow();
|
CTRow ctrow = sheet.getRow(8).getCTRow();
|
||||||
|
|
||||||
assertNotNull(ctrow);
|
assertNotNull(ctrow);
|
||||||
@ -802,7 +802,7 @@ public class TestXSSFSheet extends TestCase {
|
|||||||
|
|
||||||
//two level
|
//two level
|
||||||
sheet.groupRow(10,13);
|
sheet.groupRow(10,13);
|
||||||
assertEquals(5,sheet.rows.size());
|
assertEquals(5,sheet.getPhysicalNumberOfRows());
|
||||||
ctrow = sheet.getRow(9).getCTRow();
|
ctrow = sheet.getRow(9).getCTRow();
|
||||||
assertNotNull(ctrow);
|
assertNotNull(ctrow);
|
||||||
assertEquals(10,ctrow.getR());
|
assertEquals(10,ctrow.getR());
|
||||||
@ -811,11 +811,11 @@ public class TestXSSFSheet extends TestCase {
|
|||||||
|
|
||||||
|
|
||||||
sheet.ungroupRow(8, 10);
|
sheet.ungroupRow(8, 10);
|
||||||
assertEquals(4,sheet.rows.size());
|
assertEquals(4,sheet.getPhysicalNumberOfRows());
|
||||||
assertEquals(1,sheet.getSheetTypeSheetFormatPr().getOutlineLevelRow());
|
assertEquals(1,sheet.getSheetTypeSheetFormatPr().getOutlineLevelRow());
|
||||||
|
|
||||||
sheet.ungroupRow(10,10);
|
sheet.ungroupRow(10,10);
|
||||||
assertEquals(3,sheet.rows.size());
|
assertEquals(3,sheet.getPhysicalNumberOfRows());
|
||||||
|
|
||||||
assertEquals(1,sheet.getSheetTypeSheetFormatPr().getOutlineLevelRow());
|
assertEquals(1,sheet.getSheetTypeSheetFormatPr().getOutlineLevelRow());
|
||||||
}
|
}
|
||||||
|
@ -54,6 +54,8 @@ public final class TestXSSFWorkbook extends TestCase {
|
|||||||
|
|
||||||
public void testGetSetActiveSheet(){
|
public void testGetSetActiveSheet(){
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
|
assertEquals(0, workbook.getActiveSheetIndex());
|
||||||
|
|
||||||
workbook.createSheet("sheet1");
|
workbook.createSheet("sheet1");
|
||||||
workbook.createSheet("sheet2");
|
workbook.createSheet("sheet2");
|
||||||
workbook.createSheet("sheet3");
|
workbook.createSheet("sheet3");
|
||||||
@ -84,7 +86,7 @@ public final class TestXSSFWorkbook extends TestCase {
|
|||||||
assertSame(sheet2, workbook.getSheetAt(0));
|
assertSame(sheet2, workbook.getSheetAt(0));
|
||||||
assertSame(sheet1, workbook.getSheetAt(1));
|
assertSame(sheet1, workbook.getSheetAt(1));
|
||||||
// Test reordering of CTSheets
|
// Test reordering of CTSheets
|
||||||
CTWorkbook ctwb = workbook.getWorkbook();
|
CTWorkbook ctwb = workbook.getCTWorkbook();
|
||||||
CTSheet[] ctsheets = ctwb.getSheets().getSheetArray();
|
CTSheet[] ctsheets = ctwb.getSheets().getSheetArray();
|
||||||
assertEquals("sheet2", ctsheets[0].getName());
|
assertEquals("sheet2", ctsheets[0].getName());
|
||||||
assertEquals("sheet1", ctsheets[1].getName());
|
assertEquals("sheet1", ctsheets[1].getName());
|
||||||
@ -334,19 +336,19 @@ public final class TestXSSFWorkbook extends TestCase {
|
|||||||
assertNotNull(cellStyleAt);
|
assertNotNull(cellStyleAt);
|
||||||
|
|
||||||
//get custom style
|
//get custom style
|
||||||
StylesSource styleSource = workbook.getStylesSource();
|
StylesTable styleSource = workbook.getStylesSource();
|
||||||
CellStyle customStyle = new XSSFCellStyle(styleSource);
|
CellStyle customStyle = new XSSFCellStyle(styleSource);
|
||||||
Font font = new XSSFFont();
|
Font font = new XSSFFont();
|
||||||
font.setFontName("Verdana");
|
font.setFontName("Verdana");
|
||||||
customStyle.setFont(font);
|
customStyle.setFont(font);
|
||||||
Long x = styleSource.putStyle(customStyle);
|
int x = styleSource.putStyle(customStyle);
|
||||||
cellStyleAt = workbook.getCellStyleAt(x.shortValue());
|
cellStyleAt = workbook.getCellStyleAt((short)x);
|
||||||
assertNotNull(cellStyleAt);
|
assertNotNull(cellStyleAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetFontAt(){
|
public void testGetFontAt(){
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
StylesSource styleSource = workbook.getStylesSource();
|
StylesTable styleSource = workbook.getStylesSource();
|
||||||
short i = 0;
|
short i = 0;
|
||||||
//get default font
|
//get default font
|
||||||
Font fontAt = workbook.getFontAt(i);
|
Font fontAt = workbook.getFontAt(i);
|
||||||
@ -355,8 +357,8 @@ public final class TestXSSFWorkbook extends TestCase {
|
|||||||
//get customized font
|
//get customized font
|
||||||
Font customFont = new XSSFFont();
|
Font customFont = new XSSFFont();
|
||||||
customFont.setItalic(true);
|
customFont.setItalic(true);
|
||||||
Long x = styleSource.putFont(customFont);
|
int x = styleSource.putFont(customFont);
|
||||||
fontAt = workbook.getFontAt(x.shortValue());
|
fontAt = workbook.getFontAt((short)x);
|
||||||
assertNotNull(fontAt);
|
assertNotNull(fontAt);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,7 +434,7 @@ public final class TestXSSFWorkbook extends TestCase {
|
|||||||
public void testStyles() {
|
public void testStyles() {
|
||||||
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
|
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
|
||||||
|
|
||||||
StylesSource ss = workbook.getStylesSource();
|
StylesTable ss = workbook.getStylesSource();
|
||||||
assertNotNull(ss);
|
assertNotNull(ss);
|
||||||
assertTrue(ss instanceof StylesTable);
|
assertTrue(ss instanceof StylesTable);
|
||||||
StylesTable st = (StylesTable)ss;
|
StylesTable st = (StylesTable)ss;
|
||||||
|
@ -25,7 +25,6 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
|
||||||
|
|
||||||
@ -64,7 +63,7 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
// Remember - POI column 0 == OOXML column 1
|
// Remember - POI column 0 == OOXML column 1
|
||||||
assertEquals((double) 88, helper.getColumn(0, false).getWidth());
|
assertEquals((double) 88, helper.getColumn(0, false).getWidth());
|
||||||
assertTrue(helper.getColumn(0, false).getHidden());
|
assertTrue(helper.getColumn(0, false).getHidden());
|
||||||
assertEquals((double) 00, helper.getColumn(1, false).getWidth());
|
assertEquals((double)0, helper.getColumn(1, false).getWidth());
|
||||||
assertFalse(helper.getColumn(1, false).getHidden());
|
assertFalse(helper.getColumn(1, false).getHidden());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +259,7 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
public void testGetSetColDefaultStyle() {
|
public void testGetSetColDefaultStyle() {
|
||||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||||
XSSFSheet sheet = workbook.createSheet();
|
XSSFSheet sheet = workbook.createSheet();
|
||||||
CTWorksheet ctWorksheet = sheet.getWorksheet();
|
CTWorksheet ctWorksheet = sheet.getCTWorksheet();
|
||||||
ColumnHelper columnHelper = sheet.getColumnHelper();
|
ColumnHelper columnHelper = sheet.getColumnHelper();
|
||||||
|
|
||||||
// POI column 3, OOXML column 4
|
// POI column 3, OOXML column 4
|
||||||
@ -271,7 +270,7 @@ public final class TestColumnHelper extends TestCase {
|
|||||||
columnHelper.setColDefaultStyle(3, 2);
|
columnHelper.setColDefaultStyle(3, 2);
|
||||||
assertEquals(2, columnHelper.getColDefaultStyle(3));
|
assertEquals(2, columnHelper.getColDefaultStyle(3));
|
||||||
assertEquals(-1, columnHelper.getColDefaultStyle(4));
|
assertEquals(-1, columnHelper.getColDefaultStyle(4));
|
||||||
StylesTable stylesTable = (StylesTable) workbook.getStylesSource();
|
StylesTable stylesTable = workbook.getStylesSource();
|
||||||
CTXf cellXf = CTXf.Factory.newInstance();
|
CTXf cellXf = CTXf.Factory.newInstance();
|
||||||
cellXf.setFontId(0);
|
cellXf.setFontId(0);
|
||||||
cellXf.setFillId(0);
|
cellXf.setFillId(0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user