mirror of https://github.com/apache/poi.git
more code cleanup and refactoring: (a) removed references to ooxml schemas from XSSF enums, they should not depend on ooxml-schemas.jar
(b) removed "for testing only" constructors, the goal is to have a single, maximum 2 constructors for objects inherited from POIXMLDocumentPart (c) more javadocs git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@706003 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6e94780280
commit
90afc5eb5c
|
@ -37,18 +37,6 @@ public interface Row extends Iterable<Cell> {
|
|||
*/
|
||||
Cell createCell(int column);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
Cell createCell(short column);
|
||||
|
||||
/**
|
||||
* Use this to create new cells within the row and return it.
|
||||
* <p>
|
||||
|
|
|
@ -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(){
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -81,17 +81,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
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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..
|
||||
*/
|
||||
public STUnderlineValues.Enum getValue(){
|
||||
return underline;
|
||||
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.
|
||||
*/
|
||||
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 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 int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -78,8 +78,7 @@ public enum IndexedColors {
|
|||
PLUM(61),
|
||||
INDIGO(62),
|
||||
GREY_80_PERCENT(63),
|
||||
AUTOMATIC(64),
|
||||
;
|
||||
AUTOMATIC(64);
|
||||
|
||||
private int index;
|
||||
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,5 +40,4 @@ public enum PaperSize {
|
|||
QUARTO_PAPER,
|
||||
STANDARD_PAPER_10_14,
|
||||
STANDARD_PAPER_11_17;
|
||||
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 + ")";
|
||||
}
|
||||
|
||||
//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;
|
||||
}
|
||||
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) {
|
||||
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) {
|
||||
|
|
|
@ -21,6 +21,7 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.poi.ss.usermodel.Cell;
|
||||
import org.apache.poi.ss.usermodel.Comment;
|
||||
|
@ -31,13 +32,11 @@ import org.apache.poi.xssf.usermodel.XSSFRichTextString;
|
|||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||
import org.apache.poi.POIXMLDocumentPart;
|
||||
import org.openxml4j.opc.Package;
|
||||
import org.openxml4j.opc.PackagePart;
|
||||
import org.openxml4j.opc.PackagingURIHelper;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCommentList;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRst;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
@ -48,9 +47,13 @@ public class TestCommentsTable extends TestCase {
|
|||
private static final String TEST_A1_TEXT = "test A1 text";
|
||||
private static final String TEST_AUTHOR = "test author";
|
||||
|
||||
public void testfindAuthor() {
|
||||
CTComments comments = CTComments.Factory.newInstance();
|
||||
CommentsTable sheetComments = new CommentsTable(comments);
|
||||
public void testfindAuthor() throws Exception {
|
||||
CommentsDocument doc = CommentsDocument.Factory.newInstance();
|
||||
doc.setComments(CTComments.Factory.newInstance());
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS);
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray()));
|
||||
|
||||
assertEquals(0, sheetComments.findAuthor(TEST_AUTHOR));
|
||||
assertEquals(1, sheetComments.findAuthor("another author"));
|
||||
|
@ -59,9 +62,16 @@ public class TestCommentsTable extends TestCase {
|
|||
assertEquals(1, sheetComments.findAuthor("another author"));
|
||||
}
|
||||
|
||||
public void testGetCellComment() {
|
||||
CTComments comments = CTComments.Factory.newInstance();
|
||||
CommentsTable sheetComments = new CommentsTable(comments);
|
||||
public void testGetCellComment() throws Exception {
|
||||
CommentsDocument doc = CommentsDocument.Factory.newInstance();
|
||||
doc.setComments(CTComments.Factory.newInstance());
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS);
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray()));
|
||||
|
||||
|
||||
CTComments comments = sheetComments.getCTComments();
|
||||
CTCommentList commentList = comments.addNewCommentList();
|
||||
|
||||
// Create 2 comments for A1 and A" cells
|
||||
|
@ -85,10 +95,15 @@ public class TestCommentsTable extends TestCase {
|
|||
assertNull(sheetComments.findCellComment(2, 0));
|
||||
}
|
||||
|
||||
public void testAddCellComment() {
|
||||
CTComments comments = CTComments.Factory.newInstance();
|
||||
CommentsTable sheetComments = new CommentsTable(comments);
|
||||
CTCommentList commentList = comments.addNewCommentList();
|
||||
public void testAddCellComment() throws Exception {
|
||||
CommentsDocument doc = CommentsDocument.Factory.newInstance();
|
||||
doc.setComments(CTComments.Factory.newInstance());
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS);
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray()));
|
||||
|
||||
CTCommentList commentList = sheetComments.getCTComments().addNewCommentList();
|
||||
assertEquals(0, commentList.sizeOfCommentArray());
|
||||
|
||||
XSSFComment comment = sheetComments.addComment();
|
||||
|
@ -114,11 +129,16 @@ public class TestCommentsTable extends TestCase {
|
|||
assertTrue(xml.exists());
|
||||
|
||||
Package pkg = Package.open(xml.toString());
|
||||
PackagePart cpart = pkg.getPart(
|
||||
PackagingURIHelper.createPartName("/xl/comments1.xml")
|
||||
);
|
||||
|
||||
CommentsTable ct = new CommentsTable(cpart.getInputStream());
|
||||
XSSFWorkbook wb = new XSSFWorkbook(pkg);
|
||||
List<POIXMLDocumentPart> rels = wb.getSheetAt(0).getRelations();
|
||||
CommentsTable ct = null;
|
||||
for(POIXMLDocumentPart p : rels) {
|
||||
if(p instanceof CommentsTable){
|
||||
ct = (CommentsTable)p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertNotNull(ct);
|
||||
assertEquals(2, ct.getNumberOfComments());
|
||||
assertEquals(1, ct.getNumberOfAuthors());
|
||||
|
||||
|
@ -126,13 +146,18 @@ public class TestCommentsTable extends TestCase {
|
|||
|
||||
assertEquals("Nick Burch", comment.getAuthor());
|
||||
assertEquals("Nick Burch:\nThis is a comment", comment.getString().getString());
|
||||
|
||||
// Re-serialise
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ct.writeTo(baos);
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
ct = new CommentsTable(bais);
|
||||
|
||||
|
||||
wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||
rels = wb.getSheetAt(0).getRelations();
|
||||
ct = null;
|
||||
for(POIXMLDocumentPart p : rels) {
|
||||
if(p instanceof CommentsTable){
|
||||
ct = (CommentsTable)p;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertNotNull(ct);
|
||||
|
||||
assertEquals(2, ct.getNumberOfComments());
|
||||
assertEquals(1, ct.getNumberOfAuthors());
|
||||
|
||||
|
@ -140,9 +165,7 @@ public class TestCommentsTable extends TestCase {
|
|||
|
||||
assertEquals("Nick Burch", comment.getAuthor());
|
||||
|
||||
// TODO: Fix this!
|
||||
// New line should still be there, but isn't!
|
||||
//assertEquals("Nick Burch:\nThis is a comment", comment.getString().getString());
|
||||
assertEquals("Nick Burch:\nThis is a comment", comment.getString().getString());
|
||||
}
|
||||
|
||||
public void testExisting() throws Exception {
|
||||
|
|
|
@ -111,17 +111,11 @@ public final class TestSharedStringsTable extends TestCase {
|
|||
|
||||
public void testReadWrite() {
|
||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx");
|
||||
SharedStringsTable sst1 = (SharedStringsTable)wb.getSharedStringSource();
|
||||
SharedStringsTable sst1 = wb.getSharedStringSource();
|
||||
|
||||
//serialize, read back and compare with the original
|
||||
SharedStringsTable sst2;
|
||||
try {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
sst1.writeTo(out);
|
||||
sst2 = new SharedStringsTable(new ByteArrayInputStream(out.toByteArray()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
SharedStringsTable sst2 = XSSFTestDataSamples.writeOutAndReadBack(wb).getSharedStringSource();
|
||||
|
||||
assertEquals(sst1.getCount(), sst2.getCount());
|
||||
assertEquals(sst1.getUniqueCount(), sst2.getUniqueCount());
|
||||
|
||||
|
|
|
@ -20,11 +20,10 @@ package org.apache.poi.xssf.model;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
|
||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
|
@ -50,19 +49,17 @@ public class TestStylesTable extends TestCase {
|
|||
}
|
||||
|
||||
public void testCreateSaveLoad() throws Exception {
|
||||
StylesTable st = new StylesTable();
|
||||
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
StylesTable st = wb.getStylesSource();
|
||||
|
||||
assertNotNull(st._getRawStylesheet());
|
||||
assertEquals(1, st._getXfsSize());
|
||||
assertEquals(1, st._getStyleXfsSize());
|
||||
assertEquals(0, st._getNumberFormatSize());
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
st.writeTo(baos);
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
st = new StylesTable(bais);
|
||||
|
||||
assertNotNull(st._getRawStylesheet());
|
||||
st = XSSFTestDataSamples.writeOutAndReadBack(wb).getStylesSource();
|
||||
|
||||
assertNotNull(st._getRawStylesheet());
|
||||
assertEquals(1, st._getXfsSize());
|
||||
assertEquals(1, st._getStyleXfsSize());
|
||||
assertEquals(0, st._getNumberFormatSize());
|
||||
|
@ -72,7 +69,7 @@ public class TestStylesTable extends TestCase {
|
|||
XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
|
||||
assertNotNull(workbook.getStylesSource());
|
||||
|
||||
StylesTable st = (StylesTable)workbook.getStylesSource();
|
||||
StylesTable st = workbook.getStylesSource();
|
||||
|
||||
doTestExisting(st);
|
||||
}
|
||||
|
@ -80,13 +77,10 @@ public class TestStylesTable extends TestCase {
|
|||
XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
|
||||
assertNotNull(workbook.getStylesSource());
|
||||
|
||||
StylesTable st = (StylesTable)workbook.getStylesSource();
|
||||
StylesTable st = workbook.getStylesSource();
|
||||
doTestExisting(st);
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
st.writeTo(baos);
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
st = new StylesTable(bais);
|
||||
st = XSSFTestDataSamples.writeOutAndReadBack(workbook).getStylesSource();
|
||||
doTestExisting(st);
|
||||
}
|
||||
public void doTestExisting(StylesTable st) throws Exception {
|
||||
|
@ -116,7 +110,8 @@ public class TestStylesTable extends TestCase {
|
|||
}
|
||||
|
||||
public void testPopulateNew() throws Exception {
|
||||
StylesTable st = new StylesTable();
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
StylesTable st = wb.getStylesSource();
|
||||
|
||||
assertNotNull(st._getRawStylesheet());
|
||||
assertEquals(1, st._getXfsSize());
|
||||
|
@ -130,11 +125,8 @@ public class TestStylesTable extends TestCase {
|
|||
st.putStyle(new XSSFCellStyle(st));
|
||||
|
||||
// Save and re-load
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
st.writeTo(baos);
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
st = new StylesTable(bais);
|
||||
|
||||
st = XSSFTestDataSamples.writeOutAndReadBack(wb).getStylesSource();
|
||||
|
||||
assertNotNull(st._getRawStylesheet());
|
||||
assertEquals(2, st._getXfsSize());
|
||||
assertEquals(1, st._getStyleXfsSize());
|
||||
|
@ -149,7 +141,7 @@ public class TestStylesTable extends TestCase {
|
|||
XSSFWorkbook workbook = new XSSFWorkbook(xml.toString());
|
||||
assertNotNull(workbook.getStylesSource());
|
||||
|
||||
StylesTable st = (StylesTable)workbook.getStylesSource();
|
||||
StylesTable st = workbook.getStylesSource();
|
||||
assertEquals(11, st._getXfsSize());
|
||||
assertEquals(1, st._getStyleXfsSize());
|
||||
assertEquals(8, st._getNumberFormatSize());
|
||||
|
@ -158,11 +150,8 @@ public class TestStylesTable extends TestCase {
|
|||
long nf2 = st.putNumberFormat("YYYY-mm-DD");
|
||||
assertEquals(nf1, st.putNumberFormat("YYYY-mm-dd"));
|
||||
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
st.writeTo(baos);
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
|
||||
st = new StylesTable(bais);
|
||||
|
||||
st = XSSFTestDataSamples.writeOutAndReadBack(workbook).getStylesSource();
|
||||
|
||||
assertEquals(11, st._getXfsSize());
|
||||
assertEquals(1, st._getStyleXfsSize());
|
||||
assertEquals(10, st._getNumberFormatSize());
|
||||
|
|
|
@ -59,7 +59,7 @@ public final class TestXSSFCell extends TestCase {
|
|||
*/
|
||||
public void testSetGetBoolean() throws Exception {
|
||||
XSSFRow row = createParentObjects();
|
||||
XSSFCell cell = new XSSFCell(row);
|
||||
XSSFCell cell = row.createCell(0);
|
||||
cell.setCellValue(true);
|
||||
assertEquals(Cell.CELL_TYPE_BOOLEAN, cell.getCellType());
|
||||
assertTrue(cell.getBooleanCellValue());
|
||||
|
@ -79,7 +79,7 @@ public final class TestXSSFCell extends TestCase {
|
|||
*/
|
||||
public void testSetGetNumeric() throws Exception {
|
||||
XSSFRow row = createParentObjects();
|
||||
XSSFCell cell = new XSSFCell(row);
|
||||
XSSFCell cell = row.createCell(0);
|
||||
cell.setCellValue(10d);
|
||||
assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
|
||||
assertEquals(10d, cell.getNumericCellValue());
|
||||
|
@ -92,7 +92,7 @@ public final class TestXSSFCell extends TestCase {
|
|||
*/
|
||||
public void testSetGetDate() throws Exception {
|
||||
XSSFRow row = createParentObjects();
|
||||
XSSFCell cell = new XSSFCell(row);
|
||||
XSSFCell cell = row.createCell(0);
|
||||
Date now = new Date();
|
||||
cell.setCellValue(now);
|
||||
assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType());
|
||||
|
@ -120,7 +120,7 @@ public final class TestXSSFCell extends TestCase {
|
|||
|
||||
public void testSetGetError() throws Exception {
|
||||
XSSFRow row = createParentObjects();
|
||||
XSSFCell cell = new XSSFCell(row);
|
||||
XSSFCell cell = row.createCell(0);
|
||||
|
||||
cell.setCellErrorValue((byte)0);
|
||||
assertEquals(Cell.CELL_TYPE_ERROR, cell.getCellType());
|
||||
|
@ -137,7 +137,7 @@ public final class TestXSSFCell extends TestCase {
|
|||
|
||||
public void testSetGetFormula() throws Exception {
|
||||
XSSFRow row = createParentObjects();
|
||||
XSSFCell cell = new XSSFCell(row);
|
||||
XSSFCell cell = row.createCell(0);
|
||||
String formula = "SQRT(C2^2+D2^2)";
|
||||
|
||||
cell.setCellFormula(formula);
|
||||
|
@ -174,7 +174,7 @@ public final class TestXSSFCell extends TestCase {
|
|||
|
||||
public void testSetGetStringShared() {
|
||||
XSSFRow row = createParentObjects();
|
||||
XSSFCell cell = new XSSFCell(row);
|
||||
XSSFCell cell = row.createCell(0);
|
||||
|
||||
cell.setCellValue(new XSSFRichTextString(""));
|
||||
assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType());
|
||||
|
@ -190,7 +190,7 @@ public final class TestXSSFCell extends TestCase {
|
|||
*/
|
||||
public void testGetEmptyCellValue() {
|
||||
XSSFRow row = createParentObjects();
|
||||
XSSFCell cell = new XSSFCell(row);
|
||||
XSSFCell cell = row.createCell(0);
|
||||
cell.setCellType(Cell.CELL_TYPE_BOOLEAN);
|
||||
assertFalse(cell.getBooleanCellValue());
|
||||
cell.setCellType(Cell.CELL_TYPE_NUMERIC);
|
||||
|
@ -214,7 +214,7 @@ public final class TestXSSFCell extends TestCase {
|
|||
public void testFormatPosition() {
|
||||
XSSFRow row = createParentObjects();
|
||||
row.setRowNum(0);
|
||||
XSSFCell cell = new XSSFCell(row);
|
||||
XSSFCell cell = row.createCell(0);
|
||||
cell.setCellNum((short) 0);
|
||||
assertEquals("A1", cell.formatPosition());
|
||||
cell.setCellNum((short) 25);
|
||||
|
@ -227,41 +227,20 @@ public final class TestXSSFCell extends TestCase {
|
|||
assertEquals("IV32768", cell.formatPosition());
|
||||
}
|
||||
|
||||
public static class DummySharedStringSource implements SharedStringSource {
|
||||
ArrayList<CTRst> strs = new ArrayList<CTRst>();
|
||||
public CTRst getEntryAt(int idx) {
|
||||
return strs.get(idx);
|
||||
}
|
||||
|
||||
public synchronized int addEntry(CTRst s) {
|
||||
if(strs.contains(s)) {
|
||||
return strs.indexOf(s);
|
||||
}
|
||||
strs.add(s);
|
||||
return strs.size() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetCellComment() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||
CTComments ctComments = CTComments.Factory.newInstance();
|
||||
CommentsTable sheetComments = new CommentsTable(ctComments);
|
||||
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, workbook, sheetComments);
|
||||
XSSFSheet sheet = workbook.createSheet();
|
||||
assertNotNull(sheet);
|
||||
|
||||
|
||||
XSSFComment comment = sheet.createComment();
|
||||
comment.setAuthor(TEST_C10_AUTHOR);
|
||||
sheet.setCellComment("C10", comment);
|
||||
|
||||
// Create C10 cell
|
||||
Row row = sheet.createRow(9);
|
||||
row.createCell(2);
|
||||
row.createCell(3);
|
||||
|
||||
|
||||
// Set a comment for C10 cell
|
||||
CTComment ctComment = ctComments.addNewCommentList().insertNewComment(0);
|
||||
ctComment.setRef("C10");
|
||||
ctComment.setAuthorId(sheetComments.findAuthor(TEST_C10_AUTHOR));
|
||||
|
||||
assertNotNull(sheet.getRow(9).getCell((short)2));
|
||||
assertNotNull(sheet.getRow(9).getCell((short)2).getCellComment());
|
||||
assertEquals(TEST_C10_AUTHOR, sheet.getRow(9).getCell((short)2).getCellComment().getAuthor());
|
||||
|
@ -270,41 +249,35 @@ public final class TestXSSFCell extends TestCase {
|
|||
|
||||
public void testSetCellComment() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||
CTComments ctComments = CTComments.Factory.newInstance();
|
||||
CommentsTable comments = new CommentsTable(ctComments);
|
||||
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, workbook, comments);
|
||||
XSSFSheet sheet = workbook.createSheet();
|
||||
assertNotNull(sheet);
|
||||
|
||||
|
||||
XSSFComment comment = sheet.createComment();
|
||||
comment.setAuthor(TEST_C10_AUTHOR);
|
||||
|
||||
CTWorksheet ctWorksheet = sheet.getWorksheet();
|
||||
|
||||
// Create C10 cell
|
||||
Row row = sheet.createRow(9);
|
||||
Cell cell = row.createCell(2);
|
||||
row.createCell(3);
|
||||
|
||||
// Create a comment
|
||||
Comment comment = comments.addComment();
|
||||
comment.setAuthor(TEST_C10_AUTHOR);
|
||||
|
||||
|
||||
// Set a comment for C10 cell
|
||||
cell.setCellComment(comment);
|
||||
|
||||
CTCell ctCell = ctWorksheet.getSheetData().getRowArray(0).getCArray(0);
|
||||
assertNotNull(ctCell);
|
||||
assertEquals("C10", ctCell.getR());
|
||||
long authorId = ctComments.getCommentList().getCommentArray(0).getAuthorId();
|
||||
assertEquals(TEST_C10_AUTHOR, comments.getAuthor(authorId));
|
||||
assertEquals(TEST_C10_AUTHOR, comment.getAuthor());
|
||||
}
|
||||
|
||||
public void testSetAsActiveCell() {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = workbook.createSheet();
|
||||
Cell cell = sheet.createRow(0).createCell((short)0);
|
||||
cell.setAsActiveCell();
|
||||
|
||||
assertEquals("A1", ctWorksheet.getSheetViews().getSheetViewArray(0).getSelectionArray(0).getActiveCell());
|
||||
assertEquals("A1", sheet.getWorksheet().getSheetViews().getSheetViewArray(0).getSelectionArray(0).getActiveCell());
|
||||
}
|
||||
|
||||
|
||||
|
@ -345,9 +318,8 @@ public final class TestXSSFCell extends TestCase {
|
|||
|
||||
private static XSSFRow createParentObjects() {
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
wb.setSharedStringSource(new SharedStringsTable());
|
||||
XSSFSheet sheet = new XSSFSheet(wb);
|
||||
XSSFRow row = new XSSFRow(sheet);
|
||||
XSSFSheet sheet = wb.createSheet();
|
||||
XSSFRow row = sheet.createRow(0);
|
||||
return row;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,155 +25,164 @@ import org.apache.poi.ss.usermodel.Row;
|
|||
import org.apache.poi.ss.util.CellReference;
|
||||
import org.apache.poi.xssf.model.CommentsTable;
|
||||
import org.apache.poi.xssf.XSSFTestDataSamples;
|
||||
import org.openxml4j.opc.Package;
|
||||
import org.apache.poi.POIXMLDocumentPart;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTAuthors;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CommentsDocument;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
||||
|
||||
public class TestXSSFComment extends TestCase {
|
||||
|
||||
private static final String TEST_RICHTEXTSTRING = "test richtextstring";
|
||||
private static final String TEST_AUTHOR = "test_author";
|
||||
|
||||
public void testConstructors() {
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
XSSFComment comment = sheetComments.addComment();
|
||||
assertNotNull(comment);
|
||||
|
||||
CTComment ctComment = CTComment.Factory.newInstance();
|
||||
XSSFComment comment2 = new XSSFComment(sheetComments, ctComment);
|
||||
assertNotNull(comment2);
|
||||
}
|
||||
|
||||
public void testGetColumn() {
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
CTComment ctComment = CTComment.Factory.newInstance();
|
||||
ctComment.setRef("A1");
|
||||
XSSFComment comment = new XSSFComment(sheetComments, ctComment);
|
||||
assertNotNull(comment);
|
||||
assertEquals(0, comment.getColumn());
|
||||
ctComment.setRef("C10");
|
||||
assertEquals(2, comment.getColumn());
|
||||
}
|
||||
|
||||
public void testGetRow() {
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
CTComment ctComment = CTComment.Factory.newInstance();
|
||||
ctComment.setRef("A1");
|
||||
XSSFComment comment = new XSSFComment(sheetComments, ctComment);
|
||||
assertNotNull(comment);
|
||||
assertEquals(0, comment.getRow());
|
||||
ctComment.setRef("C10");
|
||||
assertEquals(9, comment.getRow());
|
||||
}
|
||||
|
||||
public void testGetAuthor() {
|
||||
CTComments ctComments = CTComments.Factory.newInstance();
|
||||
CTComment ctComment = ctComments.addNewCommentList().addNewComment();
|
||||
CTAuthors ctAuthors = ctComments.addNewAuthors();
|
||||
ctAuthors.insertAuthor(0, TEST_AUTHOR);
|
||||
ctComment.setAuthorId(0);
|
||||
private static final String TEST_RICHTEXTSTRING = "test richtextstring";
|
||||
private static final String TEST_AUTHOR = "test_author";
|
||||
|
||||
CommentsTable sheetComments = new CommentsTable(ctComments);
|
||||
XSSFComment comment = new XSSFComment(sheetComments, ctComment);
|
||||
assertNotNull(comment);
|
||||
assertEquals(TEST_AUTHOR, comment.getAuthor());
|
||||
}
|
||||
|
||||
public void testSetColumn() {
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
CTComment ctComment = CTComment.Factory.newInstance();
|
||||
XSSFComment comment = new XSSFComment(sheetComments, ctComment);
|
||||
comment.setColumn((short)3);
|
||||
assertEquals(3, comment.getColumn());
|
||||
assertEquals(3, (new CellReference(ctComment.getRef()).getCol()));
|
||||
assertEquals("D1", ctComment.getRef());
|
||||
public void testConstructors() {
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
XSSFComment comment = sheetComments.addComment();
|
||||
assertNotNull(comment);
|
||||
|
||||
comment.setColumn((short)13);
|
||||
assertEquals(13, comment.getColumn());
|
||||
}
|
||||
|
||||
public void testSetRow() {
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
CTComment ctComment = CTComment.Factory.newInstance();
|
||||
XSSFComment comment = new XSSFComment(sheetComments, ctComment);
|
||||
comment.setRow(20);
|
||||
assertEquals(20, comment.getRow());
|
||||
assertEquals(20, (new CellReference(ctComment.getRef()).getRow()));
|
||||
assertEquals("A21", ctComment.getRef());
|
||||
CTComment ctComment = CTComment.Factory.newInstance();
|
||||
XSSFComment comment2 = new XSSFComment(sheetComments, ctComment);
|
||||
assertNotNull(comment2);
|
||||
}
|
||||
|
||||
comment.setRow(19);
|
||||
assertEquals(19, comment.getRow());
|
||||
}
|
||||
|
||||
public void testSetAuthor() {
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
CTComment ctComment = CTComment.Factory.newInstance();
|
||||
XSSFComment comment = new XSSFComment(sheetComments, ctComment);
|
||||
comment.setAuthor(TEST_AUTHOR);
|
||||
assertEquals(TEST_AUTHOR, comment.getAuthor());
|
||||
}
|
||||
|
||||
public void testSetString() {
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
CTComment ctComment = CTComment.Factory.newInstance();
|
||||
XSSFComment comment = new XSSFComment(sheetComments, ctComment);
|
||||
RichTextString richTextString = new HSSFRichTextString(TEST_RICHTEXTSTRING);
|
||||
comment.setString(richTextString);
|
||||
assertEquals(TEST_RICHTEXTSTRING, ctComment.getText().getT());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that we can add comments to a new
|
||||
* file, save, load, and still see them
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testCreateSave() throws Exception {
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
XSSFSheet s1 = wb.createSheet();
|
||||
Row r1 = s1.createRow(0);
|
||||
Cell r1c1 = r1.createCell(0);
|
||||
r1c1.setCellValue(2.2);
|
||||
|
||||
assertEquals(0, s1.getNumberOfComments());
|
||||
|
||||
Comment c1 = s1.createComment();
|
||||
c1.setAuthor("Author 1");
|
||||
c1.setString(new XSSFRichTextString("Comment 1"));
|
||||
r1c1.setCellComment(c1);
|
||||
|
||||
assertEquals(1, s1.getNumberOfComments());
|
||||
|
||||
// Save and re-load
|
||||
wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||
s1 = wb.getSheetAt(0);
|
||||
|
||||
assertEquals(1, s1.getNumberOfComments());
|
||||
assertNotNull(s1.getRow(0).getCell(0).getCellComment());
|
||||
assertEquals("Author 1", s1.getRow(0).getCell(0).getCellComment().getAuthor());
|
||||
assertEquals("Comment 1", s1.getRow(0).getCell(0).getCellComment().getString().getString());
|
||||
|
||||
// Now add an orphaned one
|
||||
Comment c2 = s1.createComment();
|
||||
c2.setAuthor("Author 2");
|
||||
c2.setString(new XSSFRichTextString("Second Comment"));
|
||||
c2.setRow(0);
|
||||
c2.setColumn((short)1);
|
||||
assertEquals(2, s1.getNumberOfComments());
|
||||
|
||||
// Save and re-load
|
||||
public void testGetColumn() {
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
CTComment ctComment = CTComment.Factory.newInstance();
|
||||
ctComment.setRef("A1");
|
||||
XSSFComment comment = new XSSFComment(sheetComments, ctComment);
|
||||
assertNotNull(comment);
|
||||
assertEquals(0, comment.getColumn());
|
||||
ctComment.setRef("C10");
|
||||
assertEquals(2, comment.getColumn());
|
||||
}
|
||||
|
||||
wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||
s1 = wb.getSheetAt(0);
|
||||
|
||||
assertEquals(2, s1.getNumberOfComments());
|
||||
assertNotNull(s1.getCellComment(0, 0));
|
||||
assertNotNull(s1.getCellComment(0, 1));
|
||||
|
||||
assertEquals("Author 1", s1.getCellComment(0, 0).getAuthor());
|
||||
assertEquals("Author 2", s1.getCellComment(0, 1).getAuthor());
|
||||
}
|
||||
public void testGetRow() {
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
CTComment ctComment = CTComment.Factory.newInstance();
|
||||
ctComment.setRef("A1");
|
||||
XSSFComment comment = new XSSFComment(sheetComments, ctComment);
|
||||
assertNotNull(comment);
|
||||
assertEquals(0, comment.getRow());
|
||||
ctComment.setRef("C10");
|
||||
assertEquals(9, comment.getRow());
|
||||
}
|
||||
|
||||
public void testGetAuthor() throws Exception {
|
||||
CommentsDocument doc = CommentsDocument.Factory.newInstance();
|
||||
CTComments ctComments = CTComments.Factory.newInstance();
|
||||
CTComment ctComment = ctComments.addNewCommentList().addNewComment();
|
||||
CTAuthors ctAuthors = ctComments.addNewAuthors();
|
||||
ctAuthors.insertAuthor(0, TEST_AUTHOR);
|
||||
ctComment.setAuthorId(0);
|
||||
doc.setComments(ctComments);
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
doc.save(out, POIXMLDocumentPart.DEFAULT_XML_OPTIONS);
|
||||
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
sheetComments.readFrom(new ByteArrayInputStream(out.toByteArray()));
|
||||
XSSFComment comment = new XSSFComment(sheetComments, ctComment);
|
||||
assertEquals(TEST_AUTHOR, comment.getAuthor());
|
||||
}
|
||||
|
||||
public void testSetColumn() {
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
CTComment ctComment = CTComment.Factory.newInstance();
|
||||
XSSFComment comment = new XSSFComment(sheetComments, ctComment);
|
||||
comment.setColumn((short)3);
|
||||
assertEquals(3, comment.getColumn());
|
||||
assertEquals(3, (new CellReference(ctComment.getRef()).getCol()));
|
||||
assertEquals("D1", ctComment.getRef());
|
||||
|
||||
comment.setColumn((short)13);
|
||||
assertEquals(13, comment.getColumn());
|
||||
}
|
||||
|
||||
public void testSetRow() {
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
CTComment ctComment = CTComment.Factory.newInstance();
|
||||
XSSFComment comment = new XSSFComment(sheetComments, ctComment);
|
||||
comment.setRow(20);
|
||||
assertEquals(20, comment.getRow());
|
||||
assertEquals(20, (new CellReference(ctComment.getRef()).getRow()));
|
||||
assertEquals("A21", ctComment.getRef());
|
||||
|
||||
comment.setRow(19);
|
||||
assertEquals(19, comment.getRow());
|
||||
}
|
||||
|
||||
public void testSetAuthor() {
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
CTComment ctComment = CTComment.Factory.newInstance();
|
||||
XSSFComment comment = new XSSFComment(sheetComments, ctComment);
|
||||
comment.setAuthor(TEST_AUTHOR);
|
||||
assertEquals(TEST_AUTHOR, comment.getAuthor());
|
||||
}
|
||||
|
||||
public void testSetString() {
|
||||
CommentsTable sheetComments = new CommentsTable();
|
||||
CTComment ctComment = CTComment.Factory.newInstance();
|
||||
XSSFComment comment = new XSSFComment(sheetComments, ctComment);
|
||||
RichTextString richTextString = new HSSFRichTextString(TEST_RICHTEXTSTRING);
|
||||
comment.setString(richTextString);
|
||||
assertEquals(TEST_RICHTEXTSTRING, ctComment.getText().getT());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that we can add comments to a new
|
||||
* file, save, load, and still see them
|
||||
* @throws Exception
|
||||
*/
|
||||
public void testCreateSave() throws Exception {
|
||||
XSSFWorkbook wb = new XSSFWorkbook();
|
||||
XSSFSheet s1 = wb.createSheet();
|
||||
Row r1 = s1.createRow(0);
|
||||
Cell r1c1 = r1.createCell(0);
|
||||
r1c1.setCellValue(2.2);
|
||||
|
||||
assertEquals(0, s1.getNumberOfComments());
|
||||
|
||||
Comment c1 = s1.createComment();
|
||||
c1.setAuthor("Author 1");
|
||||
c1.setString(new XSSFRichTextString("Comment 1"));
|
||||
r1c1.setCellComment(c1);
|
||||
|
||||
assertEquals(1, s1.getNumberOfComments());
|
||||
|
||||
// Save and re-load
|
||||
wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||
s1 = wb.getSheetAt(0);
|
||||
|
||||
assertEquals(1, s1.getNumberOfComments());
|
||||
assertNotNull(s1.getRow(0).getCell(0).getCellComment());
|
||||
assertEquals("Author 1", s1.getRow(0).getCell(0).getCellComment().getAuthor());
|
||||
assertEquals("Comment 1", s1.getRow(0).getCell(0).getCellComment().getString().getString());
|
||||
|
||||
// Now add an orphaned one
|
||||
Comment c2 = s1.createComment();
|
||||
c2.setAuthor("Author 2");
|
||||
c2.setString(new XSSFRichTextString("Second Comment"));
|
||||
c2.setRow(0);
|
||||
c2.setColumn((short)1);
|
||||
assertEquals(2, s1.getNumberOfComments());
|
||||
|
||||
// Save and re-load
|
||||
|
||||
wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||
s1 = wb.getSheetAt(0);
|
||||
|
||||
assertEquals(2, s1.getNumberOfComments());
|
||||
assertNotNull(s1.getCellComment(0, 0));
|
||||
assertNotNull(s1.getCellComment(0, 1));
|
||||
|
||||
assertEquals("Author 1", s1.getCellComment(0, 0).getAuthor());
|
||||
assertEquals("Author 2", s1.getCellComment(0, 1).getAuthor());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,15 +27,7 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
|||
|
||||
public class TestXSSFDialogSheet extends TestCase {
|
||||
|
||||
public void testDialogsheetConstructor() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("Sheet 1");
|
||||
XSSFDialogsheet dialogsheet = new XSSFDialogsheet(CTSheet.Factory.newInstance(), CTDialogsheet.Factory.newInstance(), workbook);
|
||||
assertNotNull(dialogsheet);
|
||||
XSSFDialogsheet dialogsheet2 = new XSSFDialogsheet(CTSheet.Factory.newInstance(), null, workbook);
|
||||
assertNotNull(dialogsheet2);
|
||||
}
|
||||
|
||||
|
||||
public void testCreateDialogSheet() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
Sheet dialogsheet = workbook.createDialogsheet("Dialogsheet 1", CTDialogsheet.Factory.newInstance());
|
||||
|
|
|
@ -19,191 +19,188 @@ package org.apache.poi.xssf.usermodel;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetup;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellComments;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STOrientation;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPageOrder;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
||||
|
||||
/**
|
||||
* Tests for {@link XSSFPrintSetup}
|
||||
*
|
||||
*/
|
||||
public class TestXSSFPrintSetup extends TestCase {
|
||||
|
||||
|
||||
public void testConstructor(){
|
||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
|
||||
CTPageMargins pMargins=CTPageMargins.Factory.newInstance();
|
||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, pMargins);
|
||||
assertNotNull(printSetup);
|
||||
|
||||
XSSFWorkbook wb=new XSSFWorkbook();
|
||||
printSetup=new XSSFPrintSetup(wb.createSheet());
|
||||
assertNotNull(printSetup);
|
||||
}
|
||||
|
||||
public void testSetGetPaperSize() {
|
||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
|
||||
pSetup.setPaperSize(9);
|
||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
|
||||
assertEquals(PaperSize.A4_PAPER,printSetup.getPaperSizeEnum());
|
||||
assertEquals(9,printSetup.getPaperSize());
|
||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||
CTPageSetup pSetup = worksheet.addNewPageSetup();
|
||||
pSetup.setPaperSize(9);
|
||||
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
|
||||
assertEquals(PaperSize.A4_PAPER, printSetup.getPaperSizeEnum());
|
||||
assertEquals(9, printSetup.getPaperSize());
|
||||
|
||||
printSetup.setPaperSize(PaperSize.A3_PAPER);
|
||||
assertEquals(8,pSetup.getPaperSize());
|
||||
printSetup.setPaperSize(PaperSize.A3_PAPER);
|
||||
assertEquals(8, pSetup.getPaperSize());
|
||||
}
|
||||
|
||||
|
||||
public void testSetGetScale() {
|
||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
|
||||
pSetup.setScale(9);
|
||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
|
||||
assertEquals(9,printSetup.getScale());
|
||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||
CTPageSetup pSetup = worksheet.addNewPageSetup();
|
||||
pSetup.setScale(9);
|
||||
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
|
||||
assertEquals(9, printSetup.getScale());
|
||||
|
||||
printSetup.setScale((short)100);
|
||||
assertEquals(100,pSetup.getScale());
|
||||
printSetup.setScale((short) 100);
|
||||
assertEquals(100, pSetup.getScale());
|
||||
}
|
||||
|
||||
public void testSetGetPageStart() {
|
||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
|
||||
pSetup.setFirstPageNumber(9);
|
||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
|
||||
assertEquals(9,printSetup.getPageStart());
|
||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||
CTPageSetup pSetup = worksheet.addNewPageSetup();
|
||||
pSetup.setFirstPageNumber(9);
|
||||
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
|
||||
assertEquals(9, printSetup.getPageStart());
|
||||
|
||||
printSetup.setPageStart((short)1);
|
||||
assertEquals(1,pSetup.getFirstPageNumber());
|
||||
printSetup.setPageStart((short) 1);
|
||||
assertEquals(1, pSetup.getFirstPageNumber());
|
||||
}
|
||||
|
||||
|
||||
public void testSetGetFitWidthHeight() {
|
||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
|
||||
pSetup.setFitToWidth(50);
|
||||
pSetup.setFitToHeight(99);
|
||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
|
||||
assertEquals(50,printSetup.getFitWidth());
|
||||
assertEquals(99,printSetup.getFitHeight());
|
||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||
CTPageSetup pSetup = worksheet.addNewPageSetup();
|
||||
pSetup.setFitToWidth(50);
|
||||
pSetup.setFitToHeight(99);
|
||||
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
|
||||
assertEquals(50, printSetup.getFitWidth());
|
||||
assertEquals(99, printSetup.getFitHeight());
|
||||
|
||||
printSetup.setFitWidth((short)66);
|
||||
printSetup.setFitHeight((short)80);
|
||||
assertEquals(66,pSetup.getFitToWidth());
|
||||
assertEquals(80,pSetup.getFitToHeight());
|
||||
printSetup.setFitWidth((short) 66);
|
||||
printSetup.setFitHeight((short) 80);
|
||||
assertEquals(66, pSetup.getFitToWidth());
|
||||
assertEquals(80, pSetup.getFitToHeight());
|
||||
|
||||
}
|
||||
|
||||
public void testSetGetLeftToRight() {
|
||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
|
||||
pSetup.setPageOrder(STPageOrder.DOWN_THEN_OVER);
|
||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
|
||||
assertEquals(false,printSetup.getLeftToRight());
|
||||
|
||||
printSetup.setLeftToRight(true);
|
||||
assertEquals(PageOrder.OVER_THEN_DOWN.getValue(),pSetup.getPageOrder());
|
||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||
CTPageSetup pSetup = worksheet.addNewPageSetup();
|
||||
pSetup.setPageOrder(STPageOrder.DOWN_THEN_OVER);
|
||||
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
|
||||
assertEquals(false, printSetup.getLeftToRight());
|
||||
|
||||
printSetup.setLeftToRight(true);
|
||||
assertEquals(PageOrder.OVER_THEN_DOWN.getValue(), pSetup.getPageOrder().intValue());
|
||||
}
|
||||
|
||||
public void testSetGetOrientation() {
|
||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
|
||||
pSetup.setOrientation(STOrientation.PORTRAIT);
|
||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
|
||||
assertEquals(PrintOrientation.PORTRAIT,printSetup.getOrientation());
|
||||
assertEquals(false,printSetup.getLandscape());
|
||||
assertEquals(false,printSetup.getNoOrientation());
|
||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||
CTPageSetup pSetup = worksheet.addNewPageSetup();
|
||||
pSetup.setOrientation(STOrientation.PORTRAIT);
|
||||
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
|
||||
assertEquals(PrintOrientation.PORTRAIT, printSetup.getOrientation());
|
||||
assertEquals(false, printSetup.getLandscape());
|
||||
assertEquals(false, printSetup.getNoOrientation());
|
||||
|
||||
printSetup.setOrientation(PrintOrientation.LANDSCAPE);
|
||||
assertEquals(pSetup.getOrientation(),printSetup.getOrientation().getValue());
|
||||
assertEquals(true,printSetup.getLandscape());
|
||||
assertEquals(false,printSetup.getNoOrientation());
|
||||
printSetup.setOrientation(PrintOrientation.LANDSCAPE);
|
||||
assertEquals(pSetup.getOrientation().intValue(), printSetup.getOrientation().getValue());
|
||||
assertEquals(true, printSetup.getLandscape());
|
||||
assertEquals(false, printSetup.getNoOrientation());
|
||||
}
|
||||
|
||||
|
||||
public void testSetGetValidSettings() {
|
||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
|
||||
pSetup.setUsePrinterDefaults(false);
|
||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
|
||||
assertEquals(false,printSetup.getValidSettings());
|
||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||
CTPageSetup pSetup = worksheet.addNewPageSetup();
|
||||
pSetup.setUsePrinterDefaults(false);
|
||||
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
|
||||
assertEquals(false, printSetup.getValidSettings());
|
||||
|
||||
printSetup.setValidSettings(true);
|
||||
assertEquals(true,pSetup.getUsePrinterDefaults());
|
||||
printSetup.setValidSettings(true);
|
||||
assertEquals(true, pSetup.getUsePrinterDefaults());
|
||||
}
|
||||
|
||||
public void testSetGetNoColor() {
|
||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
|
||||
pSetup.setBlackAndWhite(false);
|
||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
|
||||
assertEquals(false,printSetup.getNoColor());
|
||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||
CTPageSetup pSetup = worksheet.addNewPageSetup();
|
||||
pSetup.setBlackAndWhite(false);
|
||||
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
|
||||
assertEquals(false, printSetup.getNoColor());
|
||||
|
||||
printSetup.setNoColor(true);
|
||||
assertEquals(true,pSetup.getBlackAndWhite());
|
||||
printSetup.setNoColor(true);
|
||||
assertEquals(true, pSetup.getBlackAndWhite());
|
||||
}
|
||||
|
||||
public void testSetGetDraft() {
|
||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
|
||||
pSetup.setDraft(false);
|
||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
|
||||
assertEquals(false,printSetup.getDraft());
|
||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||
CTPageSetup pSetup = worksheet.addNewPageSetup();
|
||||
pSetup.setDraft(false);
|
||||
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
|
||||
assertEquals(false, printSetup.getDraft());
|
||||
|
||||
printSetup.setDraft(true);
|
||||
assertEquals(true,pSetup.getDraft());
|
||||
printSetup.setDraft(true);
|
||||
assertEquals(true, pSetup.getDraft());
|
||||
}
|
||||
|
||||
public void testSetGetNotes() {
|
||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
|
||||
pSetup.setCellComments(STCellComments.NONE);
|
||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
|
||||
assertEquals(false,printSetup.getNotes());
|
||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||
CTPageSetup pSetup = worksheet.addNewPageSetup();
|
||||
pSetup.setCellComments(STCellComments.NONE);
|
||||
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
|
||||
assertEquals(false, printSetup.getNotes());
|
||||
|
||||
printSetup.setNotes(true);
|
||||
assertEquals(PrintCellComments.AS_DISPLAYED.getValue(),pSetup.getCellComments());
|
||||
printSetup.setNotes(true);
|
||||
assertEquals(PrintCellComments.AS_DISPLAYED.getValue(), pSetup.getCellComments().intValue());
|
||||
}
|
||||
|
||||
|
||||
public void testSetGetUsePage() {
|
||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
|
||||
pSetup.setUseFirstPageNumber(false);
|
||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
|
||||
assertEquals(false,printSetup.getUsePage());
|
||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||
CTPageSetup pSetup = worksheet.addNewPageSetup();
|
||||
pSetup.setUseFirstPageNumber(false);
|
||||
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
|
||||
assertEquals(false, printSetup.getUsePage());
|
||||
|
||||
printSetup.setUsePage(true);
|
||||
assertEquals(true,pSetup.getUseFirstPageNumber());
|
||||
printSetup.setUsePage(true);
|
||||
assertEquals(true, pSetup.getUseFirstPageNumber());
|
||||
}
|
||||
|
||||
public void testSetGetHVResolution() {
|
||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
|
||||
pSetup.setHorizontalDpi(120);
|
||||
pSetup.setVerticalDpi(100);
|
||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
|
||||
assertEquals(120,printSetup.getHResolution());
|
||||
assertEquals(100,printSetup.getVResolution());
|
||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||
CTPageSetup pSetup = worksheet.addNewPageSetup();
|
||||
pSetup.setHorizontalDpi(120);
|
||||
pSetup.setVerticalDpi(100);
|
||||
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
|
||||
assertEquals(120, printSetup.getHResolution());
|
||||
assertEquals(100, printSetup.getVResolution());
|
||||
|
||||
printSetup.setHResolution((short)150);
|
||||
printSetup.setVResolution((short)130);
|
||||
assertEquals(150,pSetup.getHorizontalDpi());
|
||||
assertEquals(130,pSetup.getVerticalDpi());
|
||||
printSetup.setHResolution((short) 150);
|
||||
printSetup.setVResolution((short) 130);
|
||||
assertEquals(150, pSetup.getHorizontalDpi());
|
||||
assertEquals(130, pSetup.getVerticalDpi());
|
||||
}
|
||||
|
||||
public void testSetGetHeaderFooterMargin() {
|
||||
CTPageMargins pMargins=CTPageMargins.Factory.newInstance();
|
||||
pMargins.setHeader(1.5);
|
||||
pMargins.setFooter(2);
|
||||
XSSFPrintSetup printSetup=new XSSFPrintSetup( null, pMargins);
|
||||
assertEquals(1.5,printSetup.getHeaderMargin());
|
||||
assertEquals(2.0,printSetup.getFooterMargin());
|
||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||
CTPageMargins pMargins = worksheet.addNewPageMargins();
|
||||
pMargins.setHeader(1.5);
|
||||
pMargins.setFooter(2);
|
||||
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
|
||||
assertEquals(1.5, printSetup.getHeaderMargin());
|
||||
assertEquals(2.0, printSetup.getFooterMargin());
|
||||
|
||||
printSetup.setHeaderMargin(5);
|
||||
printSetup.setFooterMargin(3.5);
|
||||
assertEquals(5.0,pMargins.getHeader());
|
||||
assertEquals(3.5,pMargins.getFooter());
|
||||
printSetup.setHeaderMargin(5);
|
||||
printSetup.setFooterMargin(3.5);
|
||||
assertEquals(5.0, pMargins.getHeader());
|
||||
assertEquals(3.5, pMargins.getFooter());
|
||||
}
|
||||
|
||||
public void testSetGetCopies() {
|
||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance();
|
||||
pSetup.setCopies(9);
|
||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null);
|
||||
assertEquals(9,printSetup.getCopies());
|
||||
CTWorksheet worksheet = CTWorksheet.Factory.newInstance();
|
||||
CTPageSetup pSetup = worksheet.addNewPageSetup();
|
||||
pSetup.setCopies(9);
|
||||
XSSFPrintSetup printSetup = new XSSFPrintSetup(worksheet);
|
||||
assertEquals(9, printSetup.getCopies());
|
||||
|
||||
printSetup.setCopies((short)15);
|
||||
assertEquals(15,pSetup.getCopies());
|
||||
printSetup.setCopies((short) 15);
|
||||
assertEquals(15, pSetup.getCopies());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -43,7 +43,8 @@ public final class TestXSSFRow extends TestCase {
|
|||
* Test adding cells to a row in various places and see if we can find them again.
|
||||
*/
|
||||
public void testAddAndIterateCells() {
|
||||
XSSFRow row = new XSSFRow(createParentObjects());
|
||||
XSSFSheet sheet = createParentObjects();
|
||||
XSSFRow row = sheet.createRow(0);
|
||||
|
||||
// One cell at the beginning
|
||||
Cell cell1 = row.createCell((short) 1);
|
||||
|
@ -125,7 +126,8 @@ public final class TestXSSFRow extends TestCase {
|
|||
assertFalse(row.getFirstCellNum() == (short) 2);
|
||||
|
||||
// Test a row without cells
|
||||
XSSFRow emptyRow = new XSSFRow(createParentObjects());
|
||||
XSSFSheet sheet = createParentObjects();
|
||||
XSSFRow emptyRow = sheet.createRow(0);
|
||||
assertEquals(-1, emptyRow.getFirstCellNum());
|
||||
}
|
||||
|
||||
|
@ -155,7 +157,8 @@ public final class TestXSSFRow extends TestCase {
|
|||
* Tests for the missing/blank cell policy stuff
|
||||
*/
|
||||
public void testGetCellPolicy() throws Exception {
|
||||
XSSFRow row = new XSSFRow(createParentObjects());
|
||||
XSSFSheet sheet = createParentObjects();
|
||||
XSSFRow row = sheet.createRow(0);
|
||||
|
||||
// 0 -> string
|
||||
// 1 -> num
|
||||
|
@ -214,7 +217,8 @@ public final class TestXSSFRow extends TestCase {
|
|||
* @return row
|
||||
*/
|
||||
private static XSSFRow getSampleRow() {
|
||||
XSSFRow row = new XSSFRow(createParentObjects());
|
||||
XSSFSheet sheet = createParentObjects();
|
||||
XSSFRow row = sheet.createRow(0);
|
||||
row.createCell((short) 2);
|
||||
row.createCell((short) 3, Cell.CELL_TYPE_NUMERIC);
|
||||
row.createCell((short) 4);
|
||||
|
|
|
@ -35,7 +35,6 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
|
|||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
|
||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane;
|
||||
|
@ -284,7 +283,7 @@ public class TestXSSFSheet extends TestCase {
|
|||
|
||||
public void testGetFooter() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = (XSSFSheet)workbook.createSheet("Sheet 1");
|
||||
XSSFSheet sheet = workbook.createSheet("Sheet 1");
|
||||
assertNotNull(sheet.getFooter());
|
||||
sheet.getFooter().setCenter("test center footer");
|
||||
assertEquals("test center footer", sheet.getFooter().getCenter());
|
||||
|
@ -610,31 +609,25 @@ public class TestXSSFSheet extends TestCase {
|
|||
|
||||
public void testGetCellComment() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||
CTComments ctComments = CTComments.Factory.newInstance();
|
||||
CommentsTable sheetComments = new CommentsTable(ctComments);
|
||||
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, workbook, sheetComments);
|
||||
assertNotNull(sheet);
|
||||
|
||||
CTComment ctComment = ctComments.addNewCommentList().insertNewComment(0);
|
||||
ctComment.setRef("C10");
|
||||
ctComment.setAuthorId(sheetComments.findAuthor("test C10 author"));
|
||||
|
||||
XSSFSheet sheet = workbook.createSheet();
|
||||
XSSFComment comment = sheet.createComment();
|
||||
comment.setAuthor("test C10 author");
|
||||
sheet.setCellComment("C10", comment);
|
||||
|
||||
assertNotNull(sheet.getCellComment(9, 2));
|
||||
assertEquals("test C10 author", sheet.getCellComment(9, 2).getAuthor());
|
||||
}
|
||||
|
||||
public void testSetCellComment() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, workbook);
|
||||
XSSFSheet sheet = workbook.createSheet();
|
||||
|
||||
XSSFComment comment = sheet.createComment();
|
||||
|
||||
Cell cell = sheet.createRow(0).createCell((short)0);
|
||||
CTComments ctComments = CTComments.Factory.newInstance();
|
||||
CommentsTable comments = new CommentsTable(ctComments);
|
||||
XSSFComment comment = comments.addComment();
|
||||
|
||||
CommentsTable comments = (CommentsTable)sheet.getCommentsSourceIfExists();
|
||||
CTComments ctComments = comments.getCTComments();
|
||||
|
||||
sheet.setCellComment("A1", comment);
|
||||
assertEquals("A1", ctComments.getCommentList().getCommentArray(0).getRef());
|
||||
comment.setAuthor("test A1 author");
|
||||
|
@ -651,10 +644,10 @@ public class TestXSSFSheet extends TestCase {
|
|||
}
|
||||
|
||||
public void testCreateFreezePane() {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = workbook.createSheet();
|
||||
CTWorksheet ctWorksheet = sheet.getWorksheet();
|
||||
|
||||
sheet.createFreezePane(2, 4);
|
||||
assertEquals((double)2, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getXSplit());
|
||||
assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane());
|
||||
|
@ -668,20 +661,17 @@ public class TestXSSFSheet extends TestCase {
|
|||
}
|
||||
|
||||
public void testNewMergedRegionAt() {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = workbook.createSheet();
|
||||
Region region = new Region("B2:D4");
|
||||
sheet.addMergedRegion(region);
|
||||
assertEquals("B2:D4", sheet.getMergedRegionAt(0).getRegionRef());
|
||||
}
|
||||
|
||||
public void testGetNumMergedRegions() {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = workbook.createSheet();
|
||||
CTWorksheet ctWorksheet = sheet.getWorksheet();
|
||||
assertEquals(0, sheet.getNumMergedRegions());
|
||||
Region region = new Region("B2:D4");
|
||||
sheet.addMergedRegion(region);
|
||||
|
@ -689,10 +679,9 @@ public class TestXSSFSheet extends TestCase {
|
|||
}
|
||||
|
||||
public void testRemoveMergedRegion() {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
|
||||
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");
|
||||
|
@ -710,11 +699,10 @@ public class TestXSSFSheet extends TestCase {
|
|||
}
|
||||
|
||||
public void testSetDefaultColumnStyle() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
|
||||
StylesTable stylesTable = (StylesTable) workbook.getStylesSource();
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = workbook.createSheet();
|
||||
CTWorksheet ctWorksheet = sheet.getWorksheet();
|
||||
StylesTable stylesTable = workbook.getStylesSource();
|
||||
XSSFFont font = new XSSFFont();
|
||||
font.setFontName("Cambria");
|
||||
stylesTable.putFont(font);
|
||||
|
@ -766,10 +754,8 @@ public class TestXSSFSheet extends TestCase {
|
|||
|
||||
|
||||
public void testGroupUngroupColumn() {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = workbook.createSheet();
|
||||
|
||||
//one level
|
||||
sheet.groupColumn((short)2,(short)7);
|
||||
|
@ -811,10 +797,8 @@ public class TestXSSFSheet extends TestCase {
|
|||
|
||||
|
||||
public void testGroupUngroupRow() {
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, (XSSFWorkbook) workbook);
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
XSSFSheet sheet = workbook.createSheet();
|
||||
|
||||
//one level
|
||||
sheet.groupRow(9,10);
|
||||
|
|
|
@ -259,9 +259,8 @@ public final class TestColumnHelper extends TestCase {
|
|||
|
||||
public void testGetSetColDefaultStyle() {
|
||||
XSSFWorkbook workbook = new XSSFWorkbook();
|
||||
CTSheet ctSheet = CTSheet.Factory.newInstance();
|
||||
CTWorksheet ctWorksheet = CTWorksheet.Factory.newInstance();
|
||||
XSSFSheet sheet = new XSSFSheet(ctSheet, ctWorksheet, workbook);
|
||||
XSSFSheet sheet = workbook.createSheet();
|
||||
CTWorksheet ctWorksheet = sheet.getWorksheet();
|
||||
ColumnHelper columnHelper = sheet.getColumnHelper();
|
||||
|
||||
// POI column 3, OOXML column 4
|
||||
|
|
Loading…
Reference in New Issue