import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorders;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellStyleXfs;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellXfs;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxf;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxfs;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFills;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTNumFmts;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STFontScheme;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument;
-
/**
* Table of styles shared across all sheets in a workbook.
*
private final LinkedList<CTXf> styleXfs = new LinkedList<CTXf>();
private final LinkedList<CTXf> xfs = new LinkedList<CTXf>();
+ private final LinkedList<CTDxf> dxfs = new LinkedList<CTDxf>();
+
/**
* The first style id available for use as a custom style
*/
public void readFrom(InputStream is) throws IOException {
try {
doc = StyleSheetDocument.Factory.parse(is);
-
// Grab all the different bits we care about
if(doc.getStyleSheet().getNumFmts() != null)
for (CTNumFmt nfmt : doc.getStyleSheet().getNumFmts().getNumFmtArray()) {
for (CTXf xf : doc.getStyleSheet().getCellStyleXfs().getXfArray()) {
styleXfs.add(xf);
}
+ // dxf
+ if(doc.getStyleSheet().getDxfs() != null)
+ for (CTDxf dxf : doc.getStyleSheet().getDxfs().getDxfArray()) {
+ dxfs.add(dxf);
+ }
+
} catch (XmlException e) {
throw new IOException(e.getLocalizedMessage());
}
public Font getFontAt(long idx) {
return new XSSFFont(fonts.get((int) idx));
}
+
public synchronized long putFont(Font font) {
return putFont((XSSFFont)font, fonts);
}
styleXfs.add(cellStyleXf);
return styleXfs.size();
}
- /**
+ /**
+ * get the size of cell styles
+ */
+ public int getNumCellStyles(){
+ return styleXfs.size();
+ }
+
+ /**
* For unit testing only
*/
public int _getNumberFormatSize() {
doc.getStyleSheet().setCellStyleXfs(ctSXfs);
}
+ // Style dxf
+ if(dxfs.size() > 0) {
+ CTDxfs ctDxfs = CTDxfs.Factory.newInstance();
+ ctDxfs.setCount(dxfs.size());
+ ctDxfs.setDxfArray(dxfs.toArray(new CTDxf[dxfs.size()])
+ );
+ doc.getStyleSheet().setDxfs(ctDxfs);
+ }
+
+
+
// Save
doc.save(out, options);
}
return font.putFont(fonts);
}
private void initialize() {
- CTFont ctFont = createDefaultFont();
- fonts.add(ctFont);
+ //CTFont ctFont = createDefaultFont();
+ XSSFFont xssfFont = createDefaultFont();
+ fonts.add(xssfFont.getCTFont());
CTFill ctFill = createDefaultFill();
fills.add(ctFill);
xf.setXfId(0);
xfs.add(xf);
}
+
private CTXf createDefaultXf() {
CTXf ctXf = CTXf.Factory.newInstance();
ctXf.setNumFmtId(0);
ctBorder.addNewDiagonal();
return ctBorder;
}
+
private CTFill createDefaultFill() {
CTFill ctFill = CTFill.Factory.newInstance();
ctFill.addNewPatternFill().setPatternType(STPatternType.NONE);
return ctFill;
}
- private CTFont createDefaultFont() {
+
+ private XSSFFont createDefaultFont() {
+ /*
CTFont ctFont = CTFont.Factory.newInstance();
ctFont.addNewSz().setVal(11);
ctFont.addNewColor().setTheme(1);
ctFont.addNewName().setVal("Calibri");
ctFont.addNewFamily().setVal(2);
ctFont.addNewScheme().setVal(STFontScheme.MINOR);
- return ctFont;
+ XSSFFont font=new XSSFFont(ctFont);
+ return font;
+ */
+
+ XSSFFont xssfFont=new XSSFFont();
+ xssfFont.setFontHeightInPoints(XSSFFont.DEFAULT_FONT_SIZE);
+ xssfFont.setColor(XSSFFont.DEFAULT_FONT_COLOR);//setTheme
+ xssfFont.setFontName(XSSFFont.DEFAULT_FONT_NAME);
+ xssfFont.setFamily(XSSFFont.FONT_FAMILY_SWISS);
+ xssfFont.setScheme(XSSFFont.SCHEME_MINOR);
+ return xssfFont;
+ }
+
+
+
+
+ public CTDxf getDxf(long idx) {
+ if(dxfs.size()==0)
+ return CTDxf.Factory.newInstance();
+ else
+ return dxfs.get((int) idx);
+ }
+
+
+ public long putDxf(CTDxf dxf) {
+ this.dxfs.add(dxf);
+ return this.dxfs.size();
}
+
+
+
}
}
public void setFillBackgroundColor(short bg) {
- // TODO Auto-generated method stub
-
+ getCellFill().setFillBackgroundColor(bg);
}
public void setFillForegroundColor(short bg) {
- // TODO Auto-generated method stub
-
+ getCellFill().setFillForegroundColor(bg);
}
public void setFillPattern(short fp) {
}
public void setFont(Font font) {
- // TODO Auto-generated method stub
-
+ if(font!=null){
+ long index=this.stylesSource.putFont(font);
+ this.cellXf.setFontId(index);
+ }
}
public void setHidden(boolean hidden) {
import java.util.LinkedList;\r
\r
import org.apache.poi.ss.usermodel.Font;\r
+\r
+import org.apache.poi.xssf.util.CTFontWrapper;\r
+import org.apache.poi.xssf.util.Charset;\r
+import org.apache.poi.xssf.util.IndexedColors;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBooleanProperty;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;\r
+\r
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontName;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontScheme;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFontSize;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTIntProperty;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTUnderlineProperty;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTVerticalAlignFontProperty;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STFontScheme;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;\r
\r
public class XSSFFont implements Font {\r
- \r
- private CTFont font;\r
+\r
+\r
+ public static final int SCHEME_MAJOR=2;\r
+ public static final int SCHEME_MINOR=3;\r
+ public static final int SCHEME_NONE=0;\r
+\r
+ public static final int FONT_FAMILY_NOT_APPLICABLE=0;\r
+ public static final int FONT_FAMILY_ROMAN=1;\r
+ public static final int FONT_FAMILY_SWISS=2;\r
+ public static final int FONT_FAMILY_MODERN=3;\r
+ public static final int FONT_FAMILY_SCRIPT=4;\r
+ public static final int FONT_FAMILY_DECORATIVE=5;\r
+\r
+\r
+ public static final String DEFAULT_FONT_NAME="Calibri";\r
+ public static final short DEFAULT_FONT_SIZE=11;\r
+ public static final short DEFAULT_FONT_COLOR=(short)IndexedColors.BLACK;\r
+\r
+ private int index=0;\r
+\r
+\r
+ private CTFontWrapper fontWrapper;\r
+\r
+\r
\r
public XSSFFont(CTFont font) {\r
- this.font = font;\r
+ this.fontWrapper=new CTFontWrapper(font);\r
}\r
- \r
+\r
+ /* \r
+ public XSSFFont(int index) {\r
+ this.fontWrapper=new CTFontWrapper(font);\r
+ this.index=index;\r
+ }\r
+ */\r
+\r
public XSSFFont() {\r
- this.font = CTFont.Factory.newInstance();\r
+ this.fontWrapper = new CTFontWrapper(CTFont.Factory.newInstance());\r
}\r
\r
- public short getBoldweight() {\r
- // TODO Auto-generated method stub\r
- return 0;\r
+\r
+ public CTFont getCTFont(){\r
+ return fontWrapper.getCTFont();\r
}\r
\r
+\r
+ public short getBoldweight() {\r
+ CTBooleanProperty bold=fontWrapper.getB();\r
+ if(bold!=null && bold.getVal())\r
+ return Font.BOLDWEIGHT_BOLD;\r
+ else\r
+ return Font.BOLDWEIGHT_NORMAL;\r
+ } \r
+\r
+\r
+\r
public byte getCharSet() {\r
- // TODO Auto-generated method stub\r
- return 0;\r
+ CTIntProperty charset= fontWrapper.getCharset();\r
+ if(charset!=null){\r
+ //this value must be set -- can't be null\r
+ switch (charset.getVal()) {\r
+ case Charset.ANSI_CHARSET:\r
+ return Font.ANSI_CHARSET;\r
+\r
+ case Charset.DEFAULT_CHARSET:\r
+ return Font.DEFAULT_CHARSET;\r
+\r
+ case Charset.SYMBOL_CHARSET:\r
+ return Font.SYMBOL_CHARSET;\r
+\r
+ default://maight be correct to return this byte value???\r
+ return Byte.parseByte(Integer.toString(charset.getVal()));\r
+ }\r
+ }\r
+ else\r
+ return Font.ANSI_CHARSET;\r
}\r
\r
public short getColor() {\r
- // TODO Auto-generated method stub\r
- return 0;\r
+ CTColor color=fontWrapper.getColor();\r
+ long index=color.getIndexed();\r
+ if (index==XSSFFont.DEFAULT_FONT_COLOR){\r
+ return Font.COLOR_NORMAL;\r
+ }\r
+ else if(index==IndexedColors.RED){\r
+ return Font.COLOR_RED;\r
+ }\r
+ else{\r
+ return Short.parseShort(new Long(index).toString());\r
+ }\r
}\r
\r
public short getFontHeight() {\r
- // TODO Auto-generated method stub\r
- return 0;\r
+ if(fontWrapper.getSz()!=null){\r
+ double fontHeight= fontWrapper.getSz().getVal()/20;\r
+ return (short)fontHeight;\r
+ }\r
+ else\r
+ return DEFAULT_FONT_SIZE/20;\r
}\r
\r
public short getFontHeightInPoints() {\r
- // TODO Auto-generated method stub\r
- return 0;\r
+ if(fontWrapper.getSz()!=null){\r
+ double fontHeight= fontWrapper.getSz().getVal();// /72;\r
+ return (short)fontHeight;//new Double(fontHeight).shortValue();\r
+ }\r
+ else\r
+ return DEFAULT_FONT_SIZE;\r
}\r
\r
- public String getFontName() {\r
- // TODO Auto-generated method stub\r
- return null;\r
+ //AGGIUNGERE CONTROLLO NULL\r
+ public String getFontName() { \r
+ if(fontWrapper.getName()!=null)\r
+ return fontWrapper.getName().getVal();\r
+ else\r
+ return DEFAULT_FONT_NAME;\r
}\r
\r
+\r
public short getIndex() {\r
// TODO Auto-generated method stub\r
return 0;\r
}\r
\r
public boolean getItalic() {\r
- // TODO Auto-generated method stub\r
- return false;\r
+ if(fontWrapper.getI()!=null)\r
+ return fontWrapper.getI().getVal();\r
+ else\r
+ return false;\r
}\r
\r
public boolean getStrikeout() {\r
- // TODO Auto-generated method stub\r
- return false;\r
+ if(fontWrapper.getStrike()!=null)\r
+ return fontWrapper.getStrike().getVal();\r
+ else\r
+ return false;\r
}\r
\r
public short getTypeOffset() {\r
- // TODO Auto-generated method stub\r
- return 0;\r
+ if(fontWrapper.getVertAlign()!=null){\r
+ int val=fontWrapper.getVertAlign().getVal().intValue();\r
+ switch (val) {\r
+ case STVerticalAlignRun.INT_BASELINE:\r
+ return Font.SS_NONE;\r
+ case STVerticalAlignRun.INT_SUBSCRIPT:\r
+ return Font.SS_SUB;\r
+ case STVerticalAlignRun.INT_SUPERSCRIPT:\r
+ return Font.SS_SUPER;\r
+ default: throw new RuntimeException("Wrong offset value "+val);\r
+ }\r
+ }\r
+ else\r
+ return Font.SS_NONE;\r
}\r
\r
- public byte getUnderline() {\r
- // TODO Auto-generated method stub\r
- return 0;\r
+ public byte getUnderline() { \r
+ if(fontWrapper.getU()!=null){\r
+ //attenzione : -- get val pu\98 tornare null----\r
+ switch (fontWrapper.getU().getVal().intValue()) {\r
+ case STUnderlineValues.INT_DOUBLE:\r
+ return Font.U_DOUBLE; \r
+ case STUnderlineValues.INT_DOUBLE_ACCOUNTING:\r
+ return Font.U_DOUBLE_ACCOUNTING; \r
+\r
+ case STUnderlineValues.INT_SINGLE_ACCOUNTING:\r
+ return Font.U_SINGLE_ACCOUNTING; \r
+\r
+ case STUnderlineValues.INT_NONE:\r
+ return Font.U_NONE;\r
+\r
+ case STUnderlineValues.INT_SINGLE: \r
+ default:\r
+ return Font.U_SINGLE;\r
+ }\r
+ }\r
+ return Font.U_NONE;\r
}\r
\r
- public void setBoldweight(short boldweight) {\r
- // TODO Auto-generated method stub\r
- \r
+ public void setBoldweight(short boldweight) { \r
+ if(boldweight==Font.BOLDWEIGHT_BOLD){\r
+\r
+ CTBooleanProperty bold;\r
+ if(fontWrapper.getCTFont().getBArray().length==0){\r
+ bold=fontWrapper.getCTFont().addNewB();\r
+ }\r
+ else{\r
+ bold=CTBooleanProperty.Factory.newInstance();\r
+ }\r
+ bold.setVal(true);\r
+ fontWrapper.setB(bold);\r
+ }\r
}\r
\r
public void setCharSet(byte charset) {\r
- // TODO Auto-generated method stub\r
- \r
+ CTIntProperty charsetProperty;\r
+ if(fontWrapper.getCTFont().getCharsetArray().length==0){\r
+ charsetProperty=fontWrapper.getCTFont().addNewCharset();\r
+ }\r
+ else{\r
+ charsetProperty=CTIntProperty.Factory.newInstance();\r
+ }\r
+ switch (charset) {\r
+ case Font.ANSI_CHARSET:\r
+ charsetProperty.setVal(Charset.ANSI_CHARSET); \r
+ break;\r
+ case Font.SYMBOL_CHARSET:\r
+ charsetProperty.setVal(Charset.SYMBOL_CHARSET); \r
+ break;\r
+ case Font.DEFAULT_CHARSET:\r
+ charsetProperty.setVal(Charset.DEFAULT_CHARSET); \r
+ break;\r
+ default:\r
+ throw new RuntimeException("Attention: an attempt to set a type of unknow charset and charset");\r
+ }\r
+\r
+ fontWrapper.setCharset(charsetProperty);\r
}\r
\r
+\r
public void setColor(short color) {\r
- // TODO Auto-generated method stub\r
+ CTColor ctColor;\r
+ if(fontWrapper.getCTFont().getColorArray().length==0){\r
+ ctColor=fontWrapper.getCTFont().addNewColor();\r
+ }\r
+ else{\r
+ ctColor=CTColor.Factory.newInstance();\r
+ }\r
\r
+ switch (color) {\r
+ case Font.COLOR_NORMAL:{\r
+ ctColor.setIndexed(XSSFFont.DEFAULT_FONT_COLOR);\r
+ break;\r
+ }\r
+ case Font.COLOR_RED:{\r
+ ctColor.setIndexed(IndexedColors.RED);\r
+ break;\r
+ }\r
+ default:\r
+ ctColor.setIndexed(color);\r
+ }\r
+\r
+ fontWrapper.setColor(ctColor);\r
}\r
\r
+\r
+\r
public void setFontHeight(short height) {\r
- // TODO Auto-generated method stub\r
- \r
+ CTFontSize fontSize;\r
+ if(fontWrapper.getCTFont().getSzArray().length==0){\r
+ fontSize=fontWrapper.getCTFont().addNewSz();\r
+ }\r
+ else{\r
+ fontSize=CTFontSize.Factory.newInstance();\r
+ }\r
+ fontSize.setVal(height*20);\r
+ fontWrapper.setSz(fontSize);\r
}\r
\r
+\r
public void setFontHeightInPoints(short height) {\r
- // TODO Auto-generated method stub\r
- \r
+ CTFontSize fontSize;\r
+ if(fontWrapper.getCTFont().getSzArray().length==0){\r
+ fontSize=fontWrapper.getCTFont().addNewSz();\r
+ }\r
+ else{\r
+ fontSize=CTFontSize.Factory.newInstance();\r
+ }\r
+\r
+ fontSize.setVal(height);\r
+ fontWrapper.setSz(fontSize);\r
}\r
\r
+\r
+\r
public void setFontName(String name) {\r
- // TODO Auto-generated method stub\r
- \r
+ CTFontName fontName;\r
+ if(fontWrapper.getCTFont().getNameArray().length==0){\r
+ fontName=fontWrapper.getCTFont().addNewName();\r
+ }\r
+ else{\r
+ fontName=CTFontName.Factory.newInstance();\r
+ }\r
+\r
+ fontName.setVal(name);\r
+ fontWrapper.setName(fontName); \r
}\r
+ \r
\r
public void setItalic(boolean italic) {\r
- // TODO Auto-generated method stub\r
- \r
+ CTBooleanProperty bool;\r
+ if(fontWrapper.getCTFont().getIArray().length==0){\r
+ bool=fontWrapper.getCTFont().addNewI(); \r
+ }\r
+ else{\r
+ bool=CTBooleanProperty.Factory.newInstance();\r
+ }\r
+\r
+ bool.setVal(italic);\r
+ fontWrapper.setI(bool);\r
}\r
\r
public void setStrikeout(boolean strikeout) {\r
- // TODO Auto-generated method stub\r
- \r
+ CTBooleanProperty strike;\r
+ if(fontWrapper.getCTFont().getStrikeArray().length==0){\r
+ strike=fontWrapper.getCTFont().addNewStrike();\r
+ }\r
+ else{\r
+ strike=CTBooleanProperty.Factory.newInstance();\r
+ }\r
+ strike.setVal(strikeout);\r
+ fontWrapper.setStrike(strike);\r
}\r
\r
public void setTypeOffset(short offset) {\r
- // TODO Auto-generated method stub\r
- \r
+ CTVerticalAlignFontProperty offsetProperty;\r
+ if(fontWrapper.getCTFont().getVertAlignArray().length==0){\r
+ offsetProperty=fontWrapper.getCTFont().addNewVertAlign(); \r
+ }\r
+ else{\r
+ offsetProperty=CTVerticalAlignFontProperty.Factory.newInstance();\r
+ }\r
+ switch (offset) {\r
+ case Font.SS_NONE:\r
+ offsetProperty.setVal(STVerticalAlignRun.BASELINE);\r
+ break;\r
+ case Font.SS_SUB:\r
+ offsetProperty.setVal(STVerticalAlignRun.SUBSCRIPT);\r
+ break;\r
+ case Font.SS_SUPER:\r
+ offsetProperty.setVal(STVerticalAlignRun.SUPERSCRIPT);\r
+ break;\r
+ }\r
+ fontWrapper.setVertAlign(offsetProperty);\r
}\r
\r
public void setUnderline(byte underline) {\r
- // TODO Auto-generated method stub\r
- \r
+ CTUnderlineProperty ctUnderline;\r
+ if(fontWrapper.getCTFont().getUArray().length==0){\r
+ ctUnderline=fontWrapper.getCTFont().addNewU();\r
+ }\r
+ else{\r
+ ctUnderline=CTUnderlineProperty.Factory.newInstance();\r
+ }\r
+ switch (underline) {\r
+ case Font.U_DOUBLE:\r
+ ctUnderline.setVal(STUnderlineValues.DOUBLE); \r
+ break;\r
+ case Font.U_DOUBLE_ACCOUNTING:\r
+ ctUnderline.setVal(STUnderlineValues.DOUBLE_ACCOUNTING); \r
+ break;\r
+ case Font.U_SINGLE_ACCOUNTING:\r
+ ctUnderline.setVal(STUnderlineValues.SINGLE_ACCOUNTING); \r
+ break;\r
+ case Font.U_NONE:\r
+ ctUnderline.setVal(STUnderlineValues.NONE); \r
+ break;\r
+\r
+ case Font.U_SINGLE:\r
+ default:\r
+ ctUnderline.setVal(STUnderlineValues.SINGLE);\r
+ break;\r
+ }\r
+\r
+ fontWrapper.setU(ctUnderline);\r
}\r
- \r
+\r
+\r
public long putFont(LinkedList<CTFont> fonts) {\r
+ //TODO\r
+ /*\r
+ * we need to implement a method equals to check that 2 instances of CTFont\r
+ * are different by comparison of all font attributes.\r
+ * NB: take a look to findFont method in XSSFWorkbook\r
+ */\r
+ CTFont font=fontWrapper.getCTFont();\r
if(fonts.contains(font)) {\r
return fonts.indexOf(font);\r
}\r
return fonts.size() - 1;\r
}\r
\r
+ // solo di xssfFont - non di Font-\r
+ //sono utilizzati nel metodo createDefaultFont in StylesTable insta.\r
+\r
+ public int getScheme(){\r
+ int fontScheme = fontWrapper.getFontScheme().getVal().intValue();\r
+ switch (fontScheme) {\r
+ case STFontScheme.INT_MAJOR:\r
+ return XSSFFont.SCHEME_MAJOR; \r
+ case STFontScheme.INT_MINOR:\r
+ return XSSFFont.SCHEME_MINOR;\r
+ case STFontScheme.INT_NONE:\r
+ return XSSFFont.SCHEME_NONE;\r
+\r
+ default:\r
+ return fontScheme;\r
+ } \r
+ }\r
+\r
+\r
+ public void setScheme(int scheme){\r
+ CTFontScheme ctFontScheme;\r
+ if(fontWrapper.getCTFont().getSchemeArray().length==0){\r
+ ctFontScheme=fontWrapper.getCTFont().addNewScheme();\r
+ }\r
+ else{\r
+ ctFontScheme=CTFontScheme.Factory.newInstance();\r
+ }\r
+ switch (scheme) {\r
+ case XSSFFont.SCHEME_MAJOR:\r
+ ctFontScheme.setVal(STFontScheme.MAJOR);\r
+ break;\r
+ case XSSFFont.SCHEME_MINOR:\r
+ ctFontScheme.setVal(STFontScheme.MINOR);\r
+ break;\r
+ case XSSFFont.SCHEME_NONE:\r
+ ctFontScheme.setVal(STFontScheme.NONE);\r
+ break;\r
+ default:\r
+ throw new RuntimeException("Schema value ["+ scheme +"] not supported in XSSFFont");\r
+ }\r
+\r
+ fontWrapper.setFontScheme(ctFontScheme);\r
+ } \r
+\r
+\r
+\r
+ public int getFamily(){\r
+ if(fontWrapper.getFamily()!=null)\r
+ return fontWrapper.getFamily().getVal();\r
+ else\r
+ return XSSFFont.FONT_FAMILY_SWISS;\r
+ }\r
+\r
+ public void setFamily(int value){\r
+ //TODO\r
+ CTIntProperty family;\r
+ if(fontWrapper.getCTFont().getSchemeArray().length==0){\r
+ family=fontWrapper.getCTFont().addNewFamily();\r
+ }\r
+ else{\r
+ family=CTIntProperty.Factory.newInstance();\r
+ }\r
+ family.setVal(value);\r
+ //fontWrapper.setFamily\r
+ } \r
+\r
+\r
+\r
}\r
this.row.setHidden(height);
}
+
+ public CTRow getCTRow(){
+ return this.row;
+ }
}
import org.openxml4j.opc.PackagePart;
import org.openxml4j.opc.PackageRelationship;
import org.openxml4j.opc.PackageRelationshipCollection;
+import org.openxmlformats.schemas.drawingml.x2006.chart.CTBoolean;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBreak;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCol;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTControls;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCustomProperties;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHeaderFooter;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTHyperlink;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCell;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTMergeCells;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTOutlinePr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageBreak;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageMargins;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetUpPr;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPageSetup;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPane;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPrintOptions;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRecord;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSelection;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetData;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetFormatPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetPr;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetProtection;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetView;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheetViews;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STSheetState;
public class XSSFSheet implements Sheet {
protected XSSFWorkbook workbook;
protected CommentsSource sheetComments;
protected CTMergeCells ctMergeCells;
+
+
protected ArrayList<Drawing> drawings;
protected ArrayList<Control> controls;
+
public static final short LeftMargin = 0;
public static final short RightMargin = 1;
public static final short TopMargin = 2;
}
public boolean getRowSumsBelow() {
- // TODO Auto-generated method stub
- return false;
+ CTSheetPr sheetPr = getSheetTypeSheetPr();
+ CTOutlinePr outLinePr = sheetPr.getOutlinePr();
+ return outLinePr.getSummaryBelow();
}
public boolean getRowSumsRight() {
- // TODO Auto-generated method stub
- return false;
+ CTSheetPr sheetPr = getSheetTypeSheetPr();
+ CTOutlinePr outLinePr = sheetPr.getOutlinePr();
+ return outLinePr.getSummaryRight();
}
public boolean getScenarioProtect() {
return getSheetTypePrintOptions().getVerticalCentered();
}
+
public void groupColumn(short fromColumn, short toColumn) {
- // TODO Auto-generated method stub
-
+ CTCols ctCols=worksheet.getColsArray(0);
+ CTCol ctCol=CTCol.Factory.newInstance();
+ ctCol.setMin(fromColumn);
+ ctCol.setMax(toColumn);
+ this.columnHelper.addCleanColIntoCols(ctCols, ctCol);
+ for(int index=fromColumn;index<=toColumn;index++){
+ CTCol col=columnHelper.getColumn(index, false);
+ //col must exist
+ short outlineLevel=col.getOutlineLevel();
+ col.setOutlineLevel((short)(outlineLevel+1));
+ index=(int)col.getMax();
+ }
+ worksheet.setColsArray(0,ctCols);
+ setSheetFormatPrOutlineLevelCol();
}
public void groupRow(int fromRow, int toRow) {
- // TODO Auto-generated method stub
-
+ for(int i=fromRow;i<=toRow;i++){
+ XSSFRow xrow=(XSSFRow)getRow(i-1);
+ if(xrow==null){//create a new Row
+ xrow=(XSSFRow)createRow(i-1);
+ }
+ CTRow ctrow=xrow.getCTRow();
+ short outlineLevel=ctrow.getOutlineLevel();
+ ctrow.setOutlineLevel((short)(outlineLevel+1));
+ }
+ setSheetFormatPrOutlineLevelRow();
+ }
+
+ private short getMaxOutlineLevelRows(){
+ short outlineLevel=0;
+ for(Row r:rows){
+ XSSFRow xrow=(XSSFRow)r;
+ outlineLevel=xrow.getCTRow().getOutlineLevel()>outlineLevel? xrow.getCTRow().getOutlineLevel(): outlineLevel;
+ }
+ return outlineLevel;
}
+
+
+ private short getMaxOutlineLevelCols(){
+ CTCols ctCols=worksheet.getColsArray(0);
+ CTCol[]colArray=ctCols.getColArray();
+ short outlineLevel=0;
+ for(CTCol col: colArray){
+ outlineLevel=col.getOutlineLevel()>outlineLevel? col.getOutlineLevel(): outlineLevel;
+ }
+ return outlineLevel;
+ }
public boolean isColumnBroken(short column) {
CTBreak[] brkArray = getSheetTypeColumnBreaks().getBrkArray();
public void removeRow(Row row) {
int counter = 0;
+ int rowNum=row.getRowNum();
for (Iterator<Row> it = rowIterator() ; it.hasNext() ; ) {
Row r = it.next();
- if (r.getRowNum() == row.getRowNum()) {
+ if (r.getRowNum() == rowNum) {
it.remove();
worksheet.getSheetData().removeRow(counter);
}
}
public void setDialog(boolean b) {
- // TODO Auto-generated method stub
+ if(b && dialogsheet == null){
+ CTDialogsheet dialogSheet = CTDialogsheet.Factory.newInstance();
+ dialogsheet = dialogSheet;
+ }else{
+ dialogsheet = null;
+ }
}
public void setDisplayFormulas(boolean show) {
}
public void setRowSumsBelow(boolean b) {
- // TODO Auto-generated method stub
-
+ CTSheetPr sheetPr = getSheetTypeSheetPr();
+ CTOutlinePr outLinePr = sheetPr.getOutlinePr();
+ outLinePr.setSummaryBelow(b);
}
public void setRowSumsRight(boolean b) {
- // TODO Auto-generated method stub
-
+ CTSheetPr sheetPr = getSheetTypeSheetPr();
+ CTOutlinePr outLinePr = sheetPr.getOutlinePr();
+ outLinePr.setSummaryRight(b);
}
public void setVerticallyCenter(boolean value) {
getSheetTypeSheetView().setTopLeftCell(cellRef);
}
- public void ungroupColumn(short fromColumn, short toColumn) {
- // TODO Auto-generated method stub
-
+public void ungroupColumn(short fromColumn, short toColumn) {
+ CTCols cols=worksheet.getColsArray(0);
+ for(int index=fromColumn;index<=toColumn;index++){
+ CTCol col=columnHelper.getColumn(index, false);
+ if(col!=null){
+ short outlineLevel=col.getOutlineLevel();
+ col.setOutlineLevel((short)(outlineLevel-1));
+ index=(int)col.getMax();
+
+ if(col.getOutlineLevel()<=0){
+ int colIndex=columnHelper.getIndexOfColumn(cols,col);
+ worksheet.getColsArray(0).removeCol(colIndex);
+ }
+ }
+ }
+ worksheet.setColsArray(0,cols);
+ setSheetFormatPrOutlineLevelCol();
}
public void ungroupRow(int fromRow, int toRow) {
- // TODO Auto-generated method stub
-
+ for(int i=fromRow;i<=toRow;i++){
+ XSSFRow xrow=(XSSFRow)getRow(i-1);
+ if(xrow!=null){
+ CTRow ctrow=xrow.getCTRow();
+ short outlinelevel=ctrow.getOutlineLevel();
+ ctrow.setOutlineLevel((short)(outlinelevel-1));
+ //remove a row only if the row has no cell and if the outline level is 0
+ if(ctrow.getOutlineLevel()==0 && xrow.getFirstCellNum()==-1){
+ removeRow(xrow);
+ }
+ }
+ }
+ setSheetFormatPrOutlineLevelRow();
}
+ private void setSheetFormatPrOutlineLevelRow(){
+ short maxLevelRow=getMaxOutlineLevelRows();
+ getSheetTypeSheetFormatPr().setOutlineLevelRow((short)(maxLevelRow));
+ }
+
+ private void setSheetFormatPrOutlineLevelCol(){
+ short maxLevelCol=getMaxOutlineLevelCols();
+ getSheetTypeSheetFormatPr().setOutlineLevelCol((short)(maxLevelCol));
+ }
+
public void setSelected(boolean flag) {
CTSheetViews views = getSheetTypeSheetViews();
for (CTSheetView view : views.getSheetViewArray()) {
}
return getDefaultSheetView().getPane();
}
+
+
+
+
+
}
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedName;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDefinedNames;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDialogsheet;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
}
public Font createFont() {
- // TODO Auto-generated method stub
- return null;
+ return new XSSFFont();
}
public XSSFName createName() {
}
public Font findFont(short boldWeight, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline) {
- // TODO Auto-generated method stub
- return null;
+ short fontNum=getNumberOfFonts();
+ for (short i = 0; i <= fontNum; i++) {
+ XSSFFont xssfFont = (XSSFFont)getFontAt(i);
+ if (xssfFont.getBoldweight() == boldWeight
+ && xssfFont.getColor() == color
+ && xssfFont.getFontHeightInPoints() == fontHeight
+ && xssfFont.getFontName().equals(name)
+ && xssfFont.getItalic() == italic
+ && xssfFont.getStrikeout() == strikeout
+ && xssfFont.getTypeOffset() == typeOffset
+ && xssfFont.getUnderline() == underline)
+ {
+ return xssfFont;
+ }
+ }
+ return null;
}
public List getAllEmbeddedObjects() {
}
public CellStyle getCellStyleAt(short idx) {
- // TODO Auto-generated method stub
- return null;
+ return stylesSource.getStyleAt(idx);
}
public Palette getCustomPalette() {
return null;
}
+ /**
+ * get the first tab that is displayed in the list of tabs in excel.
+ */
+ public int getFirstVisibleTab() {
+ CTBookViews bookViews = workbook.getBookViews();
+ CTBookView bookView = bookViews.getWorkbookViewArray(0);
+ return (short) bookView.getActiveTab();
+ }
+ /**
+ * deprecated Aug 2008
+ * @deprecated - Misleading name - use getFirstVisibleTab()
+ */
public short getDisplayedTab() {
- // TODO Auto-generated method stub
- return 0;
+ return (short) getFirstVisibleTab();
}
public Font getFontAt(short idx) {
- // TODO Auto-generated method stub
- return null;
+ return stylesSource.getFontAt(idx);
}
public XSSFName getNameAt(int index) {
return null;
}
- public short getNumCellStyles() {
- // TODO Auto-generated method stub
- return 0;
+ public short getNumCellStyles() {
+ return (short) ((StylesTable)stylesSource).getNumCellStyles();
}
public short getNumberOfFonts() {
}
+ /**
+ * sets the first tab that is displayed in the list of tabs
+ * in excel.
+ * @param index
+ */
+ public void setFirstVisibleTab(short index) {
+ CTBookViews bookViews = workbook.getBookViews();
+ CTBookView bookView= bookViews.getWorkbookViewArray(0);
+ bookView.setActiveTab(index);
+ }
+ /**
+ * deprecated Aug 2008
+ * @deprecated - Misleading name - use setFirstVisibleTab()
+ */
public void setDisplayedTab(short index) {
- // TODO Auto-generated method stub
-
+ setFirstVisibleTab(index);
}
public void setPrintArea(int sheetIndex, String reference) {
\r
import java.util.LinkedList;\r
\r
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;\r
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;\r
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTPatternFill;\r
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType.Enum;\r
public CTFill getCTFill() {\r
return this.fill;\r
}\r
+ public void setFillBackgroundColor(long index) {\r
+ CTColor ctColor=fill.getPatternFill().addNewBgColor();\r
+ ctColor.setIndexed(index);\r
+ fill.getPatternFill().setBgColor(ctColor);\r
+ }\r
\r
+ public void setFillForegroundColor(long index) {\r
+ CTColor ctColor=fill.getPatternFill().addNewFgColor();\r
+ ctColor.setIndexed(index);\r
+ fill.getPatternFill().setFgColor(ctColor);\r
+ }\r
}\r
* Insert a new CTCol at position 0 into cols, setting min=min, max=max and
* copying all the colsWithAttributes array cols attributes into newCol
*/
- private CTCol insertCol(CTCols cols, long min, long max,
- CTCol[] colsWithAttributes) {
- CTCol newCol = cols.insertNewCol(0);
- newCol.setMin(min);
- newCol.setMax(max);
- for (CTCol col : colsWithAttributes) {
- setColumnAttributes(col, newCol);
+ private CTCol insertCol(CTCols cols, long min, long max,
+ CTCol[] colsWithAttributes) {
+ if(!columnExists(cols,min,max)){
+ CTCol newCol = cols.insertNewCol(0);
+ newCol.setMin(min);
+ newCol.setMax(max);
+ for (CTCol col : colsWithAttributes) {
+ setColumnAttributes(col, newCol);
+ }
+ return newCol;
}
- return newCol;
+ return null;
}
public boolean columnExists(CTCols cols, long index) {
toCol.setHidden(fromCol.getHidden());
toCol.setBestFit(fromCol.getBestFit());
toCol.setStyle(fromCol.getStyle());
+ if(fromCol.getOutlineLevel()!=0){
+ toCol.setOutlineLevel(fromCol.getOutlineLevel());
+ }
}
public void setColBestFit(long index, boolean bestFit) {
}
return -1;
}
-
+
+ private boolean columnExists(CTCols cols, long min, long max) {
+ for (int i = 0; i < cols.sizeOfColArray(); i++) {
+ if (cols.getColArray(i).getMin() == min && cols.getColArray(i).getMax() == max) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public int getIndexOfColumn(CTCols cols, CTCol col) {
+ for (int i = 0; i < cols.sizeOfColArray(); i++) {
+ if (cols.getColArray(i).getMin() == col.getMin() && cols.getColArray(i).getMax() == col.getMax()) {
+ return i;
+ }
+ }
+ return -1;
+ }
}
--- /dev/null
+package org.apache.poi.xssf.util;
+
+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;
+
+/*
+ * The font element in xml is definited like <choice maxOccurs="unbounded">.
+ * So in the java object CTFont all methods get and set returns an array of elements also if there is always defined
+ * only one type of attribute per type.
+ * This class is made to make simple using method get and set instead of getArray() or set(index,object).
+ * We consider always the index 0 like the only one index to refer of CT_Font attribute.
+ *
+ */
+
+
+public class CTFontWrapper{
+
+ private CTFont font;
+
+
+ public CTFontWrapper(CTFont font){
+ this.font=font;
+ }
+
+ public CTFont getCTFont(){
+ return font;
+ }
+
+
+ public CTBooleanProperty getB(){
+ if( font.getBArray().length>0)
+ return font.getBArray(0);
+ else
+ return null;
+ }
+
+
+ public CTIntProperty getCharset(){
+ if(font.getCharsetArray().length>0)
+ return font.getCharsetArray(0);
+ else
+ return null;
+ }
+
+ public CTColor getColor(){
+ if(font.getColorArray().length>0)
+ return font.getColorArray(0);
+ else
+ return null;
+ }
+
+ public CTBooleanProperty getStrike(){
+ if(font.getStrikeArray().length>0)
+ return font.getStrikeArray(0);
+ else
+ return null;
+ }
+
+ public CTVerticalAlignFontProperty getVertAlign() {
+ if(font.getVertAlignArray().length>0)
+ return font.getVertAlignArray(0);
+ else
+ return null;
+ }
+
+ public CTFontName setName(){
+ if(font.getNameArray().length>0)
+ return font.getNameArray(0);
+ else
+ return null;
+ }
+
+ public CTFontSize getSz(){
+ if(font.getSzArray().length>0)
+ return font.getSzArray(0);
+ else
+ return null;
+ }
+
+ public CTBooleanProperty getI(){
+ if(font.getIArray().length>0)
+ return font.getIArray(0);
+ else
+ return null;
+ }
+
+
+
+ public CTUnderlineProperty getU(){
+ if(font.getUArray().length>0)
+ return font.getUArray(0);
+ else
+ return null;
+ }
+
+ public void setB(CTBooleanProperty value){
+ font.setBArray(0,value);
+ }
+
+ public void setCharset(CTIntProperty value){
+ font.setCharsetArray(0, value);
+ }
+
+ public void setColor(CTColor value){
+ font.setColorArray(0,value);
+ }
+
+ public void setFontName(CTFontName value){
+ font.setNameArray(0,value);
+ }
+
+ public void setSz(CTFontSize value){
+ font.setSzArray(0,value);
+ }
+ public void setI(CTBooleanProperty value){
+ font.setIArray(0,value);
+ }
+
+ public void setU(CTUnderlineProperty value){
+ font.setUArray(0,value);
+ }
+
+
+ public void setStrike(CTBooleanProperty value){
+ font.setStrikeArray(0,value);
+ }
+
+
+ public void setVertAlign(CTVerticalAlignFontProperty value){
+ font.setVertAlignArray(0,value);
+ }
+
+
+ public void setName(CTFontName fontName) {
+ font.setNameArray(0,fontName);
+ }
+
+ public CTFontName getName() {
+ return font.getNameArray(0);
+ }
+
+ public CTIntProperty getFamily() {
+ return font.getFamilyArray(0);
+ }
+
+ public void setFamily(CTIntProperty family) {
+ font.setFamilyArray(0,family);
+ }
+
+
+ public void setFontScheme(CTFontScheme ctFontScheme) {
+ font.setSchemeArray(0,ctFontScheme);
+ }
+
+ public CTFontScheme getFontScheme() {
+ return font.getSchemeArray(0);
+ }
+
+ // methods used in FontFormatting
+
+ public CTBooleanProperty getOutline(){
+ return font.getOutlineArray(0);
+ }
+
+
+
+}
+
+
\ No newline at end of file
--- /dev/null
+package org.apache.poi.xssf.util;
+
+public class Charset {
+
+ public static final int ANSI_CHARSET=0;
+ public static final int DEFAULT_CHARSET=1;
+ public static final int SYMBOL_CHARSET=2;
+ public static final int MAC_CHARSET=77;
+ public static final int SHIFTJIS_CHARSET=128;
+ public static final int HANGEUL_CHARSET=129;
+ public static final int HANGUL_CHARSET=129;
+ public static final int JOHAB_CHARSET=130;
+ public static final int GB2312_CHARSET=134;
+ public static final int CHINESEBIG5_CHARSET=136;
+ public static final int GREEK_CHARSET=161;
+ public static final int TURKISH_CHARSET=162;
+ public static final int VIETNAMESE_CHARSET=163;
+ public static final int HEBREW_CHARSET=177;
+ public static final int ARABIC_CHARSET=178;
+ public static final int BALTIC_CHARSET=186;
+ public static final int RUSSIAN_CHARSET=204;
+ public static final int THAI_CHARSET=222;
+ public static final int EASTEUROPE_CHARSET=238;
+ public static final int OEM_CHARSET=255;
+
+
+}
--- /dev/null
+package org.apache.poi.xssf.util;
+
+public class IndexedColors {
+
+ public static int BLACK=0;
+ public static int WHITE=1;
+ public static int RED=2;
+ public static int GREEN=3;
+ public static int BLUE=4;
+ public static int YELLOW=5;
+ public static int PINK=6;
+
+ public static int LIGHT_GREY=22;
+ public static int DARK_GREY=23;
+
+}
import org.apache.poi.xssf.model.TestCommentsTable;
import org.apache.poi.xssf.model.TestStylesTable;
import org.apache.poi.xssf.usermodel.AllXSSFUsermodelTests;
+import org.apache.poi.xssf.usermodel.TestXSSFFont;
+import org.apache.poi.xssf.usermodel.TestXSSFSheet;
+import org.apache.poi.xssf.usermodel.TestXSSFWorkbook;
import org.apache.poi.xssf.util.TestCTColComparator;
import org.apache.poi.xssf.util.TestNumericRanges;
public static Test suite() {
TestSuite result = new TestSuite(AllXSSFTests.class.getName());
result.addTest(AllXSSFUsermodelTests.suite());
-
result.addTestSuite(TestXSSFReader.class);
result.addTestSuite(TestXSSFExcelExtractor.class);
result.addTestSuite(TestLoadSaveXSSF.class);
result.addTestSuite(TestStylesTable.class);
result.addTestSuite(TestCellReference.class);
result.addTestSuite(TestCTColComparator.class);
- result.addTestSuite(TestNumericRanges.class);
+ result.addTestSuite(TestNumericRanges.class);
return result;
}
}
result.addTestSuite(TestXSSFRow.class);
result.addTestSuite(TestXSSFSheet.class);
result.addTestSuite(TestXSSFWorkbook.class);
+
+ result.addTestSuite(TestXSSFFont.class);
+
return result;
}
}
import junit.framework.TestCase;
+import org.apache.poi.ss.usermodel.StylesSource;
import org.apache.poi.xssf.model.StylesTable;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
import org.apache.poi.xssf.usermodel.extensions.XSSFColor;
import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder.BorderSide;
+import org.apache.poi.xssf.util.IndexedColors;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellXfs;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
assertEquals(8, cellStyle.getFillPattern());
}
- public void testGetFont() {
- assertNotNull(cellStyle.getFont());
+ public void testGetSetFont() {
+ assertNotNull(this.cellStyle.getFont());
+
+ StylesSource stylesSource=new StylesTable();
+ XSSFFont xssfFont=new XSSFFont();
+ xssfFont.setFontName("Arial");
+ stylesSource.putFont(xssfFont);
+ XSSFCellStyle cellStyle=new XSSFCellStyle(stylesSource);
+
+ XSSFFont xssfFont2=new XSSFFont();
+ xssfFont2.setFontName("courier");
+ xssfFont2.setFontHeightInPoints((short)10);
+
+ cellStyle.setFont(xssfFont2);
+ assertEquals(2,cellStyle.getFontIndex());
+ assertEquals(xssfFont2.getFontName(),cellStyle.getFont().getFontName());
+ assertEquals(stylesSource.getFontAt(2).getFontHeightInPoints(),cellStyle.getFont().getFontHeightInPoints());
+
+ cellStyle.setFont(xssfFont);
+ assertEquals(1,cellStyle.getFontIndex());
+
+
+ XSSFFont xssfFont3=new XSSFFont();
+ xssfFont3.setFontName("Arial");
+ cellStyle.setFont(xssfFont3);
+ assertNotSame(1,cellStyle.getFontIndex());
+
}
public void testGetSetHidden() {
assertFalse(cellXf.getAlignment().getWrapText());
}
+ public void testGetSetFillBackgroundColor() {
+ setUp();
+ CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
+ CTColor ctBgColor = ctPatternFill.addNewBgColor();
+ ctBgColor.setIndexed(IndexedColors.BLUE);
+ assertEquals(IndexedColors.BLUE, cellStyle.getFillBackgroundColor());
+
+ cellStyle.setFillBackgroundColor((short)IndexedColors.GREEN);
+ assertEquals(IndexedColors.GREEN,ctFill.getPatternFill().getBgColor().getIndexed());
+ }
+
+ public void testGetSetFillForegroundColor() {
+ setUp();
+
+ CTPatternFill ctPatternFill = ctFill.addNewPatternFill();
+ CTColor ctFgColor = ctPatternFill.addNewFgColor();
+ ctFgColor.setIndexed(5);
+ assertEquals(5, cellStyle.getFillForegroundColor());
+
+ ctFgColor.setIndexed(IndexedColors.BLUE);
+ assertEquals(IndexedColors.BLUE, cellStyle.getFillForegroundColor());
+
+ cellStyle.setFillForegroundColor((short)IndexedColors.GREEN);
+ assertEquals(IndexedColors.GREEN,ctFill.getPatternFill().getFgColor().getIndexed());
+ }
+
/**
* Cloning one XSSFCellStyle onto Another, same XSSFWorkbook
*/
--- /dev/null
+package org.apache.poi.xssf.usermodel;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Font;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.xssf.util.CTFontWrapper;
+import org.apache.poi.xssf.util.Charset;
+import org.apache.poi.xssf.util.IndexedColors;
+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.STFontScheme;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
+
+public class TestXSSFFont extends TestCase{
+
+ public void testConstructor(){
+ XSSFFont xssfFont=new XSSFFont();
+ assertNotNull(xssfFont);
+ assertNotNull(xssfFont.getCTFont());
+ }
+
+
+ public void testBoldweight(){
+ CTFont ctFont=CTFont.Factory.newInstance();
+ CTFontWrapper wrapper=new CTFontWrapper(ctFont);
+
+ CTBooleanProperty bool=wrapper.getCTFont().addNewB();
+ bool.setVal(false);
+ wrapper.setB(bool);
+
+ XSSFFont xssfFont=new XSSFFont(ctFont);
+ assertEquals(Font.BOLDWEIGHT_NORMAL, xssfFont.getBoldweight());
+
+
+ xssfFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
+ assertEquals(ctFont.getBArray().length,1);
+ assertEquals(true, ctFont.getBArray(0).getVal());
+ assertEquals(true,wrapper.getB().getVal());
+
+ }
+
+ public void testCharSet(){
+ CTFont ctFont=CTFont.Factory.newInstance();
+ CTFontWrapper wrapper=new CTFontWrapper(ctFont);
+ CTIntProperty prop=ctFont.addNewCharset();
+ prop.setVal(Charset.ANSI_CHARSET);
+
+ wrapper.setCharset(prop);
+ XSSFFont xssfFont=new XSSFFont(ctFont);
+ assertEquals(Font.ANSI_CHARSET,xssfFont.getCharSet());
+
+ xssfFont.setCharSet(Font.DEFAULT_CHARSET);
+ assertEquals(Charset.DEFAULT_CHARSET, wrapper.getCharset().getVal());
+ }
+
+
+ public void testFontName(){
+ CTFont ctFont=CTFont.Factory.newInstance();
+ CTFontWrapper wrapper=new CTFontWrapper(ctFont);
+ CTFontName fname=ctFont.addNewName();
+ fname.setVal("Arial");
+ wrapper.setFontName(fname);
+
+ XSSFFont xssfFont=new XSSFFont(ctFont);
+ assertEquals("Arial", xssfFont.getFontName());
+
+ xssfFont.setFontName("Courier");
+ assertEquals("Courier",wrapper.getName().getVal());
+ }
+
+
+ public void testItalic(){
+ CTFont ctFont=CTFont.Factory.newInstance();
+ CTFontWrapper wrapper=new CTFontWrapper(ctFont);
+
+ CTBooleanProperty bool=wrapper.getCTFont().addNewI();
+ bool.setVal(false);
+ wrapper.setI(bool);
+
+ XSSFFont xssfFont=new XSSFFont(ctFont);
+ assertEquals(false, xssfFont.getItalic());
+
+ xssfFont.setItalic(true);
+ assertEquals(ctFont.getIArray().length,1);
+ assertEquals(true, ctFont.getIArray(0).getVal());
+ assertEquals(true,wrapper.getI().getVal());
+ }
+
+
+ public void testStrikeout(){
+ CTFont ctFont=CTFont.Factory.newInstance();
+ CTFontWrapper wrapper=new CTFontWrapper(ctFont);
+
+ CTBooleanProperty bool=wrapper.getCTFont().addNewStrike();
+ bool.setVal(false);
+ wrapper.setStrike(bool);
+
+ XSSFFont xssfFont=new XSSFFont(ctFont);
+ assertEquals(false, xssfFont.getStrikeout());
+
+ xssfFont.setStrikeout(true);
+ assertEquals(ctFont.getStrikeArray().length,1);
+ assertEquals(true, ctFont.getStrikeArray(0).getVal());
+ assertEquals(true,wrapper.getStrike().getVal());
+ }
+
+
+ public void testFontHeight(){
+ CTFont ctFont=CTFont.Factory.newInstance();
+ CTFontWrapper wrapper=new CTFontWrapper(ctFont);
+ CTFontSize size=ctFont.addNewSz();
+ size.setVal(11);
+ wrapper.setSz(size);
+
+ XSSFFont xssfFont=new XSSFFont(ctFont);
+ assertEquals(11/20,xssfFont.getFontHeight());
+
+ xssfFont.setFontHeight((short)20);
+ assertEquals(new Double(20*20).doubleValue(),wrapper.getSz().getVal()); }
+
+
+ public void testFontHeightInPoint(){
+ CTFont ctFont=CTFont.Factory.newInstance();
+ CTFontWrapper wrapper=new CTFontWrapper(ctFont);
+ CTFontSize size=ctFont.addNewSz();
+ size.setVal(14);
+ wrapper.setSz(size);
+
+ XSSFFont xssfFont=new XSSFFont(ctFont);
+ assertEquals(14,xssfFont.getFontHeightInPoints());
+
+ xssfFont.setFontHeightInPoints((short)20);
+ assertEquals(new Double(20).doubleValue(),wrapper.getSz().getVal());
+ }
+
+
+ public void testUnderline(){
+ CTFont ctFont=CTFont.Factory.newInstance();
+ CTFontWrapper wrapper=new CTFontWrapper(ctFont);
+
+ CTUnderlineProperty underlinePropr=wrapper.getCTFont().addNewU();
+ underlinePropr.setVal(STUnderlineValues.SINGLE);
+ wrapper.setU(underlinePropr);
+
+ XSSFFont xssfFont=new XSSFFont(ctFont);
+ assertEquals(Font.U_SINGLE, xssfFont.getUnderline());
+
+ xssfFont.setUnderline(Font.U_DOUBLE);
+ assertEquals(ctFont.getUArray().length,1);
+ assertEquals(STUnderlineValues.DOUBLE,wrapper.getU().getVal());
+ }
+
+ public void testColor(){
+ CTFont ctFont=CTFont.Factory.newInstance();
+ CTFontWrapper wrapper=new CTFontWrapper(ctFont);
+ CTColor color=ctFont.addNewColor();
+ //color.setIndexed(IndexedColors.DEFAULT_COLOR);
+ color.setIndexed(XSSFFont.DEFAULT_FONT_COLOR);
+ wrapper.setColor(color);
+
+ XSSFFont xssfFont=new XSSFFont(ctFont);
+ assertEquals(Font.COLOR_NORMAL,xssfFont.getColor());
+
+ xssfFont.setColor(Font.COLOR_RED);
+ assertEquals(IndexedColors.RED,wrapper.getColor().getIndexed());
+ }
+
+
+ public void testFamily(){
+ CTFont ctFont=CTFont.Factory.newInstance();
+ CTFontWrapper wrapper=new CTFontWrapper(ctFont);
+ CTIntProperty family=ctFont.addNewFamily();
+ family.setVal(XSSFFont.FONT_FAMILY_MODERN);
+ wrapper.setFamily(family);
+
+ XSSFFont xssfFont=new XSSFFont(ctFont);
+ assertEquals(XSSFFont.FONT_FAMILY_MODERN,xssfFont.getFamily());
+
+ }
+
+
+ public void testScheme(){
+ CTFont ctFont=CTFont.Factory.newInstance();
+ CTFontWrapper wrapper=new CTFontWrapper(ctFont);
+ CTFontScheme scheme=ctFont.addNewScheme();
+ scheme.setVal(STFontScheme.MAJOR);
+ wrapper.setFontScheme(scheme);
+
+ XSSFFont font=new XSSFFont(ctFont);
+ assertEquals(XSSFFont.SCHEME_MAJOR,font.getScheme());
+
+ font.setScheme(XSSFFont.SCHEME_NONE);
+ assertEquals(STFontScheme.NONE,wrapper.getFontScheme().getVal());
+ }
+
+ public void testTypeOffset(){
+ CTFont ctFont=CTFont.Factory.newInstance();
+ CTFontWrapper wrapper=new CTFontWrapper(ctFont);
+ CTVerticalAlignFontProperty valign=ctFont.addNewVertAlign();
+ valign.setVal(STVerticalAlignRun.BASELINE);
+ wrapper.setVertAlign(valign);
+
+ XSSFFont font=new XSSFFont(ctFont);
+ assertEquals(Font.SS_NONE,font.getTypeOffset());
+
+ font.setTypeOffset(XSSFFont.SS_SUPER);
+ assertEquals(STVerticalAlignRun.SUPERSCRIPT,wrapper.getVertAlign().getVal());
+ }
+
+
+ public void testXSSFFont() throws IOException{
+ XSSFWorkbook workbook=new XSSFWorkbook();
+ //Font font1=workbook.createFont();
+
+ Sheet sheet=workbook.createSheet("sheet 1 - test font");
+
+
+ Row row=sheet.createRow(0);
+ Cell cell=row.createCell(0);
+ cell.setCellValue(new XSSFRichTextString("XSSFFont test example file"));
+ Font font=new XSSFFont();
+ font.setBoldweight(Font.BOLDWEIGHT_BOLD);
+ font.setFontHeightInPoints((short)22);
+ font.setColor((short)IndexedColors.BLUE);
+ font.setFontName("Verdana");
+ CellStyle cellStyleTitle=workbook.createCellStyle();
+ cellStyleTitle.setFont(font);
+ cell.setCellStyle(cellStyleTitle);
+
+
+ row=sheet.createRow(3);
+ Font font1=new XSSFFont();
+ font1.setBoldweight(Font.BOLDWEIGHT_BOLD);
+ font1.setItalic(true);
+ font1.setFontHeightInPoints((short)18);
+ font1.setColor(Font.COLOR_RED);
+ font1.setFontName("Arial");
+ CellStyle cellStyle1=workbook.createCellStyle();
+ cellStyle1.setFont(font1);
+
+ Cell cell1=row.createCell(0);
+ cell1.setCellValue(new XSSFRichTextString("red bold 18pt italic Arial"));
+ cell1.setCellStyle(cellStyle1);
+
+
+ row=sheet.createRow(4);
+ Font font2=new XSSFFont();
+ font2.setFontHeight((short)1);
+ font2.setFontName("Courier");
+ font2.setColor(Font.COLOR_NORMAL);
+ font2.setUnderline(Font.U_DOUBLE);
+ CellStyle cellStyle2=workbook.createCellStyle();
+ cellStyle2.setFont(font2);
+
+ Cell cell2=row.createCell(0);
+ cell2.setCellValue(new XSSFRichTextString("Something in courier underlined"));
+ cell2.setCellStyle(cellStyle2);
+
+
+ row=sheet.createRow(5);
+ cell1=row.createCell(0);
+ Font font3=new XSSFFont();
+ font3.setFontHeightInPoints((short)9);
+ font3.setFontName("Times");
+ font3.setStrikeout(true);
+ font3.setColor((short)IndexedColors.PINK);
+ CellStyle cellStyle3=workbook.createCellStyle();
+ cellStyle3.setFont(font3);
+
+ cell1.setCellValue(new XSSFRichTextString("pink italic Times 9pt strikeout!!!"));
+ cell1.setCellStyle(cellStyle3);
+
+ File tmpFile = new File("test-ooxml-font.xlsx");
+ if(tmpFile.exists()) tmpFile.delete();
+ FileOutputStream out = new FileOutputStream(tmpFile);
+ workbook.write(out);
+ out.close();
+ }
+
+
+}
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCols;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPane;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPaneState;
public class TestXSSFSheet extends TestCase {
row9.setHeight((short) 9);
return sheet;
}
+
+
+
+ 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);
+
+ //one level
+ System.out.println("livello 1");
+ sheet.groupColumn((short)2,(short)7);
+ sheet.groupColumn((short)10,(short)11);
+ CTCols cols=sheet.getWorksheet().getColsArray(0);
+ assertEquals(2,cols.sizeOfColArray());
+ CTCol[]colArray=cols.getColArray();
+ assertNotNull(colArray);
+ assertEquals(2,colArray[0].getMin());
+ assertEquals(7,colArray[0].getMax());
+ assertEquals(1, colArray[0].getOutlineLevel());
+
+ //two level
+ System.out.println("\n livello 2");
+ sheet.groupColumn((short)1,(short)2);
+ cols=sheet.getWorksheet().getColsArray(0);
+ assertEquals(4,cols.sizeOfColArray());
+ colArray=cols.getColArray();
+ assertEquals(2, colArray[1].getOutlineLevel());
+
+ //three level
+ System.out.println("\n livello 3");
+ sheet.groupColumn((short)6,(short)8);
+ sheet.groupColumn((short)2,(short)3);
+ cols=sheet.getWorksheet().getColsArray(0);
+ assertEquals(7,cols.sizeOfColArray());
+ colArray=cols.getColArray();
+ assertEquals(3, colArray[1].getOutlineLevel());
+ assertEquals(3,sheet.getSheetTypeSheetFormatPr().getOutlineLevelCol());
+
+ sheet.ungroupColumn((short)8,(short) 10);
+ colArray=cols.getColArray();
+ //assertEquals(3, colArray[1].getOutlineLevel());
+
+ sheet.ungroupColumn((short)4,(short)6);
+ sheet.ungroupColumn((short)2,(short)2);
+ colArray=cols.getColArray();
+ assertEquals(4, colArray.length);
+ assertEquals(2,sheet.getSheetTypeSheetFormatPr().getOutlineLevelCol());
+ }
+
+
+ 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);
+
+ //one level
+ sheet.groupRow(9,10);
+ assertEquals(2,sheet.rows.size());
+ CTRow[]rowArray=sheet.getWorksheet().getSheetData().getRowArray();
+ assertEquals(2,rowArray.length);
+ CTRow ctrow=rowArray[0];
+
+ assertNotNull(ctrow);
+ assertEquals(9,ctrow.getR());
+ assertEquals(1, ctrow.getOutlineLevel());
+ assertEquals(1,sheet.getSheetTypeSheetFormatPr().getOutlineLevelRow());
+
+ //two level
+ sheet.groupRow(10,13);
+ rowArray=sheet.getWorksheet().getSheetData().getRowArray();
+ assertEquals(5,rowArray.length);
+ assertEquals(5,sheet.rows.size());
+ ctrow=rowArray[1];
+ assertNotNull(ctrow);
+ assertEquals(10,ctrow.getR());
+ assertEquals(2, ctrow.getOutlineLevel());
+ assertEquals(2,sheet.getSheetTypeSheetFormatPr().getOutlineLevelRow());
+
+
+ sheet.ungroupRow(8, 10);
+ rowArray=sheet.getWorksheet().getSheetData().getRowArray();
+ assertEquals(4,rowArray.length);
+ assertEquals(1,sheet.getSheetTypeSheetFormatPr().getOutlineLevelRow());
+
+ sheet.ungroupRow(10,10);
+ rowArray=sheet.getWorksheet().getSheetData().getRowArray();
+ assertEquals(3,rowArray.length);
+ assertEquals(3,sheet.rows.size());
+
+ assertEquals(1,sheet.getSheetTypeSheetFormatPr().getOutlineLevelRow());
+ }
+
}
import junit.framework.TestCase;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Name;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.StylesSource;
-import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.model.StylesTable;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
-
import org.openxml4j.opc.ContentTypes;
import org.openxml4j.opc.Package;
import org.openxml4j.opc.PackagePart;
import org.openxml4j.opc.PackagingURIHelper;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTSheet;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
public class TestXSSFWorkbook extends TestCase {
public TestXSSFWorkbook(String name) {
}
+ public void testFindFont(){
+ //get dafault font and check against default value
+ XSSFWorkbook workbook = new XSSFWorkbook();
+ Font fontFind=workbook.findFont(Font.BOLDWEIGHT_NORMAL, Font.COLOR_NORMAL, (short)11, "Calibri", false, false, Font.SS_NONE, Font.U_NONE);
+ assertNotNull(fontFind);
+
+ //get default font, then change 2 values and check against different values (height changes)
+ Font font=workbook.createFont();
+ font.setBoldweight(Font.BOLDWEIGHT_BOLD);
+ font.setUnderline(Font.U_DOUBLE);
+ StylesSource styleSource=new StylesTable();
+ long index=styleSource.putFont(font);
+ System.out.println("index="+index);
+ workbook.setStylesSource(styleSource);
+ fontFind=workbook.findFont(Font.BOLDWEIGHT_BOLD, Font.COLOR_NORMAL, (short)15, "Calibri", false, false, Font.SS_NONE, Font.U_DOUBLE);
+ assertNull(fontFind);
+ }
+
+ public void testGetCellStyleAt(){
+ XSSFWorkbook workbook = new XSSFWorkbook();
+ short i = 0;
+ //get default style
+ CellStyle cellStyleAt = workbook.getCellStyleAt(i);
+ assertNotNull(cellStyleAt);
+
+ //get custom style
+ StylesSource styleSource = workbook.getStylesSource();
+ CellStyle customStyle = new XSSFCellStyle(styleSource);
+ Font font = new XSSFFont();
+ font.setFontName("Verdana");
+ customStyle.setFont(font);
+ Long x = styleSource.putStyle(customStyle);
+ cellStyleAt = workbook.getCellStyleAt(x.shortValue());
+ assertNotNull(cellStyleAt);
+ }
+
+ public void testGetFontAt(){
+ XSSFWorkbook workbook = new XSSFWorkbook();
+ StylesSource styleSource = workbook.getStylesSource();
+ short i = 0;
+ //get default font
+ Font fontAt = workbook.getFontAt(i);
+ assertNotNull(fontAt);
+
+ //get customized font
+ Font customFont = new XSSFFont();
+ customFont.setItalic(true);
+ Long x = styleSource.putFont(customFont);
+ fontAt = workbook.getFontAt(x.shortValue());
+ assertNotNull(fontAt);
+ }
+
+ public void testGetNumCellStyles(){
+ XSSFWorkbook workbook = new XSSFWorkbook();
+ short i = workbook.getNumCellStyles();
+ //get default cellStyles
+ assertEquals(1, i);
+ //get wrong value
+ assertNotSame(2, i);
+ }
+
+ public void testGetDisplayedTab(){
+ XSSFWorkbook workbook = new XSSFWorkbook();
+ short i = (short) workbook.getFirstVisibleTab();
+ //get default diplayedTab
+ assertEquals(0, i);
+ }
+
+ public void testSetDisplayedTab(){
+ XSSFWorkbook workbook = new XSSFWorkbook();
+ workbook.setFirstVisibleTab(new Integer(1).shortValue());
+ short i = (short) workbook.getFirstVisibleTab();
+ //0 (defualt value) is not longer set
+ assertNotSame(0, i);
+ //1 is the default tab
+ assertEquals(1, i);
+ }
+
+
public void testLoadSave() throws Exception {
File xml = new File(
System.getProperty("HSSF.testdata.path") +