import org.apache.poi.ss.usermodel.Sheet;\r
import org.apache.poi.ss.usermodel.Row;\r
import org.apache.poi.ss.usermodel.Cell;\r
+import org.apache.poi.ss.util.CellRangeAddress;\r
import org.apache.poi.xssf.usermodel.XSSFWorkbook;\r
import org.apache.poi.xssf.usermodel.XSSFRichTextString;\r
import org.apache.poi.hssf.util.Region;\r
Cell cell = row.createCell((short) 1);\r
cell.setCellValue(new XSSFRichTextString("This is a test of merging"));\r
\r
- sheet.addMergedRegion(new Region(1,(short)1,1,(short)2));\r
+ sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 2));\r
\r
// Write the output to a file\r
FileOutputStream fileOut = new FileOutputStream("merging_cells.xlsx");\r
public static int getEncodedSize(int numberOfItems) {
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());
+ }
}
import org.apache.poi.hssf.util.PaneInformation;
import org.apache.poi.ss.util.CellRangeAddress;
-import org.apache.poi.ss.util.Region;
public interface Sheet extends Iterable<Row> {
*/
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.
* @param value true to vertically center, false otherwise.
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
* be the third row if say for instance the second row is undefined.
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
* @return whether to show auto page breaks
*/
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
* @return true => protection enabled; false => protection disabled
*/
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
* fraction. For example to express a zoom of 75% use 3 for the numerator
*/
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
* classes of the various instances one needs for
package org.apache.poi;
import java.io.*;
-import java.util.LinkedList;
import java.util.List;
import org.apache.poi.poifs.common.POIFSConstants;
*/
private POIXMLProperties properties;
- protected POIXMLDocument() {
- super(null, null);
- try {
- Package pkg = newPackage();
- initialize(pkg);
- } catch (IOException e){
- throw new POIXMLException(e);
- }
- }
-
- protected POIXMLDocument(Package pkg) throws IOException {
- super(null, null);
- initialize(pkg);
+ protected POIXMLDocument(Package pkg) {
+ super(pkg);
+ this.pkg = pkg;
}
/**
}
}
- 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() {
return this.pkg;
}
protected PackagePart getCorePart() {
- return this.packagePart;
+ return getPackagePart();
}
/**
import org.apache.poi.util.POILogFactory;\r
import org.openxml4j.exceptions.OpenXML4JException;\r
import org.openxml4j.opc.*;\r
+import org.openxml4j.opc.Package;\r
\r
/**\r
* Represents an entry of a OOXML package.\r
public class POIXMLDocumentPart {\r
private static POILogger logger = POILogFactory.getLogger(POIXMLDocumentPart.class);\r
\r
- public static XmlOptions DEFAULT_XML_OPTIONS;\r
+ public static final XmlOptions DEFAULT_XML_OPTIONS;\r
static {\r
DEFAULT_XML_OPTIONS = new XmlOptions();\r
DEFAULT_XML_OPTIONS.setSaveOuter();\r
DEFAULT_XML_OPTIONS.setSaveAggressiveNamespaces();\r
}\r
\r
- protected PackagePart packagePart;\r
- protected PackageRelationship packageRel;\r
- protected POIXMLDocumentPart parent;\r
+ private PackagePart packagePart;\r
+ private PackageRelationship packageRel;\r
+ private POIXMLDocumentPart parent;\r
+ private List<POIXMLDocumentPart> relations;\r
\r
- protected List<POIXMLDocumentPart> relations;\r
+ /**\r
+ * Construct POIXMLDocumentPart representing a "core document" package part.\r
+ */\r
+ public POIXMLDocumentPart(Package pkg) {\r
+ try {\r
+ PackageRelationship coreRel = pkg.getRelationshipsByType(\r
+ PackageRelationshipTypes.CORE_DOCUMENT).getRelationship(0);\r
\r
+ this.relations = new LinkedList<POIXMLDocumentPart>();\r
+ this.packagePart = pkg.getPart(coreRel);\r
+ this.packageRel = coreRel;\r
+ } catch (OpenXML4JException e){\r
+ throw new POIXMLException(e);\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Creates new POIXMLDocumentPart - called by client code to create new parts from scratch.\r
+ *\r
+ * @see #createRelationship(POIXMLRelation, POIXMLFactory, int, boolean)\r
+ */\r
+ public POIXMLDocumentPart(){\r
+ this.relations = new LinkedList<POIXMLDocumentPart>();\r
+ }\r
+\r
+ /**\r
+ * Creates an POIXMLDocumentPart representing the given package part and relationship.\r
+ * Called by {@link #read(POIXMLFactory)} when reading in an exisiting file.\r
+ *\r
+ * @param part - The package part that holds xml data represenring this sheet.\r
+ * @param rel - the relationship of the given package part\r
+ * @see #read(POIXMLFactory)\r
+ */\r
public POIXMLDocumentPart(PackagePart part, PackageRelationship rel){\r
- relations = new LinkedList<POIXMLDocumentPart>();\r
+ this.relations = new LinkedList<POIXMLDocumentPart>();\r
this.packagePart = part;\r
this.packageRel = rel;\r
}\r
*\r
* @return the underlying PackagePart\r
*/\r
- public PackagePart getPackagePart(){\r
+ public final PackagePart getPackagePart(){\r
return packagePart;\r
}\r
\r
*\r
* @return the PackageRelationship that identifies this POIXMLDocumentPart\r
*/\r
- public PackageRelationship getPackageRelationship(){\r
+ public final PackageRelationship getPackageRelationship(){\r
return packageRel;\r
}\r
\r
*\r
* @return child relations\r
*/\r
- public List<POIXMLDocumentPart> getRelations(){\r
+ public final List<POIXMLDocumentPart> getRelations(){\r
return relations;\r
}\r
\r
*\r
* @param part the child to add\r
*/\r
- protected void addRelation(POIXMLDocumentPart part){\r
+ protected final void addRelation(POIXMLDocumentPart part){\r
relations.add(part);\r
}\r
\r
*\r
* @return the parent POIXMLDocumentPart or <code>null</code> for the root element.\r
*/\r
- public POIXMLDocumentPart getParent(){\r
+ public final POIXMLDocumentPart getParent(){\r
return parent;\r
}\r
\r
\r
/**\r
* Save changes in the underlying OOXML package.\r
+ * Recursively fires {@link #commit()} for each package part\r
*/\r
- protected void save() throws IOException{\r
+ protected final void onSave() throws IOException{\r
commit();\r
for(POIXMLDocumentPart p : relations){\r
- p.save();\r
+ p.onSave();\r
}\r
}\r
\r
* @param factory the factory that will create an instance of the requested relation\r
* @return the created child POIXMLDocumentPart\r
*/\r
- protected POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory){\r
+ protected final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory){\r
return createRelationship(descriptor, factory, -1, false);\r
}\r
\r
- protected POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx){\r
+ protected final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx){\r
return createRelationship(descriptor, factory, idx, false);\r
}\r
\r
* @param noRelation if true, then no relationship is added.\r
* @return the created child POIXMLDocumentPart\r
*/\r
- protected POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, boolean noRelation){\r
+ protected final POIXMLDocumentPart createRelationship(POIXMLRelation descriptor, POIXMLFactory factory, int idx, boolean noRelation){\r
try {\r
\r
PackagePartName ppName = PackagingURIHelper.createPartName(descriptor.getFileName(idx));\r
doc.packageRel = rel;\r
doc.packagePart = part;\r
doc.parent = this;\r
- doc.onDocumentCreate();\r
addRelation(doc);\r
return doc;\r
} catch (Exception e){\r
*\r
* @param factory the factory object that creates POIXMLFactory instances\r
*/\r
- protected void read(POIXMLFactory factory) throws OpenXML4JException {\r
+ protected final void read(POIXMLFactory factory) throws OpenXML4JException {\r
PackageRelationshipCollection rels = packagePart.getRelationships();\r
for (PackageRelationship rel : rels) {\r
if(rel.getTargetMode() == TargetMode.INTERNAL){\r
}\r
POIXMLDocumentPart childPart = factory.createDocumentPart(rel, p);\r
childPart.parent = this;\r
- childPart.onDocumentRead();\r
addRelation(childPart);\r
\r
if(p.hasRelationships()) childPart.read(factory);\r
}\r
}\r
\r
+\r
/**\r
* Fired when a new package part is created\r
*/\r
- protected void onDocumentCreate(){\r
+ protected void onDocumentCreate() throws IOException {\r
\r
}\r
\r
/**\r
* Fired when a package part is read\r
*/\r
- protected void onDocumentRead(){\r
+ protected void onDocumentRead() throws IOException{\r
\r
}\r
+\r
}\r
import org.openxml4j.opc.PackagePart;
import org.openxml4j.opc.PackageRelationship;
-public class CommentsTable extends POIXMLDocumentPart implements CommentsSource {
+public class CommentsTable extends POIXMLDocumentPart {
protected CTComments comments;
public CommentsTable() {
- super(null, null);
+ super();
comments = CTComments.Factory.newInstance();
}
}
}
public void writeTo(OutputStream out) throws IOException {
- XmlOptions options = new XmlOptions();
- options.setSaveOuter();
- options.setUseDefaultNamespace();
-
- // Requests use of whitespace for easier reading
- //options.setSavePrettyPrint();
-
- CommentsDocument doc = CommentsDocument.Factory.newInstance(options);
+ CommentsDocument doc = CommentsDocument.Factory.newInstance();
doc.setComments(comments);
- doc.save(out, options);
+ doc.save(out, DEFAULT_XML_OPTIONS);
}
@Override
private int uniqueCount;
public SharedStringsTable() {
- super(null, null);
+ super();
}
public SharedStringsTable(PackagePart part, PackageRelationship rel) throws IOException {
*
* @author ugo
*/
-public class StylesTable extends POIXMLDocumentPart implements StylesSource {
- private final Hashtable<Long,String> numberFormats = new Hashtable<Long,String>();
+public class StylesTable extends POIXMLDocumentPart {
+ private final Hashtable<Integer, String> numberFormats = new Hashtable<Integer,String>();
private final List<XSSFFont> fonts = new ArrayList<XSSFFont>();
private final List<XSSFCellFill> fills = new ArrayList<XSSFCellFill>();
private final List<XSSFCellBorder> borders = new ArrayList<XSSFCellBorder>();
/**
* 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;
* Create a new, empty StylesTable
*/
public StylesTable() {
- super(null, null);
+ super();
doc = StyleSheetDocument.Factory.newInstance();
doc.addNewStyleSheet();
// Initialization required in order to make the document readable by MSExcel
// Grab all the different bits we care about
if(doc.getStyleSheet().getNumFmts() != null)
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){
int idx = 0;
// Start of style related getters and setters
// ===========================================================
- public String getNumberFormatAt(long idx) {
+ public String getNumberFormatAt(int idx) {
return numberFormats.get(idx);
}
- public synchronized long putNumberFormat(String fmt) {
+ public synchronized int putNumberFormat(String fmt) {
if (numberFormats.containsValue(fmt)) {
// Find the key, and return that
- for(Enumeration<Long> keys = numberFormats.keys(); keys.hasMoreElements();) {
- Long key = keys.nextElement();
+ for(Enumeration<Integer> keys = numberFormats.keys(); keys.hasMoreElements();) {
+ int key = keys.nextElement();
if(numberFormats.get(key).equals(fmt)) {
return key;
}
}
// Find a spare key, and add that
- long newKey = FIRST_CUSTOM_STYLE_ID;
+ int newKey = FIRST_CUSTOM_STYLE_ID;
while(numberFormats.containsKey(newKey)) {
newKey++;
}
return newKey;
}
- public XSSFFont getFontAt(long idx) {
+ public XSSFFont getFontAt(int idx) {
return fonts.get((int)idx);
}
- public long putFont(Font font) {
+ public int putFont(Font font) {
int idx = fonts.indexOf(font);
if (idx != -1) {
return idx;
return fonts.size() - 1;
}
- public XSSFCellStyle getStyleAt(long idx) {
+ public XSSFCellStyle getStyleAt(int idx) {
int styleXfId = 0;
// 0 is the empty default
return new XSSFCellStyle((int) idx, styleXfId, this);
}
- public synchronized long putStyle(CellStyle style) {
+ public synchronized int putStyle(CellStyle style) {
XSSFCellStyle xStyle = (XSSFCellStyle)style;
CTXf mainXF = xStyle.getCoreXf();
return fills.size() - 1;
}
- public CTXf getCellXfAt(long idx) {
+ public CTXf getCellXfAt(int idx) {
return xfs.get((int) idx);
}
public int putCellXf(CTXf cellXf) {
return xfs.size();
}
- public CTXf getCellStyleXfAt(long idx) {
+ public CTXf getCellStyleXfAt(int idx) {
return styleXfs.get((int) idx);
}
public int putCellStyleXf(CTXf cellStyleXf) {
// Formats
CTNumFmts formats = CTNumFmts.Factory.newInstance();
formats.setCount(numberFormats.size());
- for (Entry<Long, String> fmt : numberFormats.entrySet()) {
+ for (Entry<Integer, String> fmt : numberFormats.entrySet()) {
CTNumFmt ctFmt = formats.addNewNumFmt();
ctFmt.setNumFmtId(fmt.getKey());
ctFmt.setFormatCode(fmt.getValue());
return xssfFont;
}
- public CTDxf getDxf(long idx) {
+ public CTDxf getDxf(int idx) {
if(dxfs.size()==0)
return CTDxf.Factory.newInstance();
else
return dxfs.get((int) idx);
}
- public long putDxf(CTDxf dxf) {
+ public int putDxf(CTDxf dxf) {
this.dxfs.add(dxf);
return this.dxfs.size();
}
*/
public XSSFCellStyle getCellStyle() {
long idx = cell.isSetS() ? cell.getS() : 0;
- return stylesSource.getStyleAt(idx);
+ return stylesSource.getStyleAt((int)idx);
}
/**
/**
* Creates an empty Cell Style
*/
- public XSSFCellStyle(StylesSource stylesSource) {
+ public XSSFCellStyle(StylesTable stylesSource) {
this.stylesSource = (StylesTable)stylesSource;
// We need a new CTXf for the main styles
// TODO decide on a style ctxf
* workbook (if they're not, it won't work)
* @throws IllegalArgumentException if there's a workbook mis-match
*/
- public void verifyBelongsToStylesSource(StylesSource src) {
+ public void verifyBelongsToStylesSource(StylesTable 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?");
}
import org.apache.poi.ss.usermodel.CommentsSource;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.xssf.usermodel.helpers.RichTextStringHelper;
+import org.apache.poi.xssf.model.CommentsTable;
import org.apache.poi.ss.util.CellReference;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
public class XSSFComment implements Comment {
private CTComment comment;
- private CommentsSource comments;
+ private CommentsTable comments;
/**
* Creates a new XSSFComment, associated with a given
* If, as an end user, you want a new XSSFComment
* object, the please ask your sheet for one.
*/
- public XSSFComment(CommentsSource comments, CTComment comment) {
+ public XSSFComment(CommentsTable comments, CTComment comment) {
this.comment = comment;
this.comments = comments;
}
public String getAuthor() {
- return comments.getAuthor(comment.getAuthorId());
+ return comments.getAuthor((int)comment.getAuthorId());
}
public int getColumn() {
import org.apache.poi.ss.usermodel.DataFormat;
import org.apache.poi.ss.usermodel.StylesSource;
+import org.apache.poi.xssf.model.StylesTable;
/**
* Handles data formats for XSSF.
* TODO Figure out if there are build in formats too
*/
public class XSSFDataFormat implements DataFormat {
- private StylesSource stylesSource;
- public XSSFDataFormat(StylesSource stylesSource) {
- this.stylesSource = stylesSource;
- }
-
- public short getFormat(String format) {
- return (short)stylesSource.putNumberFormat(format);
- }
+ private StylesTable stylesSource;
- public String getFormat(short index) {
- return stylesSource.getNumberFormatAt((long)index);
- }
+ protected XSSFDataFormat(StylesTable stylesSource) {
+ this.stylesSource = stylesSource;
+ }
+
+ public short getFormat(String format) {
+ return (short)stylesSource.putNumberFormat(format);
+ }
+
+ public String getFormat(short index) {
+ return stylesSource.getNumberFormatAt(index);
+ }
}
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.POIXMLException;
import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
import org.openxml4j.opc.PackagePart;
import java.io.IOException;
+//YK: TODO: this is only a prototype
public class XSSFDialogsheet extends XSSFSheet implements Sheet{
protected CTDialogsheet dialogsheet;
- public XSSFDialogsheet(XSSFSheet sheet) {
- this.packagePart = sheet.getPackagePart();
- this.packageRel = sheet.getPackageRelationship();
+ protected XSSFDialogsheet(XSSFSheet sheet) {
+ super(sheet.getPackagePart(), sheet.getPackageRelationship());
this.dialogsheet = CTDialogsheet.Factory.newInstance();
+ this.worksheet = CTWorksheet.Factory.newInstance();
}
public XSSFRow createRow(int rowNum) {
import org.apache.poi.POIXMLDocumentPart;\r
import org.apache.xmlbeans.XmlException;\r
import org.apache.xmlbeans.XmlOptions;\r
-import org.apache.xmlbeans.XmlObject;\r
import org.openxml4j.opc.*;\r
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*;\r
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;\r
import java.io.OutputStream;\r
import java.util.Map;\r
import java.util.HashMap;\r
-import java.util.List;\r
-import java.util.LinkedList;\r
\r
/**\r
* Represents a SpreadsheetML drawing\r
*\r
* @see org.apache.poi.xssf.usermodel.XSSFSheet#createDrawingPatriarch()\r
*/\r
- public XSSFDrawing() {\r
- super(null, null);\r
+ protected XSSFDrawing() {\r
+ super();\r
drawing = newDrawing();\r
}\r
\r
* @param rel the package relationship holding this drawing,\r
* the relationship type must be http://schemas.openxmlformats.org/officeDocument/2006/relationships/drawing\r
*/\r
- public XSSFDrawing(PackagePart part, PackageRelationship rel) throws IOException, XmlException {\r
+ protected XSSFDrawing(PackagePart part, PackageRelationship rel) throws IOException, XmlException {\r
super(part, rel);\r
drawing = CTDrawing.Factory.parse(part.getInputStream());\r
}\r
XSSFWorkbook wb = (XSSFWorkbook)getParent().getParent();\r
XSSFPictureData data = wb.getAllPictures().get(pictureIndex);\r
PackagePartName ppName = data.getPackagePart().getPartName();\r
- PackageRelationship rel = packagePart.addRelationship(ppName, TargetMode.INTERNAL, XSSFRelation.IMAGES.getRelation());\r
+ PackageRelationship rel = getPackagePart().addRelationship(ppName, TargetMode.INTERNAL, XSSFRelation.IMAGES.getRelation());\r
addRelation(new XSSFPictureData(data.getPackagePart(), rel));\r
return rel;\r
}\r
\r
}\r
\r
+ private static final XSSFFactory inst = new XSSFFactory();\r
+\r
public static XSSFFactory getInstance(){\r
- return new XSSFFactory();\r
+ return inst;\r
}\r
\r
public POIXMLDocumentPart createDocumentPart(PackageRelationship rel, PackagePart part){\r
\r
try {\r
Class cls = descriptor.getRelationClass();\r
- Constructor<? extends POIXMLDocumentPart> constructor = cls.getConstructor(PackagePart.class, PackageRelationship.class);\r
+ Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor(PackagePart.class, PackageRelationship.class);\r
return constructor.newInstance(part, rel);\r
} catch (Exception e){\r
throw new POIXMLException(e);\r
public POIXMLDocumentPart newDocumentPart(POIXMLRelation descriptor){\r
try {\r
Class cls = descriptor.getRelationClass();\r
- Constructor<? extends POIXMLDocumentPart> constructor = cls.getConstructor();\r
+ Constructor<? extends POIXMLDocumentPart> constructor = cls.getDeclaredConstructor();\r
return constructor.newInstance();\r
} catch (Exception e){\r
throw new POIXMLException(e);\r
public class XSSFFirstFooter extends XSSFHeaderFooter implements Footer{
- public XSSFFirstFooter(CTHeaderFooter headerFooter) {
+ protected XSSFFirstFooter(CTHeaderFooter headerFooter) {
super(headerFooter);
}
public class XSSFFirstHeader extends XSSFHeaderFooter implements Header{
- public XSSFFirstHeader(CTHeaderFooter headerFooter) {
+ protected XSSFFirstHeader(CTHeaderFooter headerFooter) {
super(headerFooter);
}
public class XSSFOddHeader extends XSSFHeaderFooter implements Header{
- public XSSFOddHeader(CTHeaderFooter headerFooter) {
+ protected XSSFOddHeader(CTHeaderFooter headerFooter) {
super(headerFooter);
}
*
* @see org.apache.poi.xssf.usermodel.XSSFWorkbook#addPicture(byte[], int)
*/
- public XSSFPictureData() {
- super(null, null);
+ protected XSSFPictureData() {
+ super();
}
/**
* @param rel the package relationship holding this drawing,
* 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);
}
private CTPageMargins pageMargins;
- public XSSFPrintSetup(CTWorksheet worksheet) {
+ protected XSSFPrintSetup(CTWorksheet worksheet) {
this.ctWorksheet = worksheet;
this.pageSetup = ctWorksheet.getPageSetup() == null ? ctWorksheet.addNewPageSetup() : ctWorksheet.getPageSetup();
this.pageMargins = ctWorksheet.getPageMargins() == null ? ctWorksheet.addNewPageMargins() : ctWorksheet.getPageMargins();
==================================================================== */\r
package org.apache.poi.xssf.usermodel;\r
\r
-import org.apache.xmlbeans.XmlObject;\r
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor;\r
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTAbsoluteAnchor;\r
-import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTOneCellAnchor;\r
-import org.openxmlformats.schemas.drawingml.x2006.chartDrawing.CTGroupShape;\r
import org.openxmlformats.schemas.drawingml.x2006.main.*;\r
\r
/**\r
\r
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*;\r
import org.openxmlformats.schemas.drawingml.x2006.main.*;\r
-import org.openxml4j.opc.PackagePartName;\r
import org.openxml4j.opc.PackageRelationship;\r
-import org.openxml4j.opc.TargetMode;\r
-\r
-import java.util.List;\r
\r
/**\r
* This object specifies a group shape that represents many shapes grouped together. This shape is to be treated\r
* @param drawing the XSSFDrawing that owns this shape\r
* @param ctGroup the XML bean that stores this group content\r
*/\r
- public XSSFShapeGroup(XSSFDrawing drawing, CTGroupShape ctGroup) {\r
+ protected XSSFShapeGroup(XSSFDrawing drawing, CTGroupShape ctGroup) {\r
this.drawing = drawing;\r
this.ctGroup = ctGroup;\r
}\r
import org.apache.poi.hssf.util.PaneInformation;
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.Header;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.util.CellRangeAddress;
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.Control;
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
import org.apache.poi.POIXMLDocumentPart;
import org.apache.poi.POIXMLException;
import org.openxml4j.opc.PackagePart;
import org.openxml4j.opc.PackageRelationship;
import org.openxml4j.opc.PackageRelationshipCollection;
+import org.openxml4j.exceptions.InvalidFormatException;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
import org.openxmlformats.schemas.officeDocument.x2006.relationships.STRelationshipId;
protected CTSheet sheet;
protected CTWorksheet worksheet;
- protected TreeMap<Integer, Row> rows;
- protected List<XSSFHyperlink> hyperlinks;
- protected ColumnHelper columnHelper;
- private CommentsSource sheetComments;
+ private TreeMap<Integer, Row> rows;
+ private List<XSSFHyperlink> hyperlinks;
+ private ColumnHelper columnHelper;
+ private CommentsTable sheetComments;
- public XSSFSheet() {
- super(null, null);
- this.worksheet = newSheet();
- initialize();
+ /**
+ * Creates new XSSFSheet - called by XSSFWorkbook to create a sheet from scratch.
+ *
+ * @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);
- worksheet = WorksheetDocument.Factory.parse(part.getInputStream()).getWorksheet();
}
/**
return (XSSFWorkbook)getParent();
}
- protected void initialize(){
- if (this.worksheet.getSheetData() == null) {
- this.worksheet.addNewSheetData();
+ /**
+ * Initialize worksheet data when reading in an exisiting file.
+ */
+ @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()){
if(p instanceof CommentsTable) sheetComments = (CommentsTable)p;
}
+ // Process external hyperlinks for the sheet, if there are any
+ initHyperlinks();
+ }
+
+ /**
+ * 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 and setup default values
+ * Create a new CTWorksheet instance with all values set to defaults
*
* @return a new instance
*/
- protected static CTWorksheet newSheet(){
+ private static CTWorksheet newSheet(){
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
CTSheetFormatPr ctFormat = worksheet.addNewSheetFormatPr();
ctFormat.setDefaultRowHeight(15.0);
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 columnHelper;
}
- protected void initRows(CTWorksheet worksheet) {
- this.rows = new TreeMap<Integer, Row>();
- for (CTRow row : worksheet.getSheetData().getRowArray()) {
- XSSFRow r = new XSSFRow(row, this);
- this.rows.put(r.getRowNum(), r);
- }
- }
-
- 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;
- }
+ /**
+ * Sdds a merged region of cells (hence those cells form one)
+ *
+ * @param cra (rowfrom/colfrom-rowto/colto) to merge
+ * @return index of this region
+ */
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();
CTMergeCell ctMergeCell = ctMergeCells.addNewMergeCell();
- ctMergeCell.setRef(region.getRegionRef());
+ ctMergeCell.setRef(cra.formatAsString());
return ctMergeCells.sizeOfMergeCellArray();
}
/**
* Adjusts the column width to fit the contents.
- *
+ * <p>
* This process can be relatively slow on large sheets, so this should
* normally only be called once per column, at the end of your
* processing.
- *
+ * </p>
* You can specify whether the content of merged cells should be considered or ignored.
* Default is to ignore merged cells.
*
if (sheetComments == null) {
sheetComments = (CommentsTable)createRelationship(XSSFRelation.SHEET_COMMENTS, XSSFFactory.getInstance(), (int)sheet.getSheetId());
}
- return (XSSFComment)sheetComments.addComment();
+ return sheetComments.addComment();
}
/**
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) {
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) {
* @return the number of the first logical row on the sheet, zero based
*/
public int getFirstRowNum() {
- for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
- Row row = it.next();
- if (row != null) {
- return row.getRowNum();
- }
- }
- return -1;
+ return rows.size() == 0 ? -1 : rows.firstKey();
}
/**
}
public int getLastRowNum() {
- int lastRowNum = -1;
- for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
- Row row = it.next();
- if (row != null) {
- lastRowNum = row.getRowNum();
- }
- }
- return lastRowNum;
+ return rows.size() == 0 ? -1 : rows.lastKey();
}
public short getLeftCol() {
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) {
- CTPageMargins pageMargins = getSheetTypePageMargins();
+ if (!worksheet.isSetPageMargins()) return 0;
+
+ CTPageMargins pageMargins = worksheet.getPageMargins();
switch (margin) {
- case LeftMargin:
- return pageMargins.getLeft();
- case RightMargin:
- return pageMargins.getRight();
- case TopMargin:
- return pageMargins.getTop();
- case BottomMargin:
- return pageMargins.getBottom();
- case HeaderMargin:
- return pageMargins.getHeader();
- case FooterMargin:
- return pageMargins.getFooter();
- default :
- throw new POIXMLException( "Unknown margin constant: " + margin );
+ case LeftMargin:
+ return pageMargins.getLeft();
+ case RightMargin:
+ return pageMargins.getRight();
+ case TopMargin:
+ return pageMargins.getTop();
+ case BottomMargin:
+ return pageMargins.getBottom();
+ case HeaderMargin:
+ return pageMargins.getHeader();
+ case FooterMargin:
+ return pageMargins.getFooter();
+ default :
+ throw new POIXMLException("Unknown margin constant: " + margin);
}
}
- protected CTPageMargins getSheetTypePageMargins() {
- if (worksheet.getPageMargins() == null) {
- worksheet.setPageMargins(CTPageMargins.Factory.newInstance());
+ /**
+ * Sets the size of the margin in inches.
+ *
+ * @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
+ * @throws IllegalStateException if this worksheet does not contain merged regions
*/
public CellRangeAddress getMergedRegion(int index) {
CTMergeCells ctMergeCells = worksheet.getMergeCells();
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() {
CTMergeCells ctMergeCells = worksheet.getMergeCells();
return ctMergeCells == null ? 0 : ctMergeCells.sizeOfMergeCellArray();
return hyperlinks.size();
}
- public boolean getObjectProtect() {
- // TODO Auto-generated method stub
- return false;
- }
-
public PaneInformation getPaneInformation() {
// TODO Auto-generated method stub
return null;
}
- public short getPassword() {
- // TODO Auto-generated method stub
- return 0;
- }
-
+ /**
+ * Returns the number of phsyically defined rows (NOT the number of rows in the sheet)
+ *
+ * @return the number of phsyically defined rows
+ */
public int getPhysicalNumberOfRows() {
- int counter = 0;
- for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
- if (it.next() != null) {
- counter++;
- }
- }
- return counter;
+ return rows.size();
}
+ /**
+ * Gets the print setup object.
+ *
+ * @return The user model for the print setup object.
+ */
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() {
- // TODO Auto-generated method stub
- return false;
+ return worksheet.isSetSheetProtection() && worksheet.getSheetProtection().getSheet();
}
/**
public boolean getRowSumsBelow() {
CTSheetPr sheetPr = worksheet.getSheetPr();
CTOutlinePr outlinePr = (sheetPr != null && sheetPr.isSetOutlinePr())
- ? sheetPr.getOutlinePr() : CTOutlinePr.Factory.newInstance();
- return outlinePr.getSummaryBelow();
+ ? sheetPr.getOutlinePr() : null;
+ return outlinePr == null || outlinePr.getSummaryBelow();
}
/**
*/
private CTOutlinePr ensureOutlinePr(){
CTSheetPr sheetPr = worksheet.isSetSheetPr() ? worksheet.getSheetPr() : worksheet.addNewSheetPr();
- CTOutlinePr outlinePr = sheetPr.isSetOutlinePr() ? sheetPr.getOutlinePr() : sheetPr.addNewOutlinePr();
- return outlinePr;
+ return sheetPr.isSetOutlinePr() ? sheetPr.getOutlinePr() : sheetPr.addNewOutlinePr();
}
/**
* @return true => protection enabled; false => protection disabled
*/
public boolean getScenarioProtect() {
- return getSheetTypeProtection().getScenarios();
- }
-
- protected CTSheetProtection getSheetTypeProtection() {
- if (worksheet.getSheetProtection() == null) {
- worksheet.setSheetProtection(CTSheetProtection.Factory.newInstance());
- }
- return worksheet.getSheetProtection();
+ return worksheet.isSetSheetProtection() && worksheet.getSheetProtection().getScenarios();
}
/**
}
}
- public void protectSheet(String password) {
- // TODO Auto-generated method stub
-
- }
-
/**
* Removes a merged region of cells (hence letting them free)
*
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) {
-
rows.remove(row.getRowNum());
}
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) {
getSheetTypePrintOptions().setGridLines(newPrintGridlines);
}
getSheetTypeSheetFormatPr().setOutlineLevelCol(maxLevelCol);
}
- protected CTSheetViews getSheetTypeSheetViews() {
+ private CTSheetViews getSheetTypeSheetViews() {
if (worksheet.getSheetViews() == null) {
worksheet.setSheetViews(CTSheetViews.Factory.newInstance());
worksheet.getSheetViews().addNewSheetView();
if(sheetComments == null) { return false; }
return (sheetComments.getNumberOfComments() > 0);
}
+
protected int getNumberOfComments() {
if(sheetComments == null) { return 0; }
return sheetComments.getNumberOfComments();
* Returns the sheet's comments object if there is one,
* or null if not
*/
- protected CommentsSource getCommentsSourceIfExists() {
+ protected CommentsTable getCommentsSourceIfExists() {
return sheetComments;
}
package org.apache.poi.xssf.usermodel;\r
\r
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.*;\r
-import org.openxmlformats.schemas.drawingml.x2006.main.*;\r
\r
/**\r
* Represents a text box in a SpreadsheetML drawing.\r
import org.apache.poi.POIXMLException;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlOptions;
+import org.apache.xmlbeans.XmlException;
import org.openxml4j.exceptions.OpenXML4JException;
-import org.openxml4j.exceptions.InvalidFormatException;
import org.openxml4j.opc.*;
import org.openxml4j.opc.Package;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
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.
*/
public XSSFWorkbook() {
- super();
- onDocumentCreate();
- }
-
- /**
- * Constructs a XSSFWorkbook object given a file name.
- *
- * @param path the file name.
- */
- public XSSFWorkbook(String path) throws IOException {
- this(openPackage(path));
+ super(newPackage());
+ onWorkbookCreate();
}
/**
*/
public XSSFWorkbook(Package pkg) throws IOException {
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();
}
+ /**
+ * 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.
* Packages opened by Package.open(InputStream is) are read-only,
return pkg;
}
- /**
- * Initialize this workbook from the specified Package
- */
@Override
- protected void onDocumentRead() {
+ protected void onDocumentRead() throws IOException {
try {
- //build the POIXMLDocumentPart tree, this workbook is the root
- read(XSSFFactory.getInstance());
-
WorkbookDocument doc = WorkbookDocument.Factory.parse(getPackagePart().getInputStream());
this.workbook = doc.getWorkbook();
- HashMap<String, XSSFSheet> shIdMap = new HashMap<String, XSSFSheet>();
+ Map<String, XSSFSheet> shIdMap = new HashMap<String, XSSFSheet>();
for(POIXMLDocumentPart p : getRelations()){
if(p instanceof SharedStringsTable) sharedStringSource = (SharedStringsTable)p;
else if(p instanceof StylesTable) stylesSource = (StylesTable)p;
}
}
- // Load individual sheets
- sheets = new LinkedList<XSSFSheet>();
- embedds = new LinkedList<PackagePart>();
+ // Load individual sheets. The order of sheets is defined by the order of CTSheet beans in the workbook
+ sheets = new ArrayList<XSSFSheet>(shIdMap.size());
for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) {
- String id = ctSheet.getId();
- XSSFSheet sh = shIdMap.get(id);
- sh.sheet = ctSheet;
+ XSSFSheet sh = shIdMap.get(ctSheet.getId());
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");
continue;
}
- //initialize internal arrays of rows and columns
- sh.initialize();
-
- 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));
-
+ sh.sheet = ctSheet;
+ sh.onDocumentRead();
sheets.add(sh);
}
}
// Process the named ranges
- namedRanges = new LinkedList<XSSFName>();
+ namedRanges = new ArrayList<XSSFName>();
if(workbook.getDefinedNames() != null) {
for(CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameArray()) {
namedRanges.add(new XSSFName(ctName, this));
}
}
- } catch (Exception e) {
+ } catch (XmlException 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();
CTBookViews bvs = workbook.addNewBookViews();
CTBookView bv = bvs.addNewWorkbookView();
sharedStringSource = (SharedStringsTable)createRelationship(XSSFRelation.SHARED_STRINGS, XSSFFactory.getInstance());
stylesSource = (StylesTable)createRelationship(XSSFRelation.STYLES, XSSFFactory.getInstance());
- namedRanges = new LinkedList<XSSFName>();
- sheets = new LinkedList<XSSFSheet>();
- embedds = new LinkedList<PackagePart>();
+ namedRanges = new ArrayList<XSSFName>();
+ sheets = new ArrayList<XSSFSheet>();
}
/**
* Create a new SpreadsheetML package and setup the default minimal content
*/
- protected Package newPackage() throws IOException {
+ protected static Package newPackage() {
try {
Package pkg = Package.create(PackageHelper.createTempFile());
// Main part
pkg.getPackageProperties().setCreatorProperty("Apache POI");
return pkg;
- } catch (InvalidFormatException e){
+ } catch (Exception e){
throw new POIXMLException(e);
}
}
*
* @return the underlying CTWorkbook bean
*/
- public CTWorkbook getWorkbook() {
+ public CTWorkbook getCTWorkbook() {
return this.workbook;
}
}
XSSFSheet clonedSheet = createSheet(name);
- clonedSheet.worksheet.set(srcSheet.worksheet);
+ clonedSheet.getCTWorksheet().set(srcSheet.getCTWorksheet());
return clonedSheet;
}
}
/**
- * 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
*/
}
/**
- * 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
*/
}
/**
- * 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.
*
* @return XSSFSheet representing the new sheet.
}
/**
- * 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.
*
* @param sheetname sheetname to set for the sheet, can't be duplicate, greater than 31 chars or contain /\?*[]
* @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) {
if (containsSheet( sheetname, sheets.size() ))
throw new IllegalArgumentException( "The workbook already contains a sheet of this name" );
+ CTSheet sheet = addSheet(sheetname);
+
int sheetNumber = getNumberOfSheets() + 1;
XSSFSheet wrapper = (XSSFSheet)createRelationship(XSSFRelation.WORKSHEET, XSSFFactory.getInstance(), sheetNumber);
-
- CTSheet sheet = addSheet(sheetname);
wrapper.sheet = sheet;
sheet.setId(wrapper.getPackageRelationship().getId());
sheet.setSheetId(sheetNumber);
if(sheets.size() == 0) wrapper.setSelected(true);
- this.sheets.add(wrapper);
+ sheets.add(wrapper);
return wrapper;
}
public int getActiveSheetIndex() {
//activeTab (Active Sheet Index) Specifies an unsignedInt
//that contains the index to the active sheet in this book view.
- Long index = 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;
+ return (int)workbook.getBookViews().getWorkbookViewArray(0).getActiveTab();
}
/**
* Gets all pictures from the Workbook.
*
* @return the list of pictures (a list of {@link XSSFPictureData} objects.)
+ * @see #addPicture(byte[], int)
*/
public List<XSSFPictureData> getAllPictures() {
if(pictures == null) {
* @return XSSFSheet with the name provided or <code>null</code> if it does not exist
*/
public XSSFSheet getSheet(String name) {
- CTSheet[] sheets = this.workbook.getSheets().getSheetArray();
- for (int i = 0 ; i < sheets.length ; ++i) {
- if (name.equals(sheets[i].getName())) {
- return this.sheets.get(i);
+ CTSheet[] ctSheets = this.workbook.getSheets().getSheetArray();
+ for (int i = 0 ; i < ctSheets.length ; ++i) {
+ if (name.equalsIgnoreCase(ctSheets[i].getName())) {
+ return sheets.get(i);
}
}
return null;
*
* @param index of the sheet number (0-based physical & logical)
* @return XSSFSheet at the provided index
+ * @throws IllegalArgumentException if the index is out of range (index
+ * < 0 || index >= getNumberOfSheets()).
*/
public XSSFSheet getSheetAt(int 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
- * @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) {
CTSheet[] sheets = this.workbook.getSheets().getSheetArray();
for (int i = 0 ; i < sheets.length ; ++i) {
- if (name.equals(sheets[i].getName())) {
+ if (name.equalsIgnoreCase(sheets[i].getName())) {
return i;
}
}
*/
public void write(OutputStream stream) throws IOException {
//force all children to commit their changes into the underlying OOXML Package
- save();
+ onSave();
getPackage().save(stream);
}
* Get the document's embedded files.
*/
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;
}
}
assertEquals(1, st._getStyleXfsSize());
assertEquals(0, st._getNumberFormatSize());
- long nf1 = st.putNumberFormat("yyyy-mm-dd");
- long nf2 = st.putNumberFormat("yyyy-mm-DD");
+ int nf1 = st.putNumberFormat("yyyy-mm-dd");
+ int nf2 = st.putNumberFormat("yyyy-mm-DD");
assertEquals(nf1, st.putNumberFormat("yyyy-mm-dd"));
st.putStyle(new XSSFCellStyle(st));
assertEquals(1, st._getStyleXfsSize());
assertEquals(8, st._getNumberFormatSize());
- long nf1 = st.putNumberFormat("YYYY-mm-dd");
- long nf2 = st.putNumberFormat("YYYY-mm-DD");
+ int nf1 = st.putNumberFormat("YYYY-mm-dd");
+ int nf2 = st.putNumberFormat("YYYY-mm-DD");
assertEquals(nf1, st.putNumberFormat("YYYY-mm-dd"));
st = XSSFTestDataSamples.writeOutAndReadBack(workbook).getStylesSource();
Cell cell = sheet.createRow(0).createCell((short)0);
cell.setAsActiveCell();
- assertEquals("A1", sheet.getWorksheet().getSheetViews().getSheetViewArray(0).getSelectionArray(0).getActiveCell());
+ assertEquals("A1", sheet.getCTWorksheet().getSheetViews().getSheetViewArray(0).getSelectionArray(0).getActiveCell());
}
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
public class TestXSSFDialogSheet extends TestCase {
public void testGetSetAutoBreaks() {
XSSFWorkbook workbook = new XSSFWorkbook();
- XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+ XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
assertTrue(sheet.getAutobreaks());
sheet.setAutobreaks(false);
assertFalse(sheet.getAutobreaks());
public void testIsSetFitToPage() {
XSSFWorkbook workbook = new XSSFWorkbook();
- XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+ XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
assertFalse(sheet.getFitToPage());
sheet.setFitToPage(true);
assertTrue(sheet.getFitToPage());
public void testGetSetMargin() {
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));
sheet.setMargin((short) 0, 10);
assertEquals((double) 10, sheet.getMargin((short) 0));
public void testGetFooter() {
XSSFWorkbook workbook = new XSSFWorkbook();
- XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+ XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
assertNotNull(sheet.getFooter());
sheet.getFooter().setCenter("test center footer");
assertEquals("test center footer", sheet.getFooter().getCenter());
public void testGetAllHeadersFooters() {
XSSFWorkbook workbook = new XSSFWorkbook();
- XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+ XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
assertNotNull(sheet);
assertNotNull(sheet.getOddFooter());
assertNotNull(sheet.getEvenFooter());
public void testGetSetHorizontallyCentered() {
XSSFWorkbook workbook = new XSSFWorkbook();
- XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+ XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
assertFalse(sheet.getHorizontallyCenter());
sheet.setHorizontallyCenter(true);
assertTrue(sheet.getHorizontallyCenter());
public void testGetSetVerticallyCentered() {
XSSFWorkbook workbook = new XSSFWorkbook();
- XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+ XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
assertFalse(sheet.getVerticallyCenter());
sheet.setVerticallyCenter(true);
assertTrue(sheet.getVerticallyCenter());
public void testIsSetPrintGridlines() {
XSSFWorkbook workbook = new XSSFWorkbook();
- XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+ XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
assertFalse(sheet.isPrintGridlines());
sheet.setPrintGridlines(true);
assertTrue(sheet.isPrintGridlines());
public void testIsSetDisplayFormulas() {
XSSFWorkbook workbook = new XSSFWorkbook();
- XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+ XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
assertFalse(sheet.isDisplayFormulas());
sheet.setDisplayFormulas(true);
assertTrue(sheet.isDisplayFormulas());
public void testIsSetDisplayGridLines() {
XSSFWorkbook workbook = new XSSFWorkbook();
- XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+ XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
assertTrue(sheet.isDisplayGridlines());
sheet.setDisplayGridlines(false);
assertFalse(sheet.isDisplayGridlines());
public void testIsSetDisplayRowColHeadings() {
XSSFWorkbook workbook = new XSSFWorkbook();
- XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+ XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
assertTrue(sheet.isDisplayRowColHeadings());
sheet.setDisplayRowColHeadings(false);
assertFalse(sheet.isDisplayRowColHeadings());
public void testGetScenarioProtect() {
XSSFWorkbook workbook = new XSSFWorkbook();
- XSSFDialogsheet sheet = (XSSFDialogsheet) workbook.createDialogsheet("Dialogsheet 1", null);
+ XSSFDialogsheet sheet = workbook.createDialogsheet("Dialogsheet 1", null);
assertFalse(sheet.getScenarioProtect());
}
String drawingId = drawing.getPackageRelationship().getId();\r
\r
//there should be a relation to this drawing in the worksheet\r
- assertTrue(sheet.getWorksheet().isSetDrawing());\r
- assertEquals(drawingId, sheet.getWorksheet().getDrawing().getId());\r
+ assertTrue(sheet.getCTWorksheet().isSetDrawing());\r
+ assertEquals(drawingId, sheet.getCTWorksheet().getDrawing().getId());\r
\r
}\r
\r
String drawingId = drawing.getPackageRelationship().getId();\r
\r
//there should be a relation to this drawing in the worksheet\r
- assertTrue(sheet.getWorksheet().isSetDrawing());\r
- assertEquals(drawingId, sheet.getWorksheet().getDrawing().getId());\r
+ assertTrue(sheet.getCTWorksheet().isSetDrawing());\r
+ assertEquals(drawingId, sheet.getCTWorksheet().getDrawing().getId());\r
\r
}\r
public void testMultipleDrawings(){\r
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
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.StylesTable;
import org.apache.poi.xssf.usermodel.helpers.ColumnHelper;
// Now check the low level stuff, and check that's all
// been set correctly
XSSFSheet xs = sheet;
- CTWorksheet cts = xs.getWorksheet();
+ CTWorksheet cts = xs.getCTWorksheet();
CTCols[] cols_s = cts.getColsArray();
assertEquals(1, cols_s.length);
sheet.setCellComment("A1", comment);
assertEquals("A1", ctComments.getCommentList().getCommentArray(0).getRef());
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 testCreateFreezePane() {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
- CTWorksheet ctWorksheet = sheet.getWorksheet();
+ CTWorksheet ctWorksheet = sheet.getCTWorksheet();
sheet.createFreezePane(2, 4);
assertEquals((double)2, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getXSplit());
public void testNewMergedRegionAt() {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
- Region region = new Region("B2:D4");
+ CellRangeAddress region = CellRangeAddress.valueOf("B2:D4");
sheet.addMergedRegion(region);
- assertEquals("B2:D4", sheet.getMergedRegionAt(0).getRegionRef());
+ assertEquals("B2:D4", sheet.getMergedRegion(0).formatAsString());
}
public void testGetNumMergedRegions() {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
- CTWorksheet ctWorksheet = sheet.getWorksheet();
assertEquals(0, sheet.getNumMergedRegions());
- Region region = new Region("B2:D4");
+ CellRangeAddress region = CellRangeAddress.valueOf("B2:D4");
sheet.addMergedRegion(region);
assertEquals(1, sheet.getNumMergedRegions());
}
public void testRemoveMergedRegion() {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
- CTWorksheet ctWorksheet = sheet.getWorksheet();
- Region region_1 = new Region("A1:B2");
- Region region_2 = new Region("C3:D4");
- Region region_3 = new Region("E5:F6");
+ CTWorksheet ctWorksheet = sheet.getCTWorksheet();
+ CellRangeAddress region_1 = CellRangeAddress.valueOf("A1:B2");
+ CellRangeAddress region_2 = CellRangeAddress.valueOf("C3:D4");
+ CellRangeAddress region_3 = CellRangeAddress.valueOf("E5:F6");
sheet.addMergedRegion(region_1);
sheet.addMergedRegion(region_2);
sheet.addMergedRegion(region_3);
public void testSetDefaultColumnStyle() {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
- CTWorksheet ctWorksheet = sheet.getWorksheet();
+ CTWorksheet ctWorksheet = sheet.getCTWorksheet();
StylesTable stylesTable = workbook.getStylesSource();
XSSFFont font = new XSSFFont();
font.setFontName("Cambria");
//one level
sheet.groupColumn((short)2,(short)7);
sheet.groupColumn((short)10,(short)11);
- CTCols cols=sheet.getWorksheet().getColsArray(0);
+ CTCols cols=sheet.getCTWorksheet().getColsArray(0);
assertEquals(2,cols.sizeOfColArray());
CTCol[]colArray=cols.getColArray();
assertNotNull(colArray);
//two level
sheet.groupColumn((short)1,(short)2);
- cols=sheet.getWorksheet().getColsArray(0);
+ cols=sheet.getCTWorksheet().getColsArray(0);
assertEquals(4,cols.sizeOfColArray());
colArray=cols.getColArray();
assertEquals(2, colArray[1].getOutlineLevel());
//three level
sheet.groupColumn((short)6,(short)8);
sheet.groupColumn((short)2,(short)3);
- cols=sheet.getWorksheet().getColsArray(0);
+ cols=sheet.getCTWorksheet().getColsArray(0);
assertEquals(7,cols.sizeOfColArray());
colArray=cols.getColArray();
assertEquals(3, colArray[1].getOutlineLevel());
//one level
sheet.groupRow(9,10);
- assertEquals(2,sheet.rows.size());
+ assertEquals(2,sheet.getPhysicalNumberOfRows());
CTRow ctrow = sheet.getRow(8).getCTRow();
assertNotNull(ctrow);
//two level
sheet.groupRow(10,13);
- assertEquals(5,sheet.rows.size());
+ assertEquals(5,sheet.getPhysicalNumberOfRows());
ctrow = sheet.getRow(9).getCTRow();
assertNotNull(ctrow);
assertEquals(10,ctrow.getR());
sheet.ungroupRow(8, 10);
- assertEquals(4,sheet.rows.size());
+ assertEquals(4,sheet.getPhysicalNumberOfRows());
assertEquals(1,sheet.getSheetTypeSheetFormatPr().getOutlineLevelRow());
sheet.ungroupRow(10,10);
- assertEquals(3,sheet.rows.size());
+ assertEquals(3,sheet.getPhysicalNumberOfRows());
assertEquals(1,sheet.getSheetTypeSheetFormatPr().getOutlineLevelRow());
}
public void testGetSetActiveSheet(){
XSSFWorkbook workbook = new XSSFWorkbook();
+ assertEquals(0, workbook.getActiveSheetIndex());
+
workbook.createSheet("sheet1");
workbook.createSheet("sheet2");
workbook.createSheet("sheet3");
assertSame(sheet2, workbook.getSheetAt(0));
assertSame(sheet1, workbook.getSheetAt(1));
// Test reordering of CTSheets
- CTWorkbook ctwb = workbook.getWorkbook();
+ CTWorkbook ctwb = workbook.getCTWorkbook();
CTSheet[] ctsheets = ctwb.getSheets().getSheetArray();
assertEquals("sheet2", ctsheets[0].getName());
assertEquals("sheet1", ctsheets[1].getName());
assertNotNull(cellStyleAt);
//get custom style
- StylesSource styleSource = workbook.getStylesSource();
+ StylesTable styleSource = workbook.getStylesSource();
CellStyle customStyle = new XSSFCellStyle(styleSource);
Font font = new XSSFFont();
font.setFontName("Verdana");
customStyle.setFont(font);
- Long x = styleSource.putStyle(customStyle);
- cellStyleAt = workbook.getCellStyleAt(x.shortValue());
+ int x = styleSource.putStyle(customStyle);
+ cellStyleAt = workbook.getCellStyleAt((short)x);
assertNotNull(cellStyleAt);
}
public void testGetFontAt(){
XSSFWorkbook workbook = new XSSFWorkbook();
- StylesSource styleSource = workbook.getStylesSource();
+ StylesTable styleSource = workbook.getStylesSource();
short i = 0;
//get default font
Font fontAt = workbook.getFontAt(i);
//get customized font
Font customFont = new XSSFFont();
customFont.setItalic(true);
- Long x = styleSource.putFont(customFont);
- fontAt = workbook.getFontAt(x.shortValue());
+ int x = styleSource.putFont(customFont);
+ fontAt = workbook.getFontAt((short)x);
assertNotNull(fontAt);
}
public void testStyles() {
XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("Formatting.xlsx");
- StylesSource ss = workbook.getStylesSource();
+ StylesTable ss = workbook.getStylesSource();
assertNotNull(ss);
assertTrue(ss instanceof StylesTable);
StylesTable st = (StylesTable)ss;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
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.CTXf;
// Remember - POI column 0 == OOXML column 1
assertEquals((double) 88, helper.getColumn(0, false).getWidth());
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());
}
public void testGetSetColDefaultStyle() {
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet();
- CTWorksheet ctWorksheet = sheet.getWorksheet();
+ CTWorksheet ctWorksheet = sheet.getCTWorksheet();
ColumnHelper columnHelper = sheet.getColumnHelper();
// POI column 3, OOXML column 4
columnHelper.setColDefaultStyle(3, 2);
assertEquals(2, columnHelper.getColDefaultStyle(3));
assertEquals(-1, columnHelper.getColDefaultStyle(4));
- StylesTable stylesTable = (StylesTable) workbook.getStylesSource();
+ StylesTable stylesTable = workbook.getStylesSource();
CTXf cellXf = CTXf.Factory.newInstance();
cellXf.setFontId(0);
cellXf.setFillId(0);