aboutsummaryrefslogtreecommitdiffstats
path: root/src/ooxml/java/org/apache
diff options
context:
space:
mode:
Diffstat (limited to 'src/ooxml/java/org/apache')
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/POIXMLDocumentPart.java15
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java6
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java17
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java14
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java11
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/xssf/usermodel/BorderStyle.java4
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/xssf/usermodel/FillPatternType.java2
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/xssf/usermodel/FontCharset.java65
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/xssf/usermodel/FontFamily.java40
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/xssf/usermodel/FontScheme.java45
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/xssf/usermodel/FontUnderline.java136
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/xssf/usermodel/IndexedColors.java3
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/xssf/usermodel/PageOrder.java32
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/xssf/usermodel/PaperSize.java1
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/xssf/usermodel/PrintCellComments.java38
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/xssf/usermodel/PrintOrientation.java40
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java15
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDialogsheet.java17
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java71
-rwxr-xr-xsrc/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java34
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java67
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java46
-rw-r--r--src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java49
23 files changed, 307 insertions, 461 deletions
diff --git a/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java b/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
index faf7e7c07e..342c9949e5 100755
--- a/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
+++ b/src/ooxml/java/org/apache/poi/POIXMLDocumentPart.java
@@ -176,6 +176,7 @@ public class POIXMLDocumentPart {
doc.packageRel = rel;
doc.packagePart = part;
doc.parent = this;
+ doc.onDocumentCreate();
addRelation(doc);
return doc;
} catch (Exception e){
@@ -201,6 +202,7 @@ public class POIXMLDocumentPart {
}
POIXMLDocumentPart childPart = factory.createDocumentPart(rel, p);
childPart.parent = this;
+ childPart.onDocumentRead();
addRelation(childPart);
if(p.hasRelationships()) childPart.read(factory);
@@ -208,4 +210,17 @@ public class POIXMLDocumentPart {
}
}
+ /**
+ * Fired when a new package part is created
+ */
+ public void onDocumentCreate(){
+
+ }
+
+ /**
+ * Fired when a package part is read
+ */
+ public void onDocumentRead(){
+
+ }
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
index f0a84d1603..ceeaa0f441 100644
--- a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
+++ b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
@@ -68,7 +68,8 @@ public class XSSFReader {
* shared strings.
*/
public SharedStringsTable getSharedStringsTable() throws IOException, InvalidFormatException {
- return new SharedStringsTable(getSharedStringsData());
+ ArrayList<PackagePart> parts = pkg.getPartsByContentType( XSSFRelation.SHARED_STRINGS.getContentType());
+ return parts.size() == 0 ? null : new SharedStringsTable(parts.get(0), null);
}
/**
@@ -76,7 +77,8 @@ public class XSSFReader {
* returns a handy object for working with cell styles
*/
public StylesTable getStylesTable() throws IOException, InvalidFormatException {
- return new StylesTable(getStylesData());
+ ArrayList<PackagePart> parts = pkg.getPartsByContentType( XSSFRelation.STYLES.getContentType());
+ return parts.size() == 0 ? null : new StylesTable(parts.get(0), null);
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java b/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java
index f59a8bc308..b0efd0bd46 100644
--- a/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java
+++ b/src/ooxml/java/org/apache/poi/xssf/model/CommentsTable.java
@@ -35,23 +35,12 @@ import org.openxml4j.opc.PackagePart;
import org.openxml4j.opc.PackageRelationship;
public class CommentsTable extends POIXMLDocumentPart implements CommentsSource {
- private CTComments comments;
+ protected CTComments comments;
- public CommentsTable(InputStream is) throws IOException {
- super(null, null);
- readFrom(is);
- }
public CommentsTable() {
super(null, null);
comments = CTComments.Factory.newInstance();
}
- /**
- * For unit testing only!
- */
- public CommentsTable(CTComments comments) {
- super(null, null);
- this.comments = comments;
- }
public CommentsTable(PackagePart part, PackageRelationship rel) throws IOException {
super(part, rel);
@@ -148,4 +137,8 @@ public class CommentsTable extends POIXMLDocumentPart implements CommentsSource
getCommentsAuthors().insertAuthor(index, author);
return index;
}
+
+ public CTComments getCTComments(){
+ return comments;
+ }
} \ No newline at end of file
diff --git a/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java b/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java
index cbf2811676..94d0174567 100644
--- a/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java
+++ b/src/ooxml/java/org/apache/poi/xssf/model/SharedStringsTable.java
@@ -60,7 +60,7 @@ import org.openxml4j.opc.PackageRelationship;
* @author Nick Birch
* @author Yegor Kozlov
*/
-public class SharedStringsTable extends POIXMLDocumentPart implements SharedStringSource {
+public class SharedStringsTable extends POIXMLDocumentPart {
/**
* Array of individual string items in the Shared String table.
@@ -85,18 +85,6 @@ public class SharedStringsTable extends POIXMLDocumentPart implements SharedStri
*/
private int uniqueCount;
- /**
- * Create a new SharedStringsTable, by reading it
- * from the InputStream of a PackagePart.
- *
- * @param is The input stream containing the XML document.
- * @throws IOException if an error occurs while reading.
- */
- public SharedStringsTable(InputStream is) throws IOException {
- super(null, null);
- readFrom(is);
- }
-
public SharedStringsTable() {
super(null, null);
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
index 1e7fdd888f..2e1473b671 100644
--- a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
+++ b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java
@@ -82,17 +82,6 @@ public class StylesTable extends POIXMLDocumentPart implements StylesSource {
private StyleSheetDocument doc;
/**
- * Create a new StylesTable, by reading it from
- * the InputStream of a a PackagePart.
- *
- * @param is The input stream containing the XML document.
- * @throws IOException if an error occurs while reading.
- */
- public StylesTable(InputStream is) throws IOException {
- super(null, null);
- readFrom(is);
- }
- /**
* Create a new, empty StylesTable
*/
public StylesTable() {
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/BorderStyle.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/BorderStyle.java
index 11f29233b4..a9d596931c 100755
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/BorderStyle.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/BorderStyle.java
@@ -22,9 +22,7 @@ package org.apache.poi.xssf.usermodel;
* i.e., whether it is borded dash dot, dash dot dot, dashed, dotted, double, hair, medium,
* medium dash dot, medium dash dot dot, medium dashed, none, slant dash dot, thick or thin.
*/
-
-
-public enum BorderStyle {
+ public enum BorderStyle {
/**
* No border
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/FillPatternType.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/FillPatternType.java
index 98ec5eee00..36e3c9e255 100755
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/FillPatternType.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/FillPatternType.java
@@ -21,8 +21,6 @@ package org.apache.poi.xssf.usermodel;
* The enumeration value indicating the style of fill pattern being used for a cell format.
*
*/
-
-
public enum FillPatternType {
/** No background */
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/FontCharset.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/FontCharset.java
index 4ad63f06ae..215ccec991 100755
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/FontCharset.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/FontCharset.java
@@ -23,7 +23,6 @@ package org.apache.poi.xssf.usermodel;
* corresponds to the ANSI codepage (8-bit or DBCS) of that character set used by a given language.
*
* @author Gisella Bronzetti
- *
*/
public enum FontCharset {
@@ -33,7 +32,6 @@ public enum FontCharset {
MAC(77),
SHIFTJIS(128),
HANGEUL(129),
- HANGUL(129),
JOHAB(130),
GB2312(134),
CHINESEBIG5(136),
@@ -51,62 +49,27 @@ public enum FontCharset {
private int charset;
-
- FontCharset(int value){
+ private FontCharset(int value){
charset = value;
}
/**
- * Returns index of this charset
+ * Returns value of this charset
*
- * @return index of this charset
+ * @return value of this charset
*/
- public byte getValue(){
- return (byte)charset;
+ public int getValue(){
+ return charset;
}
-
+
+ private static FontCharset[] _table = new FontCharset[256];
+ static {
+ for (FontCharset c : values()) {
+ _table[c.getValue()] = c;
+ }
+ }
+
public static FontCharset valueOf(int value){
- switch (value) {
- case 0:
- return ANSI;
- case 1:
- return DEFAULT;
- case 2:
- return SYMBOL;
- case 77:
- return MAC;
- case 128:
- return SHIFTJIS;
- case 129:
- return HANGEUL;
- case 130:
- return JOHAB;
- case 134:
- return GB2312;
- case 136:
- return CHINESEBIG5;
- case 161:
- return GREEK;
- case 162:
- return TURKISH;
- case 163:
- return VIETNAMESE;
- case 177:
- return HEBREW;
- case 178:
- return ARABIC;
- case 186:
- return BALTIC;
- case 204:
- return RUSSIAN;
- case 222:
- return THAI;
- case 238:
- return EASTEUROPE;
- case 255:
- return OEM;
- }
- throw new RuntimeException("Charset value ["+ value +"] not supported");
+ return _table[value];
}
-
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/FontFamily.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/FontFamily.java
index 2457336bd3..dc34e76bf3 100755
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/FontFamily.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/FontFamily.java
@@ -19,12 +19,10 @@ package org.apache.poi.xssf.usermodel;
/**
- *
* The font family this font belongs to. A font family is a set of fonts having common stroke width and serif
* characteristics. The font name overrides when there are conflicting values.
- *
- * @author Gisella Bronzetti
*
+ * @author Gisella Bronzetti
*/
public enum FontFamily {
@@ -34,11 +32,10 @@ public enum FontFamily {
MODERN(3),
SCRIPT(4),
DECORATIVE(5);
-
+
private int family;
-
- FontFamily(int value){
+ private FontFamily(int value) {
family = value;
}
@@ -47,28 +44,19 @@ public enum FontFamily {
*
* @return index of this font family
*/
- public int getValue(){
+ public int getValue() {
return family;
}
-
- public static FontFamily valueOf(int family){
- switch (family) {
- case 0:
- return NOT_APPLICABLE;
- case 1:
- return ROMAN;
- case 2:
- return SWISS;
- case 3:
- return MODERN;
- case 4:
- return SCRIPT;
- case 5:
- return DECORATIVE;
- }
- throw new RuntimeException("Family value ["+ family +"] not supported");
+ private static FontFamily[] _table = new FontFamily[6];
+
+ static {
+ for (FontFamily c : values()) {
+ _table[c.getValue()] = c;
+ }
+ }
+
+ public static FontFamily valueOf(int family) {
+ return _table[family];
}
-
-
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/FontScheme.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/FontScheme.java
index c7c9cf0f12..6576fbbbbf 100755
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/FontScheme.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/FontScheme.java
@@ -17,52 +17,41 @@
package org.apache.poi.xssf.usermodel;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STFontScheme;
-
/**
- * Defines the font scheme to which this font belongs.
+ * Defines the font scheme to which this font belongs.
* When a font definition is part of a theme definition, then the font is categorized as either a major or minor font scheme component.
* When a new theme is chosen, every font that is part of a theme definition is updated to use the new major or minor font definition for that
* theme.
* Usually major fonts are used for styles like headings, and minor fonts are used for body & paragraph text.
*
* @author Gisella Bronzetti
- *
*/
public enum FontScheme {
- MAJOR(STFontScheme.MAJOR),
- MINOR(STFontScheme.MINOR),
- NONE(STFontScheme.NONE);
+ NONE(1),
+ MAJOR(2),
+ MINOR(3);
- private STFontScheme.Enum scheme;
+ private int value;
-
- FontScheme(STFontScheme.Enum value){
- scheme = value;
+ private FontScheme(int val) {
+ value = val;
}
- /**
- * Returns STFontScheme.Enum value of this font scheme
- *
- * @return STFontScheme.Enum value of this font scheme
- */
- public STFontScheme.Enum getValue(){
- return scheme;
+ public int getValue() {
+ return value;
}
+ private static FontScheme[] _table = new FontScheme[4];
+ static {
+ for (FontScheme c : values()) {
+ _table[c.getValue()] = c;
+ }
+ }
- public static FontScheme valueOf(STFontScheme.Enum scheme){
- switch (scheme.intValue()) {
- case STFontScheme.INT_MAJOR:
- return MAJOR;
- case STFontScheme.INT_MINOR:
- return MINOR;
- case STFontScheme.INT_NONE:
- return NONE;
- }
- throw new RuntimeException("Schema value ["+ scheme +"] not supported");
+ public static FontScheme valueOf(int value){
+ return _table[value];
}
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/FontUnderline.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/FontUnderline.java
index 34b52bbef4..ec77af9009 100755
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/FontUnderline.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/FontUnderline.java
@@ -17,59 +17,107 @@
package org.apache.poi.xssf.usermodel;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
-
+import org.apache.poi.ss.usermodel.Font;
/**
* the different types of possible underline formatting
- *
- * @author Gisella Bronzetti
*
+ * @author Gisella Bronzetti
*/
public enum FontUnderline {
-
-/**
- * Double-line underlining under each character in the
- * cell. underlines are drawn through the descenders of
- * characters such as g and p.
- */
- DOUBLE(STUnderlineValues.DOUBLE),
- DOUBLE_ACCOUNTING(STUnderlineValues.DOUBLE_ACCOUNTING),
- NONE(STUnderlineValues.NONE),
- SINGLE(STUnderlineValues.SINGLE),
- SINGLE_ACCOUNTING(STUnderlineValues.SINGLE_ACCOUNTING);
-
- private STUnderlineValues.Enum underline;
-
-
- FontUnderline(STUnderlineValues.Enum value){
- underline = value;
- }
/**
- * Returns index of this font family
- *
- * @return index of this font family
+ * Single-line underlining under each character in the cell.
+ * The underline is drawn through the descenders of
+ * characters such as g and p..
+ */
+ SINGLE(1),
+
+ /**
+ * Double-line underlining under each character in the
+ * cell. underlines are drawn through the descenders of
+ * characters such as g and p.
+ */
+ DOUBLE(2),
+
+ /**
+ * Single-line accounting underlining under each
+ * character in the cell. The underline is drawn under the
+ * descenders of characters such as g and p.
*/
- public STUnderlineValues.Enum getValue(){
- return underline;
+ SINGLE_ACCOUNTING(3),
+
+ /**
+ * Double-line accounting underlining under each
+ * character in the cell. The underlines are drawn under
+ * the descenders of characters such as g and p.
+ */
+ DOUBLE_ACCOUNTING(4),
+
+ /**
+ * No underline.
+ */
+ NONE(5);
+
+ private int value;
+
+
+ private FontUnderline(int val) {
+ value = val;
+ }
+
+ public int getValue() {
+ return value;
}
-
- public static FontUnderline valueOf(STUnderlineValues.Enum underline){
- switch (underline.intValue()) {
- case STUnderlineValues.INT_DOUBLE:
- return DOUBLE;
- case STUnderlineValues.INT_DOUBLE_ACCOUNTING:
- return DOUBLE_ACCOUNTING;
- case STUnderlineValues.INT_SINGLE:
- return SINGLE;
- case STUnderlineValues.INT_SINGLE_ACCOUNTING:
- return SINGLE_ACCOUNTING;
- case STUnderlineValues.INT_NONE:
- return NONE;
- }
- throw new RuntimeException("Underline value ["+ underline +"] not supported");
+
+ public byte getByteValue() {
+ switch (this) {
+ case DOUBLE:
+ return Font.U_DOUBLE;
+ case DOUBLE_ACCOUNTING:
+ return Font.U_DOUBLE_ACCOUNTING;
+ case SINGLE_ACCOUNTING:
+ return Font.U_SINGLE_ACCOUNTING;
+ case NONE:
+ return Font.U_NONE;
+ case SINGLE:
+ return Font.U_SINGLE;
+ default:
+ return Font.U_SINGLE;
+ }
}
-
-
+
+ private static FontUnderline[] _table = new FontUnderline[6];
+ static {
+ for (FontUnderline c : values()) {
+ _table[c.getValue()] = c;
+ }
+ }
+
+ public static FontUnderline valueOf(int value){
+ return _table[value];
+ }
+
+ public static FontUnderline valueOf(byte value){
+ FontUnderline val;
+ switch (value) {
+ case Font.U_DOUBLE:
+ val = FontUnderline.DOUBLE;
+ break;
+ case Font.U_DOUBLE_ACCOUNTING:
+ val = FontUnderline.DOUBLE_ACCOUNTING;
+ break;
+ case Font.U_SINGLE_ACCOUNTING:
+ val = FontUnderline.SINGLE_ACCOUNTING;
+ break;
+ case Font.U_SINGLE:
+ val = FontUnderline.SINGLE;
+ break;
+ default:
+ val = FontUnderline.NONE;
+ break;
+ }
+ return val;
+ }
+
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/IndexedColors.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/IndexedColors.java
index b61e62d5d9..45e6dd3bb1 100755
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/IndexedColors.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/IndexedColors.java
@@ -78,8 +78,7 @@ public enum IndexedColors {
PLUM(61),
INDIGO(62),
GREY_80_PERCENT(63),
- AUTOMATIC(64),
- ;
+ AUTOMATIC(64);
private int index;
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/PageOrder.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/PageOrder.java
index 3306d0680c..7aa7a90da1 100755
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/PageOrder.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/PageOrder.java
@@ -17,8 +17,6 @@
package org.apache.poi.xssf.usermodel;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPageOrder;
-
/**
* Specifies printed page order.
*
@@ -29,37 +27,33 @@ public enum PageOrder {
/**
* Order pages vertically first, then move horizontally.
*/
- DOWN_THEN_OVER(STPageOrder.DOWN_THEN_OVER),
+ DOWN_THEN_OVER(1),
/**
* Order pages horizontally first, then move vertically
*/
- OVER_THEN_DOWN(STPageOrder.OVER_THEN_DOWN);
+ OVER_THEN_DOWN(2);
- private STPageOrder.Enum order;
+ private int order;
- PageOrder(STPageOrder.Enum order) {
+ private PageOrder(int order) {
this.order = order;
}
- /**
- * Returns value of pages order
- *
- * @return String value of pages order
- */
- public STPageOrder.Enum getValue() {
+ public int getValue() {
return order;
}
- public static PageOrder valueOf(STPageOrder.Enum pageOrder) {
- switch (pageOrder.intValue()) {
- case STPageOrder.INT_DOWN_THEN_OVER:
- return DOWN_THEN_OVER;
- case STPageOrder.INT_OVER_THEN_DOWN:
- return OVER_THEN_DOWN;
+ private static PageOrder[] _table = new PageOrder[3];
+ static {
+ for (PageOrder c : values()) {
+ _table[c.getValue()] = c;
}
- throw new RuntimeException("PageOrder value [" + pageOrder + "] not supported");
+ }
+
+ public static PageOrder valueOf(int value){
+ return _table[value];
}
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/PaperSize.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/PaperSize.java
index d0a94f00db..359e0d7139 100755
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/PaperSize.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/PaperSize.java
@@ -40,5 +40,4 @@ public enum PaperSize {
QUARTO_PAPER,
STANDARD_PAPER_10_14,
STANDARD_PAPER_11_17;
-
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/PrintCellComments.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/PrintCellComments.java
index 822721085d..31c392be6a 100755
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/PrintCellComments.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/PrintCellComments.java
@@ -17,8 +17,6 @@
package org.apache.poi.xssf.usermodel;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellComments;
-
/**
* These enumerations specify how cell comments shall be displayed for paper printing purposes.
*
@@ -29,45 +27,35 @@ public enum PrintCellComments {
/**
* Do not print cell comments.
*/
- NONE(STCellComments.NONE),
+ NONE(1),
/**
* Print cell comments as displayed.
*/
- AS_DISPLAYED(STCellComments.AS_DISPLAYED),
+ AS_DISPLAYED(2),
/**
* Print cell comments at end of document.
*/
- AT_END(STCellComments.AT_END);
-
+ AT_END(3);
- private STCellComments.Enum comments;
+ private int comments;
- PrintCellComments(STCellComments.Enum comments) {
+ private PrintCellComments(int comments) {
this.comments = comments;
}
-
- /**
- * Returns comments of cell
- *
- * @return String comments of cell
- */
- public STCellComments.Enum getValue() {
+ public int getValue() {
return comments;
}
-
- public static PrintCellComments valueOf(STCellComments.Enum cellComment) {
- switch (cellComment.intValue()) {
- case STCellComments.INT_AS_DISPLAYED:
- return AS_DISPLAYED;
- case STCellComments.INT_AT_END:
- return AT_END;
- case STCellComments.INT_NONE:
- return NONE;
+ private static PrintCellComments[] _table = new PrintCellComments[4];
+ static {
+ for (PrintCellComments c : values()) {
+ _table[c.getValue()] = c;
}
- throw new RuntimeException("PrintCellComments: value [" + cellComment + "] not supported");
}
+ public static PrintCellComments valueOf(int value){
+ return _table[value];
+ }
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/PrintOrientation.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/PrintOrientation.java
index 3b65f3ed32..4215acd9e6 100755
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/PrintOrientation.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/PrintOrientation.java
@@ -17,8 +17,6 @@
package org.apache.poi.xssf.usermodel;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STOrientation;
-
/**
* The enumeration value indicating the print orientation for a sheet.
*
@@ -29,49 +27,37 @@ public enum PrintOrientation {
/**
* orientation not specified
*/
- DEFAULT(STOrientation.DEFAULT),
+ DEFAULT(1),
/**
* portrait orientation
*/
- PORTRAIT(STOrientation.PORTRAIT),
+ PORTRAIT(2),
/**
* landscape orientations
*/
- LANDSCAPE(STOrientation.LANDSCAPE);
-
+ LANDSCAPE(3);
- private STOrientation.Enum orientation;
+ private int orientation;
- PrintOrientation(STOrientation.Enum orientation) {
+ private PrintOrientation(int orientation) {
this.orientation = orientation;
}
- /**
- * Returns value of the orientation
- *
- * @return String value of the orientation
- */
- public STOrientation.Enum getValue() {
+ public int getValue() {
return orientation;
}
- public static PrintOrientation valueOf(STOrientation.Enum orient) {
- switch (orient.intValue()) {
- case STOrientation.INT_DEFAULT:
- return DEFAULT;
- case STOrientation.INT_LANDSCAPE:
- return LANDSCAPE;
- case STOrientation.INT_PORTRAIT:
- return PORTRAIT;
- /*
- default:
- return DEFAULT;
- */
+ private static PrintOrientation[] _table = new PrintOrientation[4];
+ static {
+ for (PrintOrientation c : values()) {
+ _table[c.getValue()] = c;
}
- throw new RuntimeException("Orientation value [" + orient + "] not supported");
}
+ public static PrintOrientation valueOf(int value){
+ return _table[value];
+ }
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
index 9d52a7fa55..8ac49b8443 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
@@ -36,6 +36,7 @@ import org.apache.poi.util.POILogFactory;
import org.apache.poi.util.POILogger;
import org.apache.poi.xssf.model.SharedStringSource;
import org.apache.poi.xssf.model.StylesTable;
+import org.apache.poi.xssf.model.SharedStringsTable;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType;
@@ -50,19 +51,11 @@ public final class XSSFCell implements Cell {
private final CTCell cell;
private final XSSFRow row;
private int cellNum;
- private SharedStringSource sharedStringSource;
+ private SharedStringsTable sharedStringSource;
private StylesTable stylesSource;
private POILogger logger = POILogFactory.getLogger(XSSFCell.class);
- /**
- * Create a new XSSFCell. This method is protected to be used only by
- * tests.
- */
- protected XSSFCell(XSSFRow row) {
- this(row, CTCell.Factory.newInstance());
- }
-
public XSSFCell(XSSFRow row, CTCell cell) {
this.cell = cell;
this.row = row;
@@ -70,10 +63,10 @@ public final class XSSFCell implements Cell {
this.cellNum = parseCellNum(cell.getR());
}
this.sharedStringSource = row.getSheet().getWorkbook().getSharedStringSource();
- this.stylesSource = (StylesTable)row.getSheet().getWorkbook().getStylesSource();
+ this.stylesSource = row.getSheet().getWorkbook().getStylesSource();
}
- protected SharedStringSource getSharedStringSource() {
+ protected SharedStringsTable getSharedStringSource() {
return this.sharedStringSource;
}
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDialogsheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDialogsheet.java
index 7ce6c000e2..b1f6246b6f 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDialogsheet.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFDialogsheet.java
@@ -19,18 +19,19 @@ package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.xmlbeans.XmlException;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
+import org.openxml4j.opc.PackagePart;
+import org.openxml4j.opc.PackageRelationship;
+
+import java.io.IOException;
public class XSSFDialogsheet extends XSSFSheet implements Sheet{
- public XSSFDialogsheet(CTSheet sheet, CTDialogsheet dialogsheet,
- XSSFWorkbook workbook) {
- super(sheet, CTWorksheet.Factory.newInstance(), workbook);
- this.worksheet = null;
- this.dialogsheet = dialogsheet;
- if (this.dialogsheet == null) {
- this.dialogsheet = CTDialogsheet.Factory.newInstance();
- }
+ public XSSFDialogsheet(XSSFSheet sheet) {
+ this.packagePart = sheet.getPackagePart();
+ this.packageRel = sheet.getPackageRelationship();
+ this.dialogsheet = CTDialogsheet.Factory.newInstance();
}
public XSSFRow createRow(int rowNum) {
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
index 0fe4861d69..976bf61178 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
@@ -21,17 +21,7 @@ import java.util.ArrayList;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.xssf.usermodel.extensions.XSSFColor;
import org.apache.poi.xssf.model.StylesTable;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontName;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontScheme;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontSize;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIntProperty;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTUnderlineProperty;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTVerticalAlignFontProperty;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
/**
* Represents a font used in a workbook.
@@ -106,7 +96,8 @@ public class XSSFFont implements Font {
*/
public byte getCharSet() {
CTIntProperty charset = ctFont.sizeOfCharsetArray() == 0 ? null : ctFont.getCharsetArray(0);
- return charset == null ? FontCharset.ANSI.getValue() : FontCharset.valueOf(charset.getVal()).getValue();
+ int val = charset == null ? FontCharset.ANSI.getValue() : FontCharset.valueOf(charset.getVal()).getValue();
+ return (byte)val;
}
@@ -247,23 +238,8 @@ public class XSSFFont implements Font {
public byte getUnderline() {
CTUnderlineProperty underline = ctFont.sizeOfUArray() == 0 ? null : ctFont.getUArray(0);
if (underline != null) {
- FontUnderline fontUnderline = FontUnderline.valueOf(underline.getVal());
- switch (fontUnderline.getValue().intValue()) {
- case STUnderlineValues.INT_DOUBLE:
- return Font.U_DOUBLE;
- case STUnderlineValues.INT_DOUBLE_ACCOUNTING:
- return Font.U_DOUBLE_ACCOUNTING;
-
- case STUnderlineValues.INT_SINGLE_ACCOUNTING:
- return Font.U_SINGLE_ACCOUNTING;
-
- case STUnderlineValues.INT_NONE:
- return Font.U_NONE;
-
- case STUnderlineValues.INT_SINGLE:
- default:
- return Font.U_SINGLE;
- }
+ FontUnderline val = FontUnderline.valueOf(underline.getVal().intValue());
+ return val.getByteValue();
}
return Font.U_NONE;
}
@@ -328,7 +304,7 @@ public class XSSFFont implements Font {
* @param charSet
*/
public void setCharSet(FontCharset charSet) {
- setCharSet(charSet.getValue());
+ setCharSet((byte)charSet.getValue());
}
/**
@@ -490,26 +466,7 @@ public class XSSFFont implements Font {
* @see FontUnderline
*/
public void setUnderline(byte underline) {
- if(underline == Font.U_NONE) {
- ctFont.setUArray(null);
- } else {
- CTUnderlineProperty ctUnderline = ctFont.sizeOfUArray() == 0 ? ctFont.addNewU() : ctFont.getUArray(0);
- switch (underline) {
- case Font.U_DOUBLE:
- ctUnderline.setVal(FontUnderline.DOUBLE.getValue());
- break;
- case Font.U_DOUBLE_ACCOUNTING:
- ctUnderline.setVal(FontUnderline.DOUBLE_ACCOUNTING.getValue());
- break;
- case Font.U_SINGLE_ACCOUNTING:
- ctUnderline.setVal(FontUnderline.SINGLE_ACCOUNTING.getValue());
- break;
- case Font.U_SINGLE:
- default:
- ctUnderline.setVal(FontUnderline.NONE.getValue());
- break;
- }
- }
+ setUnderline(FontUnderline.valueOf(underline));
}
/**
@@ -520,8 +477,13 @@ public class XSSFFont implements Font {
* @param underline - FontUnderline enum value
*/
public void setUnderline(FontUnderline underline) {
- CTUnderlineProperty ctUnderline = ctFont.sizeOfUArray() == 0 ? ctFont.addNewU() : ctFont.getUArray(0);
- ctUnderline.setVal(underline.getValue());
+ if(underline == FontUnderline.NONE && ctFont.sizeOfUArray() > 0){
+ ctFont.setUArray(null);
+ } else {
+ CTUnderlineProperty ctUnderline = ctFont.sizeOfUArray() == 0 ? ctFont.addNewU() : ctFont.getUArray(0);
+ STUnderlineValues.Enum val = STUnderlineValues.Enum.forInt(underline.getValue());
+ ctUnderline.setVal(val);
+ }
}
@@ -550,7 +512,7 @@ public class XSSFFont implements Font {
*/
public FontScheme getScheme() {
CTFontScheme scheme = ctFont.sizeOfSchemeArray() == 0 ? null : ctFont.getSchemeArray(0);
- return scheme == null ? FontScheme.NONE : FontScheme.valueOf(scheme.getVal());
+ return scheme == null ? FontScheme.NONE : FontScheme.valueOf(scheme.getVal().intValue());
}
/**
@@ -561,7 +523,8 @@ public class XSSFFont implements Font {
*/
public void setScheme(FontScheme scheme) {
CTFontScheme ctFontScheme = ctFont.sizeOfSchemeArray() == 0 ? ctFont.addNewScheme() : ctFont.getSchemeArray(0);
- ctFontScheme.setVal(scheme.getValue());
+ STFontScheme.Enum val = STFontScheme.Enum.forInt(scheme.getValue());
+ ctFontScheme.setVal(val);
}
/**
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java
index cbfe9c0f30..22f48f9407 100755
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFPrintSetup.java
@@ -18,9 +18,7 @@
package org.apache.poi.xssf.usermodel;
import org.apache.poi.ss.usermodel.PrintSetup;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetup;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
/**
@@ -34,22 +32,11 @@ public class XSSFPrintSetup implements PrintSetup {
public XSSFPrintSetup(CTWorksheet worksheet) {
- if (worksheet == null) throw new NullPointerException("");
this.ctWorksheet = worksheet;
this.pageSetup = ctWorksheet.getPageSetup() == null ? ctWorksheet.addNewPageSetup() : ctWorksheet.getPageSetup();
this.pageMargins = ctWorksheet.getPageMargins() == null ? ctWorksheet.addNewPageMargins() : ctWorksheet.getPageMargins();
}
- public XSSFPrintSetup(XSSFSheet sheet) {
- this(sheet.getWorksheet());
- }
-
- public XSSFPrintSetup(CTPageSetup pageSetup, CTPageMargins pageMargins) {
- this.pageMargins = pageMargins;
- this.pageSetup = pageSetup;
- }
-
-
/**
* Set the paper size.
*
@@ -164,8 +151,9 @@ public class XSSFPrintSetup implements PrintSetup {
* @param printnotes print the notes
*/
public void setNotes(boolean printnotes) {
- if (printnotes)
- pageSetup.setCellComments(PrintCellComments.AS_DISPLAYED.getValue());
+ if (printnotes){
+ pageSetup.setCellComments(STCellComments.AS_DISPLAYED);
+ }
}
/**
@@ -240,7 +228,8 @@ public class XSSFPrintSetup implements PrintSetup {
* @see PrintOrientation
*/
public void setOrientation(PrintOrientation orientation) {
- pageSetup.setOrientation(orientation.getValue());
+ STOrientation.Enum v = STOrientation.Enum.forInt(orientation.getValue());
+ pageSetup.setOrientation(v);
}
/**
@@ -250,12 +239,14 @@ public class XSSFPrintSetup implements PrintSetup {
* @see PrintOrientation
*/
public PrintOrientation getOrientation() {
- return (pageSetup.getOrientation() == null) ? null : PrintOrientation.valueOf(pageSetup.getOrientation());
+ STOrientation.Enum val = pageSetup.getOrientation();
+ return val == null ? PrintOrientation.DEFAULT : PrintOrientation.valueOf(val.intValue());
}
public PrintCellComments getCellComment() {
- return (pageSetup.getCellComments() == null) ? null : PrintCellComments.valueOf(pageSetup.getCellComments());
+ STCellComments.Enum val = pageSetup.getCellComments();
+ return val == null ? PrintCellComments.NONE : PrintCellComments.valueOf(val.intValue());
}
/**
@@ -264,7 +255,8 @@ public class XSSFPrintSetup implements PrintSetup {
* @param pageOrder
*/
public void setPageOrder(PageOrder pageOrder) {
- pageSetup.setPageOrder(pageOrder.getValue());
+ STPageOrder.Enum v = STPageOrder.Enum.forInt(pageOrder.getValue());
+ pageSetup.setPageOrder(v);
}
/**
@@ -273,7 +265,7 @@ public class XSSFPrintSetup implements PrintSetup {
* @return PageOrder
*/
public PageOrder getPageOrder() {
- return (pageSetup.getPageOrder() == null) ? null : PageOrder.valueOf(pageSetup.getPageOrder());
+ return (pageSetup.getPageOrder() == null) ? null : PageOrder.valueOf(pageSetup.getPageOrder().intValue());
}
/**
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
index e65224e72f..b938c1fac2 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
@@ -35,15 +35,7 @@ public class XSSFRow implements Row, Comparable {
private List<Cell> cells;
private XSSFSheet sheet;
-
- /**
- * Create a new XSSFRow. This method is protected to be used only by
- * tests.
- */
- protected XSSFRow(XSSFSheet sheet) {
- this(CTRow.Factory.newInstance(), sheet);
- }
-
+
/**
* Create a new XSSFRow.
*
@@ -75,29 +67,35 @@ public class XSSFRow implements Row, Comparable {
return cellIterator();
}
- public int compareTo(Object obj) {
- XSSFRow loc = (XSSFRow) obj;
- if (this.getRowNum() == loc.getRowNum())
- {
- return 0;
- }
- if (this.getRowNum() < loc.getRowNum())
- {
- return -1;
- }
- if (this.getRowNum() > loc.getRowNum())
- {
- return 1;
- }
- return -1;
+ /**
+ * Compares two <code>XSSFRow</code> objects.
+ *
+ * @param row the <code>XSSFRow</code> to be compared.
+ * @return the value <code>0</code> if the row number of this <code>XSSFRow</code> is
+ * equal to the row number of the argument <code>XSSFRow</code>; a value less than
+ * <code>0</code> if the row number of this this <code>XSSFRow</code> is numerically less
+ * than the row number of the argument <code>XSSFRow</code>; and a value greater
+ * than <code>0</code> if the row number of this this <code>XSSFRow</code> is numerically
+ * greater than the row number of the argument <code>XSSFRow</code>.
+ */
+ public int compareTo(Object row) {
+ int thisVal = this.getRowNum();
+ int anotherVal = ((XSSFRow)row).getRowNum();
+ return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0 : 1));
}
+ /**
+ * Use this to create new cells within the row and return it.
+ * <p>
+ * The cell that is returned is a CELL_TYPE_BLANK. The type can be changed
+ * either through calling <code>setCellValue</code> or <code>setCellType</code>.
+ *
+ * @param column - the column number this cell represents
+ * @return Cell a high level representation of the created cell.
+ */
public XSSFCell createCell(int column) {
return createCell(column, Cell.CELL_TYPE_BLANK);
}
- public XSSFCell createCell(short column) {
- return createCell((int)column);
- }
/**
* Add a new empty cell to this row.
@@ -117,19 +115,24 @@ public class XSSFRow implements Row, Comparable {
return xcell;
}
- public XSSFCell createCell(short column, int type) {
- return createCell((int)column, type);
- }
+ /**
+ * Use this to create new cells within the row and return it.
+ *
+ * @param column - the column number this cell represents
+ * @param type - the cell's data type
+ *
+ * @return XSSFCell a high level representation of the created cell.
+ */
public XSSFCell createCell(int column, int type) {
int index = 0;
for (Cell c : this.cells) {
- if (c.getCellNum() == column) {
+ if (c.getColumnIndex() == column) {
// Replace c with new Cell
XSSFCell xcell = addCell(column, index, type);
cells.set(index, xcell);
return xcell;
}
- if (c.getCellNum() > column) {
+ if (c.getColumnIndex() > column) {
XSSFCell xcell = addCell(column, index, type);
cells.add(index, xcell);
return xcell;
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
index e2632b7d17..b4c15b5d53 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
@@ -75,7 +75,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
protected List<Row> rows;
protected List<XSSFHyperlink> hyperlinks;
protected ColumnHelper columnHelper;
- protected CommentsSource sheetComments;
+ private CommentsSource sheetComments;
protected CTMergeCells ctMergeCells;
public static final short LeftMargin = 0;
@@ -97,27 +97,6 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
worksheet = WorksheetDocument.Factory.parse(part.getInputStream()).getWorksheet();
}
- public XSSFSheet(CTSheet sheet, CTWorksheet worksheet, XSSFWorkbook workbook, CommentsSource sheetComments) {
- super(null, null);
- this.parent = workbook;
- this.sheet = sheet;
- this.worksheet = worksheet;
- this.sheetComments = sheetComments;
-
- initialize();
- }
-
- public XSSFSheet(CTSheet sheet, CTWorksheet worksheet, XSSFWorkbook workbook) {
- this(sheet, worksheet, workbook, null);
- }
-
- protected XSSFSheet(XSSFWorkbook workbook) {
- super(null, null);
- this.parent = workbook;
-
- hyperlinks = new ArrayList<XSSFHyperlink>();
- }
-
/**
* Returns the parent XSSFWorkbook
*
@@ -326,7 +305,10 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
* need to assign it to a cell though
*/
public XSSFComment createComment() {
- return (XSSFComment)getComments().addComment();
+ if (sheetComments == null) {
+ sheetComments = (CommentsTable)createRelationship(XSSFRelation.SHEET_COMMENTS, XSSFFactory.getInstance(), (int)sheet.getSheetId());
+ }
+ return (XSSFComment)sheetComments.addComment();
}
protected XSSFRow addRow(int index, int rownum) {
@@ -394,7 +376,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
public XSSFComment getCellComment(int row, int column) {
if (sheetComments == null) return null;
- else return (XSSFComment)getComments().findCellComment(row, column);
+ else return (XSSFComment)sheetComments.findCellComment(row, column);
}
public XSSFHyperlink getHyperlink(int row, int column) {
@@ -1633,22 +1615,6 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
return views.getSheetViewArray(views.getSheetViewArray().length - 1);
}
- protected XSSFSheet cloneSheet() {
- XSSFSheet newSheet = new XSSFSheet(getWorkbook());
- newSheet.setSheet((CTSheet)sheet.copy());
- return newSheet;
- }
-
- private void setSheet(CTSheet sheet) {
- this.sheet = sheet;
- }
-
- private CommentsSource getComments() {
- if (sheetComments == null) {
- sheetComments = (CommentsTable)createRelationship(XSSFRelation.SHEET_COMMENTS, XSSFFactory.getInstance(), (int)sheet.getSheetId());
- }
- return sheetComments;
- }
/**
* Returns the sheet's comments object if there is one,
* or null if not
diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
index 5bed893990..3ac30559bb 100644
--- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
+++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
@@ -310,33 +310,26 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
public XSSFSheet cloneSheet(int sheetNum) {
XSSFSheet srcSheet = sheets.get(sheetNum);
String srcName = getSheetName(sheetNum);
- if (srcSheet != null) {
- XSSFSheet clonedSheet = srcSheet.cloneSheet();
-
- sheets.add(clonedSheet);
- CTSheet newcts = this.workbook.getSheets().addNewSheet();
- newcts.set(clonedSheet.getSheet());
-
- int i = 1;
- while (true) {
- //Try and find the next sheet name that is unique
- String name = srcName;
- String index = Integer.toString(i++);
- if (name.length() + index.length() + 2 < 31) {
- name = name + "("+index+")";
- } else {
- name = name.substring(0, 31 - index.length() - 2) + "(" +index + ")";
- }
+ int i = 1;
+ String name = srcName;
+ while (true) {
+ //Try and find the next sheet name that is unique
+ String index = Integer.toString(i++);
+ if (name.length() + index.length() + 2 < 31) {
+ name = name + "("+index+")";
+ } else {
+ name = name.substring(0, 31 - index.length() - 2) + "(" +index + ")";
+ }
- //If the sheet name is unique, then set it otherwise move on to the next number.
- if (getSheetIndex(name) == -1) {
- setSheetName(sheets.size() - 1, name);
- break;
- }
+ //If the sheet name is unique, then set it otherwise move on to the next number.
+ if (getSheetIndex(name) == -1) {
+ break;
}
- return clonedSheet;
}
- return null;
+
+ XSSFSheet clonedSheet = createSheet(name);
+ clonedSheet.worksheet.set(srcSheet.worksheet);
+ return clonedSheet;
}
/**
@@ -425,11 +418,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
return wrapper;
}
- protected XSSFSheet createDialogsheet(String sheetname, CTDialogsheet dialogsheet) {
- CTSheet sheet = addSheet(sheetname);
- XSSFDialogsheet wrapper = new XSSFDialogsheet(sheet, dialogsheet, this);
- this.sheets.add(wrapper);
- return wrapper;
+ protected XSSFDialogsheet createDialogsheet(String sheetname, CTDialogsheet dialogsheet) {
+ XSSFSheet sheet = createSheet(sheetname);
+ return new XSSFDialogsheet(sheet);
}
private CTSheet addSheet(String sheetname) {