(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-ffa450edef68tags/ooxml_20081107
*/ | */ | ||||
Cell createCell(int column); | 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. | * Use this to create new cells within the row and return it. | ||||
* <p> | * <p> |
doc.packageRel = rel; | doc.packageRel = rel; | ||||
doc.packagePart = part; | doc.packagePart = part; | ||||
doc.parent = this; | doc.parent = this; | ||||
doc.onDocumentCreate(); | |||||
addRelation(doc); | addRelation(doc); | ||||
return doc; | return doc; | ||||
} catch (Exception e){ | } catch (Exception e){ | ||||
} | } | ||||
POIXMLDocumentPart childPart = factory.createDocumentPart(rel, p); | POIXMLDocumentPart childPart = factory.createDocumentPart(rel, p); | ||||
childPart.parent = this; | childPart.parent = this; | ||||
childPart.onDocumentRead(); | |||||
addRelation(childPart); | addRelation(childPart); | ||||
if(p.hasRelationships()) childPart.read(factory); | if(p.hasRelationships()) childPart.read(factory); | ||||
} | } | ||||
} | } | ||||
/** | |||||
* Fired when a new package part is created | |||||
*/ | |||||
public void onDocumentCreate(){ | |||||
} | |||||
/** | |||||
* Fired when a package part is read | |||||
*/ | |||||
public void onDocumentRead(){ | |||||
} | |||||
} | } |
* shared strings. | * shared strings. | ||||
*/ | */ | ||||
public SharedStringsTable getSharedStringsTable() throws IOException, InvalidFormatException { | 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); | |||||
} | } | ||||
/** | /** | ||||
* returns a handy object for working with cell styles | * returns a handy object for working with cell styles | ||||
*/ | */ | ||||
public StylesTable getStylesTable() throws IOException, InvalidFormatException { | 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); | |||||
} | } | ||||
import org.openxml4j.opc.PackageRelationship; | import org.openxml4j.opc.PackageRelationship; | ||||
public class CommentsTable extends POIXMLDocumentPart implements CommentsSource { | 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() { | public CommentsTable() { | ||||
super(null, null); | super(null, null); | ||||
comments = CTComments.Factory.newInstance(); | 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 { | public CommentsTable(PackagePart part, PackageRelationship rel) throws IOException { | ||||
super(part, rel); | super(part, rel); | ||||
getCommentsAuthors().insertAuthor(index, author); | getCommentsAuthors().insertAuthor(index, author); | ||||
return index; | return index; | ||||
} | } | ||||
public CTComments getCTComments(){ | |||||
return comments; | |||||
} | |||||
} | } |
* @author Nick Birch | * @author Nick Birch | ||||
* @author Yegor Kozlov | * @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. | * Array of individual string items in the Shared String table. | ||||
*/ | */ | ||||
private int uniqueCount; | 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() { | public SharedStringsTable() { | ||||
super(null, null); | super(null, null); | ||||
} | } |
private StyleSheetDocument doc; | 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 | * Create a new, empty StylesTable | ||||
*/ | */ |
* i.e., whether it is borded dash dot, dash dot dot, dashed, dotted, double, hair, medium, | * 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. | * medium dash dot, medium dash dot dot, medium dashed, none, slant dash dot, thick or thin. | ||||
*/ | */ | ||||
public enum BorderStyle { | |||||
public enum BorderStyle { | |||||
/** | /** | ||||
* No border | * No border |
* The enumeration value indicating the style of fill pattern being used for a cell format. | * The enumeration value indicating the style of fill pattern being used for a cell format. | ||||
* | * | ||||
*/ | */ | ||||
public enum FillPatternType { | public enum FillPatternType { | ||||
/** No background */ | /** No background */ |
* corresponds to the ANSI codepage (8-bit or DBCS) of that character set used by a given language. | * corresponds to the ANSI codepage (8-bit or DBCS) of that character set used by a given language. | ||||
* | * | ||||
* @author Gisella Bronzetti | * @author Gisella Bronzetti | ||||
* | |||||
*/ | */ | ||||
public enum FontCharset { | public enum FontCharset { | ||||
MAC(77), | MAC(77), | ||||
SHIFTJIS(128), | SHIFTJIS(128), | ||||
HANGEUL(129), | HANGEUL(129), | ||||
HANGUL(129), | |||||
JOHAB(130), | JOHAB(130), | ||||
GB2312(134), | GB2312(134), | ||||
CHINESEBIG5(136), | CHINESEBIG5(136), | ||||
private int charset; | private int charset; | ||||
FontCharset(int value){ | |||||
private FontCharset(int value){ | |||||
charset = 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){ | 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]; | |||||
} | } | ||||
} | } |
/** | /** | ||||
* | |||||
* The font family this font belongs to. A font family is a set of fonts having common stroke width and serif | * 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. | * characteristics. The font name overrides when there are conflicting values. | ||||
* | |||||
* @author Gisella Bronzetti | |||||
* | * | ||||
* @author Gisella Bronzetti | |||||
*/ | */ | ||||
public enum FontFamily { | public enum FontFamily { | ||||
MODERN(3), | MODERN(3), | ||||
SCRIPT(4), | SCRIPT(4), | ||||
DECORATIVE(5); | DECORATIVE(5); | ||||
private int family; | private int family; | ||||
FontFamily(int value){ | |||||
private FontFamily(int value) { | |||||
family = value; | family = value; | ||||
} | } | ||||
* | * | ||||
* @return index of this font family | * @return index of this font family | ||||
*/ | */ | ||||
public int getValue(){ | |||||
public int getValue() { | |||||
return family; | 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]; | |||||
} | } | ||||
} | } |
package org.apache.poi.xssf.usermodel; | 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 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 | * 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. | * theme. | ||||
* Usually major fonts are used for styles like headings, and minor fonts are used for body & paragraph text. | * Usually major fonts are used for styles like headings, and minor fonts are used for body & paragraph text. | ||||
* | * | ||||
* @author Gisella Bronzetti | * @author Gisella Bronzetti | ||||
* | |||||
*/ | */ | ||||
public enum FontScheme { | 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]; | |||||
} | } | ||||
} | } |
package org.apache.poi.xssf.usermodel; | 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 | * the different types of possible underline formatting | ||||
* | |||||
* @author Gisella Bronzetti | |||||
* | * | ||||
* @author Gisella Bronzetti | |||||
*/ | */ | ||||
public enum FontUnderline { | public enum FontUnderline { | ||||
/** | |||||
* Double-line underlining under each character in the | |||||
* cell. underlines are drawn through the descenders of | |||||
* characters such as g and p. | |||||
*/ | |||||
DOUBLE(STUnderlineValues.DOUBLE), | |||||
DOUBLE_ACCOUNTING(STUnderlineValues.DOUBLE_ACCOUNTING), | |||||
NONE(STUnderlineValues.NONE), | |||||
SINGLE(STUnderlineValues.SINGLE), | |||||
SINGLE_ACCOUNTING(STUnderlineValues.SINGLE_ACCOUNTING); | |||||
private STUnderlineValues.Enum underline; | |||||
FontUnderline(STUnderlineValues.Enum value){ | |||||
underline = value; | |||||
} | |||||
/** | /** | ||||
* Returns index of this font family | |||||
* | |||||
* @return index of this font family | |||||
* Single-line underlining under each character in the cell. | |||||
* The underline is drawn through the descenders of | |||||
* characters such as g and p.. | |||||
*/ | |||||
SINGLE(1), | |||||
/** | |||||
* Double-line underlining under each character in the | |||||
* cell. underlines are drawn through the descenders of | |||||
* characters such as g and p. | |||||
*/ | |||||
DOUBLE(2), | |||||
/** | |||||
* Single-line accounting underlining under each | |||||
* character in the cell. The underline is drawn under the | |||||
* descenders of characters such as g and p. | |||||
*/ | */ | ||||
public STUnderlineValues.Enum getValue(){ | |||||
return underline; | |||||
SINGLE_ACCOUNTING(3), | |||||
/** | |||||
* Double-line accounting underlining under each | |||||
* character in the cell. The underlines are drawn under | |||||
* the descenders of characters such as g and p. | |||||
*/ | |||||
DOUBLE_ACCOUNTING(4), | |||||
/** | |||||
* No underline. | |||||
*/ | |||||
NONE(5); | |||||
private int value; | |||||
private FontUnderline(int val) { | |||||
value = val; | |||||
} | |||||
public int getValue() { | |||||
return value; | |||||
} | } | ||||
public static FontUnderline valueOf(STUnderlineValues.Enum underline){ | |||||
switch (underline.intValue()) { | |||||
case STUnderlineValues.INT_DOUBLE: | |||||
return DOUBLE; | |||||
case STUnderlineValues.INT_DOUBLE_ACCOUNTING: | |||||
return DOUBLE_ACCOUNTING; | |||||
case STUnderlineValues.INT_SINGLE: | |||||
return SINGLE; | |||||
case STUnderlineValues.INT_SINGLE_ACCOUNTING: | |||||
return SINGLE_ACCOUNTING; | |||||
case STUnderlineValues.INT_NONE: | |||||
return NONE; | |||||
} | |||||
throw new RuntimeException("Underline value ["+ underline +"] not supported"); | |||||
public byte getByteValue() { | |||||
switch (this) { | |||||
case DOUBLE: | |||||
return Font.U_DOUBLE; | |||||
case DOUBLE_ACCOUNTING: | |||||
return Font.U_DOUBLE_ACCOUNTING; | |||||
case SINGLE_ACCOUNTING: | |||||
return Font.U_SINGLE_ACCOUNTING; | |||||
case NONE: | |||||
return Font.U_NONE; | |||||
case SINGLE: | |||||
return Font.U_SINGLE; | |||||
default: | |||||
return Font.U_SINGLE; | |||||
} | |||||
} | } | ||||
private static FontUnderline[] _table = new FontUnderline[6]; | |||||
static { | |||||
for (FontUnderline c : values()) { | |||||
_table[c.getValue()] = c; | |||||
} | |||||
} | |||||
public static FontUnderline valueOf(int value){ | |||||
return _table[value]; | |||||
} | |||||
public static FontUnderline valueOf(byte value){ | |||||
FontUnderline val; | |||||
switch (value) { | |||||
case Font.U_DOUBLE: | |||||
val = FontUnderline.DOUBLE; | |||||
break; | |||||
case Font.U_DOUBLE_ACCOUNTING: | |||||
val = FontUnderline.DOUBLE_ACCOUNTING; | |||||
break; | |||||
case Font.U_SINGLE_ACCOUNTING: | |||||
val = FontUnderline.SINGLE_ACCOUNTING; | |||||
break; | |||||
case Font.U_SINGLE: | |||||
val = FontUnderline.SINGLE; | |||||
break; | |||||
default: | |||||
val = FontUnderline.NONE; | |||||
break; | |||||
} | |||||
return val; | |||||
} | |||||
} | } |
PLUM(61), | PLUM(61), | ||||
INDIGO(62), | INDIGO(62), | ||||
GREY_80_PERCENT(63), | GREY_80_PERCENT(63), | ||||
AUTOMATIC(64), | |||||
; | |||||
AUTOMATIC(64); | |||||
private int index; | private int index; | ||||
package org.apache.poi.xssf.usermodel; | package org.apache.poi.xssf.usermodel; | ||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPageOrder; | |||||
/** | /** | ||||
* Specifies printed page order. | * Specifies printed page order. | ||||
* | * | ||||
/** | /** | ||||
* Order pages vertically first, then move horizontally. | * 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 | * 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; | this.order = order; | ||||
} | } | ||||
/** | |||||
* Returns value of pages order | |||||
* | |||||
* @return String value of pages order | |||||
*/ | |||||
public STPageOrder.Enum getValue() { | |||||
public int getValue() { | |||||
return order; | 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]; | |||||
} | } | ||||
} | } |
QUARTO_PAPER, | QUARTO_PAPER, | ||||
STANDARD_PAPER_10_14, | STANDARD_PAPER_10_14, | ||||
STANDARD_PAPER_11_17; | STANDARD_PAPER_11_17; | ||||
} | } |
package org.apache.poi.xssf.usermodel; | 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. | * These enumerations specify how cell comments shall be displayed for paper printing purposes. | ||||
* | * | ||||
/** | /** | ||||
* Do not print cell comments. | * Do not print cell comments. | ||||
*/ | */ | ||||
NONE(STCellComments.NONE), | |||||
NONE(1), | |||||
/** | /** | ||||
* Print cell comments as displayed. | * Print cell comments as displayed. | ||||
*/ | */ | ||||
AS_DISPLAYED(STCellComments.AS_DISPLAYED), | |||||
AS_DISPLAYED(2), | |||||
/** | /** | ||||
* Print cell comments at end of document. | * 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; | this.comments = comments; | ||||
} | } | ||||
/** | |||||
* Returns comments of cell | |||||
* | |||||
* @return String comments of cell | |||||
*/ | |||||
public STCellComments.Enum getValue() { | |||||
public int getValue() { | |||||
return comments; | 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]; | |||||
} | |||||
} | } |
package org.apache.poi.xssf.usermodel; | package org.apache.poi.xssf.usermodel; | ||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STOrientation; | |||||
/** | /** | ||||
* The enumeration value indicating the print orientation for a sheet. | * The enumeration value indicating the print orientation for a sheet. | ||||
* | * | ||||
/** | /** | ||||
* orientation not specified | * orientation not specified | ||||
*/ | */ | ||||
DEFAULT(STOrientation.DEFAULT), | |||||
DEFAULT(1), | |||||
/** | /** | ||||
* portrait orientation | * portrait orientation | ||||
*/ | */ | ||||
PORTRAIT(STOrientation.PORTRAIT), | |||||
PORTRAIT(2), | |||||
/** | /** | ||||
* landscape orientations | * 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; | this.orientation = orientation; | ||||
} | } | ||||
/** | |||||
* Returns value of the orientation | |||||
* | |||||
* @return String value of the orientation | |||||
*/ | |||||
public STOrientation.Enum getValue() { | |||||
public int getValue() { | |||||
return orientation; | 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]; | |||||
} | |||||
} | } |
import org.apache.poi.util.POILogger; | import org.apache.poi.util.POILogger; | ||||
import org.apache.poi.xssf.model.SharedStringSource; | import org.apache.poi.xssf.model.SharedStringSource; | ||||
import org.apache.poi.xssf.model.StylesTable; | 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.CTCell; | ||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula; | import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellFormula; | ||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType; | import org.openxmlformats.schemas.spreadsheetml.x2006.main.STCellType; | ||||
private final CTCell cell; | private final CTCell cell; | ||||
private final XSSFRow row; | private final XSSFRow row; | ||||
private int cellNum; | private int cellNum; | ||||
private SharedStringSource sharedStringSource; | |||||
private SharedStringsTable sharedStringSource; | |||||
private StylesTable stylesSource; | private StylesTable stylesSource; | ||||
private POILogger logger = POILogFactory.getLogger(XSSFCell.class); | 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) { | public XSSFCell(XSSFRow row, CTCell cell) { | ||||
this.cell = cell; | this.cell = cell; | ||||
this.row = row; | this.row = row; | ||||
this.cellNum = parseCellNum(cell.getR()); | this.cellNum = parseCellNum(cell.getR()); | ||||
} | } | ||||
this.sharedStringSource = row.getSheet().getWorkbook().getSharedStringSource(); | 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; | return this.sharedStringSource; | ||||
} | } | ||||
import org.apache.poi.ss.usermodel.Row; | import org.apache.poi.ss.usermodel.Row; | ||||
import org.apache.poi.ss.usermodel.Sheet; | import org.apache.poi.ss.usermodel.Sheet; | ||||
import org.apache.xmlbeans.XmlException; | |||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; | import org.openxmlformats.schemas.spreadsheetml.x2006.main.*; | ||||
import org.openxml4j.opc.PackagePart; | |||||
import org.openxml4j.opc.PackageRelationship; | |||||
import java.io.IOException; | |||||
public class XSSFDialogsheet extends XSSFSheet implements Sheet{ | 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) { | public XSSFRow createRow(int rowNum) { |
import org.apache.poi.ss.usermodel.Font; | import org.apache.poi.ss.usermodel.Font; | ||||
import org.apache.poi.xssf.usermodel.extensions.XSSFColor; | import org.apache.poi.xssf.usermodel.extensions.XSSFColor; | ||||
import org.apache.poi.xssf.model.StylesTable; | 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. | * Represents a font used in a workbook. | ||||
*/ | */ | ||||
public byte getCharSet() { | public byte getCharSet() { | ||||
CTIntProperty charset = ctFont.sizeOfCharsetArray() == 0 ? null : ctFont.getCharsetArray(0); | 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; | |||||
} | } | ||||
public byte getUnderline() { | public byte getUnderline() { | ||||
CTUnderlineProperty underline = ctFont.sizeOfUArray() == 0 ? null : ctFont.getUArray(0); | CTUnderlineProperty underline = ctFont.sizeOfUArray() == 0 ? null : ctFont.getUArray(0); | ||||
if (underline != null) { | 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; | return Font.U_NONE; | ||||
} | } | ||||
* @param charSet | * @param charSet | ||||
*/ | */ | ||||
public void setCharSet(FontCharset charSet) { | public void setCharSet(FontCharset charSet) { | ||||
setCharSet(charSet.getValue()); | |||||
setCharSet((byte)charSet.getValue()); | |||||
} | } | ||||
/** | /** | ||||
* @see FontUnderline | * @see FontUnderline | ||||
*/ | */ | ||||
public void setUnderline(byte underline) { | 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)); | |||||
} | } | ||||
/** | /** | ||||
* @param underline - FontUnderline enum value | * @param underline - FontUnderline enum value | ||||
*/ | */ | ||||
public void setUnderline(FontUnderline underline) { | 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); | |||||
} | |||||
} | } | ||||
*/ | */ | ||||
public FontScheme getScheme() { | public FontScheme getScheme() { | ||||
CTFontScheme scheme = ctFont.sizeOfSchemeArray() == 0 ? null : ctFont.getSchemeArray(0); | 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()); | |||||
} | } | ||||
/** | /** | ||||
*/ | */ | ||||
public void setScheme(FontScheme scheme) { | public void setScheme(FontScheme scheme) { | ||||
CTFontScheme ctFontScheme = ctFont.sizeOfSchemeArray() == 0 ? ctFont.addNewScheme() : ctFont.getSchemeArray(0); | 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); | |||||
} | } | ||||
/** | /** |
package org.apache.poi.xssf.usermodel; | package org.apache.poi.xssf.usermodel; | ||||
import org.apache.poi.ss.usermodel.PrintSetup; | 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.*; | |||||
/** | /** | ||||
public XSSFPrintSetup(CTWorksheet worksheet) { | public XSSFPrintSetup(CTWorksheet worksheet) { | ||||
if (worksheet == null) throw new NullPointerException(""); | |||||
this.ctWorksheet = worksheet; | this.ctWorksheet = worksheet; | ||||
this.pageSetup = ctWorksheet.getPageSetup() == null ? ctWorksheet.addNewPageSetup() : ctWorksheet.getPageSetup(); | this.pageSetup = ctWorksheet.getPageSetup() == null ? ctWorksheet.addNewPageSetup() : ctWorksheet.getPageSetup(); | ||||
this.pageMargins = ctWorksheet.getPageMargins() == null ? ctWorksheet.addNewPageMargins() : ctWorksheet.getPageMargins(); | this.pageMargins = ctWorksheet.getPageMargins() == null ? ctWorksheet.addNewPageMargins() : ctWorksheet.getPageMargins(); | ||||
} | } | ||||
public XSSFPrintSetup(XSSFSheet sheet) { | |||||
this(sheet.getWorksheet()); | |||||
} | |||||
public XSSFPrintSetup(CTPageSetup pageSetup, CTPageMargins pageMargins) { | |||||
this.pageMargins = pageMargins; | |||||
this.pageSetup = pageSetup; | |||||
} | |||||
/** | /** | ||||
* Set the paper size. | * Set the paper size. | ||||
* | * | ||||
* @param printnotes print the notes | * @param printnotes print the notes | ||||
*/ | */ | ||||
public void setNotes(boolean printnotes) { | public void setNotes(boolean printnotes) { | ||||
if (printnotes) | |||||
pageSetup.setCellComments(PrintCellComments.AS_DISPLAYED.getValue()); | |||||
if (printnotes){ | |||||
pageSetup.setCellComments(STCellComments.AS_DISPLAYED); | |||||
} | |||||
} | } | ||||
/** | /** | ||||
* @see PrintOrientation | * @see PrintOrientation | ||||
*/ | */ | ||||
public void setOrientation(PrintOrientation orientation) { | public void setOrientation(PrintOrientation orientation) { | ||||
pageSetup.setOrientation(orientation.getValue()); | |||||
STOrientation.Enum v = STOrientation.Enum.forInt(orientation.getValue()); | |||||
pageSetup.setOrientation(v); | |||||
} | } | ||||
/** | /** | ||||
* @see PrintOrientation | * @see PrintOrientation | ||||
*/ | */ | ||||
public PrintOrientation getOrientation() { | 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() { | 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()); | |||||
} | } | ||||
/** | /** | ||||
* @param pageOrder | * @param pageOrder | ||||
*/ | */ | ||||
public void setPageOrder(PageOrder pageOrder) { | public void setPageOrder(PageOrder pageOrder) { | ||||
pageSetup.setPageOrder(pageOrder.getValue()); | |||||
STPageOrder.Enum v = STPageOrder.Enum.forInt(pageOrder.getValue()); | |||||
pageSetup.setPageOrder(v); | |||||
} | } | ||||
/** | /** | ||||
* @return PageOrder | * @return PageOrder | ||||
*/ | */ | ||||
public PageOrder getPageOrder() { | public PageOrder getPageOrder() { | ||||
return (pageSetup.getPageOrder() == null) ? null : PageOrder.valueOf(pageSetup.getPageOrder()); | |||||
return (pageSetup.getPageOrder() == null) ? null : PageOrder.valueOf(pageSetup.getPageOrder().intValue()); | |||||
} | } | ||||
/** | /** |
private List<Cell> cells; | private List<Cell> cells; | ||||
private XSSFSheet sheet; | 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. | * Create a new XSSFRow. | ||||
* | * | ||||
return cellIterator(); | 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) { | public XSSFCell createCell(int column) { | ||||
return createCell(column, Cell.CELL_TYPE_BLANK); | return createCell(column, Cell.CELL_TYPE_BLANK); | ||||
} | } | ||||
public XSSFCell createCell(short column) { | |||||
return createCell((int)column); | |||||
} | |||||
/** | /** | ||||
* Add a new empty cell to this row. | * Add a new empty cell to this row. | ||||
return xcell; | 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) { | public XSSFCell createCell(int column, int type) { | ||||
int index = 0; | int index = 0; | ||||
for (Cell c : this.cells) { | for (Cell c : this.cells) { | ||||
if (c.getCellNum() == column) { | |||||
if (c.getColumnIndex() == column) { | |||||
// Replace c with new Cell | // Replace c with new Cell | ||||
XSSFCell xcell = addCell(column, index, type); | XSSFCell xcell = addCell(column, index, type); | ||||
cells.set(index, xcell); | cells.set(index, xcell); | ||||
return xcell; | return xcell; | ||||
} | } | ||||
if (c.getCellNum() > column) { | |||||
if (c.getColumnIndex() > column) { | |||||
XSSFCell xcell = addCell(column, index, type); | XSSFCell xcell = addCell(column, index, type); | ||||
cells.add(index, xcell); | cells.add(index, xcell); | ||||
return xcell; | return xcell; |
protected List<Row> rows; | protected List<Row> rows; | ||||
protected List<XSSFHyperlink> hyperlinks; | protected List<XSSFHyperlink> hyperlinks; | ||||
protected ColumnHelper columnHelper; | protected ColumnHelper columnHelper; | ||||
protected CommentsSource sheetComments; | |||||
private CommentsSource sheetComments; | |||||
protected CTMergeCells ctMergeCells; | protected CTMergeCells ctMergeCells; | ||||
public static final short LeftMargin = 0; | public static final short LeftMargin = 0; | ||||
worksheet = WorksheetDocument.Factory.parse(part.getInputStream()).getWorksheet(); | 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 | * Returns the parent XSSFWorkbook | ||||
* | * | ||||
* need to assign it to a cell though | * need to assign it to a cell though | ||||
*/ | */ | ||||
public XSSFComment createComment() { | 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) { | protected XSSFRow addRow(int index, int rownum) { | ||||
public XSSFComment getCellComment(int row, int column) { | public XSSFComment getCellComment(int row, int column) { | ||||
if (sheetComments == null) return null; | if (sheetComments == null) return null; | ||||
else return (XSSFComment)getComments().findCellComment(row, column); | |||||
else return (XSSFComment)sheetComments.findCellComment(row, column); | |||||
} | } | ||||
public XSSFHyperlink getHyperlink(int row, int column) { | public XSSFHyperlink getHyperlink(int row, int column) { | ||||
return views.getSheetViewArray(views.getSheetViewArray().length - 1); | 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, | * Returns the sheet's comments object if there is one, | ||||
* or null if not | * or null if not |
public XSSFSheet cloneSheet(int sheetNum) { | public XSSFSheet cloneSheet(int sheetNum) { | ||||
XSSFSheet srcSheet = sheets.get(sheetNum); | XSSFSheet srcSheet = sheets.get(sheetNum); | ||||
String srcName = getSheetName(sheetNum); | String srcName = getSheetName(sheetNum); | ||||
if (srcSheet != null) { | |||||
XSSFSheet clonedSheet = srcSheet.cloneSheet(); | |||||
sheets.add(clonedSheet); | |||||
CTSheet newcts = this.workbook.getSheets().addNewSheet(); | |||||
newcts.set(clonedSheet.getSheet()); | |||||
int i = 1; | |||||
while (true) { | |||||
//Try and find the next sheet name that is unique | |||||
String name = srcName; | |||||
String index = Integer.toString(i++); | |||||
if (name.length() + index.length() + 2 < 31) { | |||||
name = name + "("+index+")"; | |||||
} else { | |||||
name = name.substring(0, 31 - index.length() - 2) + "(" +index + ")"; | |||||
} | |||||
int i = 1; | |||||
String name = srcName; | |||||
while (true) { | |||||
//Try and find the next sheet name that is unique | |||||
String index = Integer.toString(i++); | |||||
if (name.length() + index.length() + 2 < 31) { | |||||
name = name + "("+index+")"; | |||||
} else { | |||||
name = name.substring(0, 31 - index.length() - 2) + "(" +index + ")"; | |||||
} | |||||
//If the sheet name is unique, then set it otherwise move on to the next number. | |||||
if (getSheetIndex(name) == -1) { | |||||
setSheetName(sheets.size() - 1, name); | |||||
break; | |||||
} | |||||
//If the sheet name is unique, then set it otherwise move on to the next number. | |||||
if (getSheetIndex(name) == -1) { | |||||
break; | |||||
} | } | ||||
return clonedSheet; | |||||
} | } | ||||
return null; | |||||
XSSFSheet clonedSheet = createSheet(name); | |||||
clonedSheet.worksheet.set(srcSheet.worksheet); | |||||
return clonedSheet; | |||||
} | } | ||||
/** | /** | ||||
return wrapper; | 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) { | private CTSheet addSheet(String sheetname) { |
import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | ||||
import java.io.File; | import java.io.File; | ||||
import java.io.FileOutputStream; | import java.io.FileOutputStream; | ||||
import java.util.List; | |||||
import org.apache.poi.ss.usermodel.Cell; | import org.apache.poi.ss.usermodel.Cell; | ||||
import org.apache.poi.ss.usermodel.Comment; | import org.apache.poi.ss.usermodel.Comment; | ||||
import org.apache.poi.xssf.usermodel.XSSFSheet; | import org.apache.poi.xssf.usermodel.XSSFSheet; | ||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; | import org.apache.poi.xssf.usermodel.XSSFWorkbook; | ||||
import org.apache.poi.xssf.XSSFTestDataSamples; | import org.apache.poi.xssf.XSSFTestDataSamples; | ||||
import org.apache.poi.POIXMLDocumentPart; | |||||
import org.openxml4j.opc.Package; | import org.openxml4j.opc.Package; | ||||
import org.openxml4j.opc.PackagePart; | import org.openxml4j.opc.PackagePart; | ||||
import org.openxml4j.opc.PackagingURIHelper; | 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; | import junit.framework.TestCase; | ||||
private static final String TEST_A1_TEXT = "test A1 text"; | private static final String TEST_A1_TEXT = "test A1 text"; | ||||
private static final String TEST_AUTHOR = "test author"; | 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(0, sheetComments.findAuthor(TEST_AUTHOR)); | ||||
assertEquals(1, sheetComments.findAuthor("another author")); | assertEquals(1, sheetComments.findAuthor("another author")); | ||||
assertEquals(1, sheetComments.findAuthor("another author")); | 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(); | CTCommentList commentList = comments.addNewCommentList(); | ||||
// Create 2 comments for A1 and A" cells | // Create 2 comments for A1 and A" cells | ||||
assertNull(sheetComments.findCellComment(2, 0)); | 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()); | assertEquals(0, commentList.sizeOfCommentArray()); | ||||
XSSFComment comment = sheetComments.addComment(); | XSSFComment comment = sheetComments.addComment(); | ||||
assertTrue(xml.exists()); | assertTrue(xml.exists()); | ||||
Package pkg = Package.open(xml.toString()); | 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(2, ct.getNumberOfComments()); | ||||
assertEquals(1, ct.getNumberOfAuthors()); | assertEquals(1, ct.getNumberOfAuthors()); | ||||
assertEquals("Nick Burch", comment.getAuthor()); | assertEquals("Nick Burch", comment.getAuthor()); | ||||
assertEquals("Nick Burch:\nThis is a comment", comment.getString().getString()); | 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(2, ct.getNumberOfComments()); | ||||
assertEquals(1, ct.getNumberOfAuthors()); | assertEquals(1, ct.getNumberOfAuthors()); | ||||
assertEquals("Nick Burch", comment.getAuthor()); | 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 { | public void testExisting() throws Exception { |
public void testReadWrite() { | public void testReadWrite() { | ||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx"); | XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("sample.xlsx"); | ||||
SharedStringsTable sst1 = (SharedStringsTable)wb.getSharedStringSource(); | |||||
SharedStringsTable sst1 = wb.getSharedStringSource(); | |||||
//serialize, read back and compare with the original | //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.getCount(), sst2.getCount()); | ||||
assertEquals(sst1.getUniqueCount(), sst2.getUniqueCount()); | assertEquals(sst1.getUniqueCount(), sst2.getUniqueCount()); | ||||
import java.io.ByteArrayInputStream; | import java.io.ByteArrayInputStream; | ||||
import java.io.ByteArrayOutputStream; | import java.io.ByteArrayOutputStream; | ||||
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | |||||
import org.apache.poi.xssf.usermodel.XSSFCellStyle; | import org.apache.poi.xssf.usermodel.XSSFCellStyle; | ||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook; | 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; | import junit.framework.TestCase; | ||||
} | } | ||||
public void testCreateSaveLoad() throws Exception { | public void testCreateSaveLoad() throws Exception { | ||||
StylesTable st = new StylesTable(); | |||||
XSSFWorkbook wb = new XSSFWorkbook(); | |||||
StylesTable st = wb.getStylesSource(); | |||||
assertNotNull(st._getRawStylesheet()); | assertNotNull(st._getRawStylesheet()); | ||||
assertEquals(1, st._getXfsSize()); | assertEquals(1, st._getXfsSize()); | ||||
assertEquals(1, st._getStyleXfsSize()); | assertEquals(1, st._getStyleXfsSize()); | ||||
assertEquals(0, st._getNumberFormatSize()); | 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._getXfsSize()); | ||||
assertEquals(1, st._getStyleXfsSize()); | assertEquals(1, st._getStyleXfsSize()); | ||||
assertEquals(0, st._getNumberFormatSize()); | assertEquals(0, st._getNumberFormatSize()); | ||||
XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); | XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); | ||||
assertNotNull(workbook.getStylesSource()); | assertNotNull(workbook.getStylesSource()); | ||||
StylesTable st = (StylesTable)workbook.getStylesSource(); | |||||
StylesTable st = workbook.getStylesSource(); | |||||
doTestExisting(st); | doTestExisting(st); | ||||
} | } | ||||
XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); | XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); | ||||
assertNotNull(workbook.getStylesSource()); | assertNotNull(workbook.getStylesSource()); | ||||
StylesTable st = (StylesTable)workbook.getStylesSource(); | |||||
StylesTable st = workbook.getStylesSource(); | |||||
doTestExisting(st); | 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); | doTestExisting(st); | ||||
} | } | ||||
public void doTestExisting(StylesTable st) throws Exception { | public void doTestExisting(StylesTable st) throws Exception { | ||||
} | } | ||||
public void testPopulateNew() throws Exception { | public void testPopulateNew() throws Exception { | ||||
StylesTable st = new StylesTable(); | |||||
XSSFWorkbook wb = new XSSFWorkbook(); | |||||
StylesTable st = wb.getStylesSource(); | |||||
assertNotNull(st._getRawStylesheet()); | assertNotNull(st._getRawStylesheet()); | ||||
assertEquals(1, st._getXfsSize()); | assertEquals(1, st._getXfsSize()); | ||||
st.putStyle(new XSSFCellStyle(st)); | st.putStyle(new XSSFCellStyle(st)); | ||||
// Save and re-load | // 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()); | assertNotNull(st._getRawStylesheet()); | ||||
assertEquals(2, st._getXfsSize()); | assertEquals(2, st._getXfsSize()); | ||||
assertEquals(1, st._getStyleXfsSize()); | assertEquals(1, st._getStyleXfsSize()); | ||||
XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); | XSSFWorkbook workbook = new XSSFWorkbook(xml.toString()); | ||||
assertNotNull(workbook.getStylesSource()); | assertNotNull(workbook.getStylesSource()); | ||||
StylesTable st = (StylesTable)workbook.getStylesSource(); | |||||
StylesTable st = workbook.getStylesSource(); | |||||
assertEquals(11, st._getXfsSize()); | assertEquals(11, st._getXfsSize()); | ||||
assertEquals(1, st._getStyleXfsSize()); | assertEquals(1, st._getStyleXfsSize()); | ||||
assertEquals(8, st._getNumberFormatSize()); | assertEquals(8, st._getNumberFormatSize()); | ||||
long nf2 = st.putNumberFormat("YYYY-mm-DD"); | long nf2 = st.putNumberFormat("YYYY-mm-DD"); | ||||
assertEquals(nf1, 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(11, st._getXfsSize()); | ||||
assertEquals(1, st._getStyleXfsSize()); | assertEquals(1, st._getStyleXfsSize()); | ||||
assertEquals(10, st._getNumberFormatSize()); | assertEquals(10, st._getNumberFormatSize()); |
*/ | */ | ||||
public void testSetGetBoolean() throws Exception { | public void testSetGetBoolean() throws Exception { | ||||
XSSFRow row = createParentObjects(); | XSSFRow row = createParentObjects(); | ||||
XSSFCell cell = new XSSFCell(row); | |||||
XSSFCell cell = row.createCell(0); | |||||
cell.setCellValue(true); | cell.setCellValue(true); | ||||
assertEquals(Cell.CELL_TYPE_BOOLEAN, cell.getCellType()); | assertEquals(Cell.CELL_TYPE_BOOLEAN, cell.getCellType()); | ||||
assertTrue(cell.getBooleanCellValue()); | assertTrue(cell.getBooleanCellValue()); | ||||
*/ | */ | ||||
public void testSetGetNumeric() throws Exception { | public void testSetGetNumeric() throws Exception { | ||||
XSSFRow row = createParentObjects(); | XSSFRow row = createParentObjects(); | ||||
XSSFCell cell = new XSSFCell(row); | |||||
XSSFCell cell = row.createCell(0); | |||||
cell.setCellValue(10d); | cell.setCellValue(10d); | ||||
assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType()); | assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType()); | ||||
assertEquals(10d, cell.getNumericCellValue()); | assertEquals(10d, cell.getNumericCellValue()); | ||||
*/ | */ | ||||
public void testSetGetDate() throws Exception { | public void testSetGetDate() throws Exception { | ||||
XSSFRow row = createParentObjects(); | XSSFRow row = createParentObjects(); | ||||
XSSFCell cell = new XSSFCell(row); | |||||
XSSFCell cell = row.createCell(0); | |||||
Date now = new Date(); | Date now = new Date(); | ||||
cell.setCellValue(now); | cell.setCellValue(now); | ||||
assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType()); | assertEquals(Cell.CELL_TYPE_NUMERIC, cell.getCellType()); | ||||
public void testSetGetError() throws Exception { | public void testSetGetError() throws Exception { | ||||
XSSFRow row = createParentObjects(); | XSSFRow row = createParentObjects(); | ||||
XSSFCell cell = new XSSFCell(row); | |||||
XSSFCell cell = row.createCell(0); | |||||
cell.setCellErrorValue((byte)0); | cell.setCellErrorValue((byte)0); | ||||
assertEquals(Cell.CELL_TYPE_ERROR, cell.getCellType()); | assertEquals(Cell.CELL_TYPE_ERROR, cell.getCellType()); | ||||
public void testSetGetFormula() throws Exception { | public void testSetGetFormula() throws Exception { | ||||
XSSFRow row = createParentObjects(); | XSSFRow row = createParentObjects(); | ||||
XSSFCell cell = new XSSFCell(row); | |||||
XSSFCell cell = row.createCell(0); | |||||
String formula = "SQRT(C2^2+D2^2)"; | String formula = "SQRT(C2^2+D2^2)"; | ||||
cell.setCellFormula(formula); | cell.setCellFormula(formula); | ||||
public void testSetGetStringShared() { | public void testSetGetStringShared() { | ||||
XSSFRow row = createParentObjects(); | XSSFRow row = createParentObjects(); | ||||
XSSFCell cell = new XSSFCell(row); | |||||
XSSFCell cell = row.createCell(0); | |||||
cell.setCellValue(new XSSFRichTextString("")); | cell.setCellValue(new XSSFRichTextString("")); | ||||
assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType()); | assertEquals(Cell.CELL_TYPE_STRING, cell.getCellType()); | ||||
*/ | */ | ||||
public void testGetEmptyCellValue() { | public void testGetEmptyCellValue() { | ||||
XSSFRow row = createParentObjects(); | XSSFRow row = createParentObjects(); | ||||
XSSFCell cell = new XSSFCell(row); | |||||
XSSFCell cell = row.createCell(0); | |||||
cell.setCellType(Cell.CELL_TYPE_BOOLEAN); | cell.setCellType(Cell.CELL_TYPE_BOOLEAN); | ||||
assertFalse(cell.getBooleanCellValue()); | assertFalse(cell.getBooleanCellValue()); | ||||
cell.setCellType(Cell.CELL_TYPE_NUMERIC); | cell.setCellType(Cell.CELL_TYPE_NUMERIC); | ||||
public void testFormatPosition() { | public void testFormatPosition() { | ||||
XSSFRow row = createParentObjects(); | XSSFRow row = createParentObjects(); | ||||
row.setRowNum(0); | row.setRowNum(0); | ||||
XSSFCell cell = new XSSFCell(row); | |||||
XSSFCell cell = row.createCell(0); | |||||
cell.setCellNum((short) 0); | cell.setCellNum((short) 0); | ||||
assertEquals("A1", cell.formatPosition()); | assertEquals("A1", cell.formatPosition()); | ||||
cell.setCellNum((short) 25); | cell.setCellNum((short) 25); | ||||
assertEquals("IV32768", cell.formatPosition()); | 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() { | public void testGetCellComment() { | ||||
XSSFWorkbook workbook = new XSSFWorkbook(); | 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); | assertNotNull(sheet); | ||||
XSSFComment comment = sheet.createComment(); | |||||
comment.setAuthor(TEST_C10_AUTHOR); | |||||
sheet.setCellComment("C10", comment); | |||||
// Create C10 cell | // Create C10 cell | ||||
Row row = sheet.createRow(9); | Row row = sheet.createRow(9); | ||||
row.createCell(2); | row.createCell(2); | ||||
row.createCell(3); | 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)); | ||||
assertNotNull(sheet.getRow(9).getCell((short)2).getCellComment()); | assertNotNull(sheet.getRow(9).getCell((short)2).getCellComment()); | ||||
assertEquals(TEST_C10_AUTHOR, sheet.getRow(9).getCell((short)2).getCellComment().getAuthor()); | assertEquals(TEST_C10_AUTHOR, sheet.getRow(9).getCell((short)2).getCellComment().getAuthor()); | ||||
public void testSetCellComment() { | public void testSetCellComment() { | ||||
XSSFWorkbook workbook = new XSSFWorkbook(); | 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); | assertNotNull(sheet); | ||||
XSSFComment comment = sheet.createComment(); | |||||
comment.setAuthor(TEST_C10_AUTHOR); | |||||
CTWorksheet ctWorksheet = sheet.getWorksheet(); | |||||
// Create C10 cell | // Create C10 cell | ||||
Row row = sheet.createRow(9); | Row row = sheet.createRow(9); | ||||
Cell cell = row.createCell(2); | Cell cell = row.createCell(2); | ||||
row.createCell(3); | row.createCell(3); | ||||
// Create a comment | |||||
Comment comment = comments.addComment(); | |||||
comment.setAuthor(TEST_C10_AUTHOR); | |||||
// Set a comment for C10 cell | // Set a comment for C10 cell | ||||
cell.setCellComment(comment); | cell.setCellComment(comment); | ||||
CTCell ctCell = ctWorksheet.getSheetData().getRowArray(0).getCArray(0); | CTCell ctCell = ctWorksheet.getSheetData().getRowArray(0).getCArray(0); | ||||
assertNotNull(ctCell); | assertNotNull(ctCell); | ||||
assertEquals("C10", ctCell.getR()); | 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() { | 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 cell = sheet.createRow(0).createCell((short)0); | ||||
cell.setAsActiveCell(); | cell.setAsActiveCell(); | ||||
assertEquals("A1", ctWorksheet.getSheetViews().getSheetViewArray(0).getSelectionArray(0).getActiveCell()); | |||||
assertEquals("A1", sheet.getWorksheet().getSheetViews().getSheetViewArray(0).getSelectionArray(0).getActiveCell()); | |||||
} | } | ||||
private static XSSFRow createParentObjects() { | private static XSSFRow createParentObjects() { | ||||
XSSFWorkbook wb = new XSSFWorkbook(); | 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; | return row; | ||||
} | } | ||||
import org.apache.poi.ss.util.CellReference; | import org.apache.poi.ss.util.CellReference; | ||||
import org.apache.poi.xssf.model.CommentsTable; | import org.apache.poi.xssf.model.CommentsTable; | ||||
import org.apache.poi.xssf.XSSFTestDataSamples; | 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.CTAuthors; | ||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment; | import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment; | ||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments; | import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments; | ||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CommentsDocument; | |||||
import junit.framework.TestCase; | import junit.framework.TestCase; | ||||
import java.io.ByteArrayOutputStream; | |||||
import java.io.ByteArrayInputStream; | |||||
public class TestXSSFComment extends TestCase { | 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); | |||||
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()); | |||||
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()); | |||||
} | |||||
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() 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()); | |||||
} | |||||
} | } |
public class TestXSSFDialogSheet extends TestCase { | 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() { | public void testCreateDialogSheet() { | ||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
Sheet dialogsheet = workbook.createDialogsheet("Dialogsheet 1", CTDialogsheet.Factory.newInstance()); | Sheet dialogsheet = workbook.createDialogsheet("Dialogsheet 1", CTDialogsheet.Factory.newInstance()); |
import junit.framework.TestCase; | 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} | * Tests for {@link XSSFPrintSetup} | ||||
* | |||||
*/ | */ | ||||
public class TestXSSFPrintSetup extends TestCase { | 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() { | 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()); | |||||
printSetup.setPaperSize(PaperSize.A3_PAPER); | |||||
assertEquals(8,pSetup.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()); | |||||
} | } | ||||
public void testSetGetScale() { | public void testSetGetScale() { | ||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance(); | |||||
pSetup.setScale(9); | |||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null); | |||||
assertEquals(9,printSetup.getScale()); | |||||
printSetup.setScale((short)100); | |||||
assertEquals(100,pSetup.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()); | |||||
} | } | ||||
public void testSetGetPageStart() { | public void testSetGetPageStart() { | ||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance(); | |||||
pSetup.setFirstPageNumber(9); | |||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null); | |||||
assertEquals(9,printSetup.getPageStart()); | |||||
printSetup.setPageStart((short)1); | |||||
assertEquals(1,pSetup.getFirstPageNumber()); | |||||
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()); | |||||
} | } | ||||
public void testSetGetFitWidthHeight() { | 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()); | |||||
printSetup.setFitWidth((short)66); | |||||
printSetup.setFitHeight((short)80); | |||||
assertEquals(66,pSetup.getFitToWidth()); | |||||
assertEquals(80,pSetup.getFitToHeight()); | |||||
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()); | |||||
} | } | ||||
public void testSetGetLeftToRight() { | 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() { | 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()); | |||||
printSetup.setOrientation(PrintOrientation.LANDSCAPE); | |||||
assertEquals(pSetup.getOrientation(),printSetup.getOrientation().getValue()); | |||||
assertEquals(true,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().intValue(), printSetup.getOrientation().getValue()); | |||||
assertEquals(true, printSetup.getLandscape()); | |||||
assertEquals(false, printSetup.getNoOrientation()); | |||||
} | } | ||||
public void testSetGetValidSettings() { | public void testSetGetValidSettings() { | ||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance(); | |||||
pSetup.setUsePrinterDefaults(false); | |||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null); | |||||
assertEquals(false,printSetup.getValidSettings()); | |||||
printSetup.setValidSettings(true); | |||||
assertEquals(true,pSetup.getUsePrinterDefaults()); | |||||
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()); | |||||
} | } | ||||
public void testSetGetNoColor() { | public void testSetGetNoColor() { | ||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance(); | |||||
pSetup.setBlackAndWhite(false); | |||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null); | |||||
assertEquals(false,printSetup.getNoColor()); | |||||
printSetup.setNoColor(true); | |||||
assertEquals(true,pSetup.getBlackAndWhite()); | |||||
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()); | |||||
} | } | ||||
public void testSetGetDraft() { | public void testSetGetDraft() { | ||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance(); | |||||
pSetup.setDraft(false); | |||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null); | |||||
assertEquals(false,printSetup.getDraft()); | |||||
printSetup.setDraft(true); | |||||
assertEquals(true,pSetup.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()); | |||||
} | } | ||||
public void testSetGetNotes() { | public void testSetGetNotes() { | ||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance(); | |||||
pSetup.setCellComments(STCellComments.NONE); | |||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null); | |||||
assertEquals(false,printSetup.getNotes()); | |||||
printSetup.setNotes(true); | |||||
assertEquals(PrintCellComments.AS_DISPLAYED.getValue(),pSetup.getCellComments()); | |||||
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().intValue()); | |||||
} | } | ||||
public void testSetGetUsePage() { | public void testSetGetUsePage() { | ||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance(); | |||||
pSetup.setUseFirstPageNumber(false); | |||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null); | |||||
assertEquals(false,printSetup.getUsePage()); | |||||
printSetup.setUsePage(true); | |||||
assertEquals(true,pSetup.getUseFirstPageNumber()); | |||||
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()); | |||||
} | } | ||||
public void testSetGetHVResolution() { | 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()); | |||||
printSetup.setHResolution((short)150); | |||||
printSetup.setVResolution((short)130); | |||||
assertEquals(150,pSetup.getHorizontalDpi()); | |||||
assertEquals(130,pSetup.getVerticalDpi()); | |||||
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()); | |||||
} | } | ||||
public void testSetGetHeaderFooterMargin() { | 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()); | |||||
printSetup.setHeaderMargin(5); | |||||
printSetup.setFooterMargin(3.5); | |||||
assertEquals(5.0,pMargins.getHeader()); | |||||
assertEquals(3.5,pMargins.getFooter()); | |||||
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()); | |||||
} | } | ||||
public void testSetGetCopies() { | public void testSetGetCopies() { | ||||
CTPageSetup pSetup=CTPageSetup.Factory.newInstance(); | |||||
pSetup.setCopies(9); | |||||
XSSFPrintSetup printSetup=new XSSFPrintSetup(pSetup, null); | |||||
assertEquals(9,printSetup.getCopies()); | |||||
printSetup.setCopies((short)15); | |||||
assertEquals(15,pSetup.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()); | |||||
} | } | ||||
} | } |
* Test adding cells to a row in various places and see if we can find them again. | * Test adding cells to a row in various places and see if we can find them again. | ||||
*/ | */ | ||||
public void testAddAndIterateCells() { | public void testAddAndIterateCells() { | ||||
XSSFRow row = new XSSFRow(createParentObjects()); | |||||
XSSFSheet sheet = createParentObjects(); | |||||
XSSFRow row = sheet.createRow(0); | |||||
// One cell at the beginning | // One cell at the beginning | ||||
Cell cell1 = row.createCell((short) 1); | Cell cell1 = row.createCell((short) 1); | ||||
assertFalse(row.getFirstCellNum() == (short) 2); | assertFalse(row.getFirstCellNum() == (short) 2); | ||||
// Test a row without cells | // Test a row without cells | ||||
XSSFRow emptyRow = new XSSFRow(createParentObjects()); | |||||
XSSFSheet sheet = createParentObjects(); | |||||
XSSFRow emptyRow = sheet.createRow(0); | |||||
assertEquals(-1, emptyRow.getFirstCellNum()); | assertEquals(-1, emptyRow.getFirstCellNum()); | ||||
} | } | ||||
* Tests for the missing/blank cell policy stuff | * Tests for the missing/blank cell policy stuff | ||||
*/ | */ | ||||
public void testGetCellPolicy() throws Exception { | public void testGetCellPolicy() throws Exception { | ||||
XSSFRow row = new XSSFRow(createParentObjects()); | |||||
XSSFSheet sheet = createParentObjects(); | |||||
XSSFRow row = sheet.createRow(0); | |||||
// 0 -> string | // 0 -> string | ||||
// 1 -> num | // 1 -> num | ||||
* @return row | * @return row | ||||
*/ | */ | ||||
private static XSSFRow getSampleRow() { | private static XSSFRow getSampleRow() { | ||||
XSSFRow row = new XSSFRow(createParentObjects()); | |||||
XSSFSheet sheet = createParentObjects(); | |||||
XSSFRow row = sheet.createRow(0); | |||||
row.createCell((short) 2); | row.createCell((short) 2); | ||||
row.createCell((short) 3, Cell.CELL_TYPE_NUMERIC); | row.createCell((short) 3, Cell.CELL_TYPE_NUMERIC); | ||||
row.createCell((short) 4); | row.createCell((short) 4); |
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment; | import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment; | ||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments; | import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments; | ||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow; | 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.CTWorksheet; | ||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf; | import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf; | ||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane; | import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane; | ||||
public void testGetFooter() { | public void testGetFooter() { | ||||
XSSFWorkbook workbook = new XSSFWorkbook(); | XSSFWorkbook workbook = new XSSFWorkbook(); | ||||
XSSFSheet sheet = (XSSFSheet)workbook.createSheet("Sheet 1"); | |||||
XSSFSheet sheet = workbook.createSheet("Sheet 1"); | |||||
assertNotNull(sheet.getFooter()); | assertNotNull(sheet.getFooter()); | ||||
sheet.getFooter().setCenter("test center footer"); | sheet.getFooter().setCenter("test center footer"); | ||||
assertEquals("test center footer", sheet.getFooter().getCenter()); | assertEquals("test center footer", sheet.getFooter().getCenter()); | ||||
public void testGetCellComment() { | public void testGetCellComment() { | ||||
XSSFWorkbook workbook = new XSSFWorkbook(); | 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)); | assertNotNull(sheet.getCellComment(9, 2)); | ||||
assertEquals("test C10 author", sheet.getCellComment(9, 2).getAuthor()); | assertEquals("test C10 author", sheet.getCellComment(9, 2).getAuthor()); | ||||
} | } | ||||
public void testSetCellComment() { | public void testSetCellComment() { | ||||
XSSFWorkbook workbook = new XSSFWorkbook(); | 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); | 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); | sheet.setCellComment("A1", comment); | ||||
assertEquals("A1", ctComments.getCommentList().getCommentArray(0).getRef()); | assertEquals("A1", ctComments.getCommentList().getCommentArray(0).getRef()); | ||||
comment.setAuthor("test A1 author"); | comment.setAuthor("test A1 author"); | ||||
} | } | ||||
public void testCreateFreezePane() { | 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); | sheet.createFreezePane(2, 4); | ||||
assertEquals((double)2, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getXSplit()); | assertEquals((double)2, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getXSplit()); | ||||
assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane()); | assertEquals(STPane.BOTTOM_RIGHT, ctWorksheet.getSheetViews().getSheetViewArray(0).getPane().getActivePane()); | ||||
} | } | ||||
public void testNewMergedRegionAt() { | 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"); | Region region = new Region("B2:D4"); | ||||
sheet.addMergedRegion(region); | sheet.addMergedRegion(region); | ||||
assertEquals("B2:D4", sheet.getMergedRegionAt(0).getRegionRef()); | assertEquals("B2:D4", sheet.getMergedRegionAt(0).getRegionRef()); | ||||
} | } | ||||
public void testGetNumMergedRegions() { | 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()); | assertEquals(0, sheet.getNumMergedRegions()); | ||||
Region region = new Region("B2:D4"); | Region region = new Region("B2:D4"); | ||||
sheet.addMergedRegion(region); | sheet.addMergedRegion(region); | ||||
} | } | ||||
public void testRemoveMergedRegion() { | 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_1 = new Region("A1:B2"); | ||||
Region region_2 = new Region("C3:D4"); | Region region_2 = new Region("C3:D4"); | ||||
Region region_3 = new Region("E5:F6"); | Region region_3 = new Region("E5:F6"); | ||||
} | } | ||||
public void testSetDefaultColumnStyle() { | 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(); | XSSFFont font = new XSSFFont(); | ||||
font.setFontName("Cambria"); | font.setFontName("Cambria"); | ||||
stylesTable.putFont(font); | stylesTable.putFont(font); | ||||
public void testGroupUngroupColumn() { | 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 | //one level | ||||
sheet.groupColumn((short)2,(short)7); | sheet.groupColumn((short)2,(short)7); | ||||
public void testGroupUngroupRow() { | 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 | //one level | ||||
sheet.groupRow(9,10); | sheet.groupRow(9,10); |
public void testGetSetColDefaultStyle() { | public void testGetSetColDefaultStyle() { | ||||
XSSFWorkbook workbook = new XSSFWorkbook(); | 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(); | ColumnHelper columnHelper = sheet.getColumnHelper(); | ||||
// POI column 3, OOXML column 4 | // POI column 3, OOXML column 4 |