You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2008/10/01 19:15:02 UTC

svn commit: r700844 - in /poi/branches/ooxml/src: java/org/apache/poi/ss/usermodel/ ooxml/java/org/apache/poi/xssf/usermodel/ ooxml/testcases/org/apache/poi/xssf/usermodel/

Author: yegor
Date: Wed Oct  1 10:15:02 2008
New Revision: 700844

URL: http://svn.apache.org/viewvc?rev=700844&view=rev
Log:
applied patches provided by Gisella Bronzetti in bugs #45918, #45917 and #45920

Modified:
    poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/DateUtil.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
    poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
    poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java

Modified: poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/DateUtil.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/DateUtil.java?rev=700844&r1=700843&r2=700844&view=diff
==============================================================================
--- poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/DateUtil.java (original)
+++ poi/branches/ooxml/src/java/org/apache/poi/ss/usermodel/DateUtil.java Wed Oct  1 10:15:02 2008
@@ -276,6 +276,7 @@
         double d = cell.getNumericCellValue();
         if ( DateUtil.isValidExcelDate(d) ) {
             CellStyle style = cell.getCellStyle();
+            if(style==null) return false;
             int i = style.getDataFormat();
             String f = style.getDataFormatString();
             bDate = isADateFormat(i, f);

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java?rev=700844&r1=700843&r2=700844&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCell.java Wed Oct  1 10:15:02 2008
@@ -17,10 +17,13 @@
 
 package org.apache.poi.xssf.usermodel;
 
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.Calendar;
 import java.util.Date;
 
-import org.apache.poi.hssf.usermodel.HSSFDateUtil;
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;
+import org.apache.poi.ss.usermodel.DateUtil;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Comment;
@@ -73,6 +76,7 @@
     protected SharedStringSource getSharedStringSource() {
         return this.sharedStringSource;
     }
+    
     protected StylesSource getStylesSource() {
         return this.stylesSource;
     }
@@ -154,10 +158,10 @@
         if (STCellType.N == this.cell.getT() || STCellType.STR == this.cell.getT()) {
             double value = this.getNumericCellValue();
             if (false /* book.isUsing1904DateWindowing() */) {  // FIXME
-                return HSSFDateUtil.getJavaDate(value,true);
+                return DateUtil.getJavaDate(value,true);
             }
             else {
-                return HSSFDateUtil.getJavaDate(value,false);
+                return DateUtil.getJavaDate(value,false);
             }
         }
         throw new NumberFormatException("You cannot get a date value from a cell of type " + this.cell.getT());
@@ -256,14 +260,17 @@
         }
         throw new NumberFormatException("You cannot get a string value from a non-string cell");
     }
-
+    
+    /**
+     * Sets this cell as the active cell for the worksheet
+     */
     public void setAsActiveCell() {
         row.getSheet().setActiveCell(cell.getR());
     }
 
+   
     public void setCellComment(Comment comment) {
-        String cellRef =
-            new CellReference(row.getRowNum(), getCellNum()).formatAsString();
+        String cellRef = new CellReference(row.getRowNum(), getCellNum()).formatAsString();
         row.getSheet().setCellComment(cellRef, (XSSFComment)comment);
     }
 
@@ -352,6 +359,15 @@
         }
     }
 
+    /**
+     * set the cells type (numeric, formula or string)
+     * @see #CELL_TYPE_NUMERIC
+     * @see #CELL_TYPE_STRING
+     * @see #CELL_TYPE_FORMULA
+     * @see #CELL_TYPE_BLANK
+     * @see #CELL_TYPE_BOOLEAN
+     * @see #CELL_TYPE_ERROR
+     */
     public void setCellType(int cellType) {
         switch (cellType) {
         case CELL_TYPE_BOOLEAN:
@@ -379,13 +395,38 @@
         this.cell.setV(String.valueOf(value));
     }
 
+
+    /**
+     * set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as
+     * a date.
+     *
+     * @param value  the date value to set this cell to.  For formulas we'll set the
+     *        precalculated value, for numerics we'll set its value. For other types we
+     *        will change the cell to a numeric cell and set its value.
+     */
     public void setCellValue(Date value) {
-        setCellValue(HSSFDateUtil.getExcelDate(value, false /*this.book.isUsing1904DateWindowing()*/)); // FIXME
+	    boolean date1904 = this.row.getSheet().getWorkbook().isDate1904();
+        setCellValue(DateUtil.getExcelDate(value, date1904));
     }
 
+    /**
+     * set a date value for the cell. Excel treats dates as numeric so you will need to format the cell as
+     * a date.
+     *
+     * This will set the cell value based on the Calendar's timezone. As Excel
+     * does not support timezones this means that both 20:00+03:00 and
+     * 20:00-03:00 will be reported as the same value (20:00) even that there
+     * are 6 hours difference between the two times. This difference can be
+     * preserved by using <code>setCellValue(value.getTime())</code> which will
+     * automatically shift the times to the default timezone.
+     *
+     * @param value  the date value to set this cell to.  For formulas we'll set the
+     *        precalculated value, for numerics we'll set its value. For othertypes we
+     *        will change the cell to a numeric cell and set its value.
+     */
     public void setCellValue(Calendar value) {
-        // TODO Auto-generated method stub
-
+	    boolean date1904 = this.row.getSheet().getWorkbook().isDate1904();
+        setCellValue( DateUtil.getExcelDate(value, date1904 ));
     }
 
     public void setCellValue(String str) {
@@ -414,8 +455,42 @@
         this.cell.setV(value ? TRUE_AS_STRING : FALSE_AS_STRING);
     }
 
+    /**
+     * Returns a string representation of the cell
+     *
+     * This method returns a simple representation,
+     * anthing more complex should be in user code, with
+     * knowledge of the semantics of the sheet being processed.
+     *
+     * Formula cells return the formula string,
+     * rather than the formula result.
+     * Dates are displayed in dd-MMM-yyyy format
+     * Errors are displayed as #ERR&lt;errIdx&gt;
+     */
     public String toString() {
-        return "[" + this.row.getRowNum() + "," + this.getCellNum() + "] " + this.cell.getV();
+        // return "[" + this.row.getRowNum() + "," + this.getCellNum() + "] " + this.cell.getV();
+        switch (getCellType()) {
+            case CELL_TYPE_BLANK:
+                return "";
+            case CELL_TYPE_BOOLEAN:
+                return getBooleanCellValue() ? "TRUE" : "FALSE";
+            case CELL_TYPE_ERROR:
+                return ErrorEval.getText(getErrorCellValue());
+            case CELL_TYPE_FORMULA:
+                return getCellFormula();
+            case CELL_TYPE_NUMERIC:
+                //TODO apply the dataformat for this cell
+                if (DateUtil.isCellDateFormatted(this)) {
+                    DateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
+                    return sdf.format(getDateCellValue());
+                } else {
+                    return getNumericCellValue() + "";
+                }
+            case CELL_TYPE_STRING:
+                return getRichStringCellValue().toString();
+            default:
+                return "Unknown Cell Type: " + getCellType();
+        }
     }
 
     /**
@@ -429,16 +504,15 @@
      * @throws RuntimeException if the bounds are exceeded.
      */
     private void checkBounds(int cellNum) {
-      if (cellNum > 255) {
-          throw new RuntimeException("You cannot have more than 255 columns "+
+        if (cellNum > 255) {
+            throw new RuntimeException("You cannot have more than 255 columns " +
                     "in a given row (IV).  Because Excel can't handle it");
-      }
-      else if (cellNum < 0) {
-          throw new RuntimeException("You cannot reference columns with an index of less then 0.");
-      }
+        } else if (cellNum < 0) {
+            throw new RuntimeException("You cannot reference columns with an index of less then 0.");
+        }
     }
 
-	public Hyperlink getHyperlink() {
+    public Hyperlink getHyperlink() {
 		return row.getSheet().getHyperlink(row.getRowNum(), cellNum);
 	}
 	public void setHyperlink(Hyperlink hyperlink) {

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java?rev=700844&r1=700843&r2=700844&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFFont.java Wed Oct  1 10:15:02 2008
@@ -32,336 +32,531 @@
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STUnderlineValues;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.STVerticalAlignRun;
 
+/**
+ * Represents a font used in a workbook.
+ *
+ * @author Gisella Bronzetti
+ */
 public class XSSFFont implements Font {
 
-    public static final String DEFAULT_FONT_NAME="Calibri";
-    public static final short DEFAULT_FONT_SIZE=11;
+    /**
+     * By default, Microsoft Office Excel 2007 uses the Calibry font in font size 11
+     */
+    public static final String DEFAULT_FONT_NAME = "Calibri";
+    /**
+     * By default, Microsoft Office Excel 2007 uses the Calibry font in font size 11
+     */
+    public static final short DEFAULT_FONT_SIZE = 11;
+    /**
+     * Default font color is black
+     * @see IndexedColors.BLACK
+     */
     public static final short DEFAULT_FONT_COLOR = IndexedColors.BLACK.getIndex();
 
-     private CTFont ctFont;
+    private CTFont ctFont;
 
+    /**
+     * Create a new XSSFFont
+     *
+     * @param font the underlying CTFont bean
+     */
     public XSSFFont(CTFont font) {
-         this.ctFont=font;
-    }
-
-     protected XSSFFont() {
-         this.ctFont = CTFont.Factory.newInstance();
-    }
-
-
-    public CTFont getCTFont(){
-         return ctFont;
-    }
-
-     
-     public boolean getBold() {
-         CTBooleanProperty bold=ctFont.sizeOfBArray() == 0 ? null : ctFont.getBArray(0);
-         return (bold!=null && bold.getVal());
+        this.ctFont = font;
     }
 
+    /**
+     * Create a new XSSFont. This method is protected to be used only by XSSFWorkbook
+     */
+    protected XSSFFont() {
+        this.ctFont = CTFont.Factory.newInstance();
+    }
+
+    /**
+     * get the underlying CTFont font
+     */
+    public CTFont getCTFont() {
+        return ctFont;
+    }
+
+    /**
+     * get a boolean value for the boldness to use.
+     *
+     * @return boolean - bold
+     */
+    public boolean getBold() {
+        CTBooleanProperty bold = ctFont.sizeOfBArray() == 0 ? null : ctFont.getBArray(0);
+        return (bold != null && bold.getVal());
+    }
+
+    /**
+     * get character-set to use.
+     *
+     * @return byte - character-set
+     * @see FontCharset
+     */
     public byte getCharSet() {
-         CTIntProperty charset= ctFont.sizeOfCharsetArray() == 0?null:ctFont.getCharsetArray(0);
-         return charset == null ? FontCharset.ANSI.getValue() : FontCharset.valueOf(charset.getVal()).getValue(); 
+        CTIntProperty charset = ctFont.sizeOfCharsetArray() == 0 ? null : ctFont.getCharsetArray(0);
+        return charset == null ? FontCharset.ANSI.getValue() : FontCharset.valueOf(charset.getVal()).getValue();
     }
 
+
+    /**
+     * get the indexed color value for the font
+     * References a color defined in IndexedColors.
+     *
+     * @return short - indexed color to use
+     * @see IndexedColors
+     */
     public short getColor() {
-        CTColor color=ctFont.sizeOfColorArray()==0?null: ctFont.getColorArray(0);
-        if(color == null) return IndexedColors.BLACK.getIndex();
-        
-        long index=color.getIndexed();
-        if (index==XSSFFont.DEFAULT_FONT_COLOR){
+        CTColor color = ctFont.sizeOfColorArray() == 0 ? null : ctFont.getColorArray(0);
+        if (color == null) return IndexedColors.BLACK.getIndex();
+
+        long index = color.getIndexed();
+        if (index == XSSFFont.DEFAULT_FONT_COLOR) {
             return IndexedColors.BLACK.getIndex();
-        }
-        else if(index == IndexedColors.RED.getIndex()){
+        } else if (index == IndexedColors.RED.getIndex()) {
             return IndexedColors.RED.getIndex();
-        }
-        else{
-            return Short.parseShort(new Long(index).toString());
+        } else {
+            return (short)index;
         }
     }
 
 
-     public XSSFColor getRgbColor() {
-         CTColor ctColor=ctFont.sizeOfColorArray()==0?null: ctFont.getColorArray(0);
-         XSSFColor color=new XSSFColor(ctColor);
-         return color;
-     }
-
-     public short getThemeColor() {
-         CTColor color=ctFont.sizeOfColorArray()==0?null: ctFont.getColorArray(0);
-         long index=color.getTheme();
-         return (short)index;
-     }
+    /**
+     * get the color value for the font
+     * References a color defined as  Standard Alpha Red Green Blue color value (ARGB).
+     *
+     * @return XSSFColor - rgb color to use
+     */
+    public XSSFColor getRgbColor() {
+        CTColor ctColor = ctFont.sizeOfColorArray() == 0 ? null : ctFont.getColorArray(0);
+        XSSFColor color = new XSSFColor(ctColor);
+        return color;
+    }
 
 
+    /**
+     * get the color value for the font
+     * References a color defined in theme.
+     *
+     * @return short - theme defined to use
+     */
+    public short getThemeColor() {
+        CTColor color = ctFont.sizeOfColorArray() == 0 ? null : ctFont.getColorArray(0);
+        long index = color == null ? 0 : color.getTheme();
+        return (short) index;
+    }
+
+    /**
+     * get the font height in point.
+     *
+     * @return short - height in point
+     */
     public short getFontHeight() {
-         CTFontSize size=ctFont.sizeOfSzArray()==0?null: ctFont.getSzArray(0);
-         if(size!=null){
-             double fontHeight= size.getVal();
-            return (short)fontHeight;
-        }
-        else
+        CTFontSize size = ctFont.sizeOfSzArray() == 0 ? null : ctFont.getSzArray(0);
+        if (size != null) {
+            double fontHeight = size.getVal();
+            return (short) fontHeight;
+        } else
             return DEFAULT_FONT_SIZE;
     }
 
-
+    /**
+     * @see #getFontHeight()
+     */
     public short getFontHeightInPoints() {
-         CTFontSize size=ctFont.sizeOfSzArray()==0?null: ctFont.getSzArray(0);
-         if(size!=null){
-             double fontHeight= size.getVal();
-             return (short)fontHeight;
-          }
-        else
+        CTFontSize size = ctFont.sizeOfSzArray() == 0 ? null : ctFont.getSzArray(0);
+        if (size != null) {
+            double fontHeight = size.getVal();
+            return (short) fontHeight;
+        } else
             return DEFAULT_FONT_SIZE;
     }
 
-
+    /**
+     * get the name of the font (i.e. Arial)
+     *
+     * @return String - a string representing the name of the font to use
+     */
     public String getFontName() {
-	CTFontName name = ctFont.sizeOfNameArray() == 0 ? null : ctFont.getNameArray(0);
-	return name == null ? null : name.getVal();
+        CTFontName name = ctFont.sizeOfNameArray() == 0 ? null : ctFont.getNameArray(0);
+        return name == null ? null : name.getVal();
     }
 
-
-      public boolean getItalic() {
-         CTBooleanProperty italic=ctFont.sizeOfIArray()==0?null:ctFont.getIArray(0);
-         return italic!=null && italic.getVal();
-      }
-
-      public boolean getStrikeout() {
-         CTBooleanProperty strike=ctFont.sizeOfStrikeArray()==0?null:ctFont.getStrikeArray(0);
-         return strike!=null && strike.getVal();
-      }
-
+    /**
+     * get a boolean value that specify whether to use italics or not
+     *
+     * @return boolean - value for italic
+     */
+    public boolean getItalic() {
+        CTBooleanProperty italic = ctFont.sizeOfIArray() == 0 ? null : ctFont.getIArray(0);
+        return italic != null && italic.getVal();
+    }
+
+    /**
+     * get a boolean value that specify whether to use a strikeout horizontal line through the text or not
+     *
+     * @return boolean - value for strikeout
+     */
+    public boolean getStrikeout() {
+        CTBooleanProperty strike = ctFont.sizeOfStrikeArray() == 0 ? null : ctFont.getStrikeArray(0);
+        return strike != null && strike.getVal();
+    }
+
+    /**
+     * get normal,super or subscript.
+     *
+     * @return short - offset type to use (none,super,sub)
+     * @see Font#SS_NONE
+     * @see Font#SS_SUPER
+     * @see Font#SS_SUB
+     */
     public short getTypeOffset() {
-        CTVerticalAlignFontProperty vAlign=ctFont.sizeOfVertAlignArray()==0?null:ctFont.getVertAlignArray(0);
-        if(vAlign!=null){
-            int val=vAlign.getVal().intValue();
+        CTVerticalAlignFontProperty vAlign = ctFont.sizeOfVertAlignArray() == 0 ? null : ctFont.getVertAlignArray(0);
+        if (vAlign != null) {
+            int val = vAlign.getVal().intValue();
             switch (val) {
-            case STVerticalAlignRun.INT_BASELINE:
-                return Font.SS_NONE;
-            case STVerticalAlignRun.INT_SUBSCRIPT:
-                return Font.SS_SUB;
-            case STVerticalAlignRun.INT_SUPERSCRIPT:
-                return Font.SS_SUPER;
-            default: throw new RuntimeException("Wrong offset value "+val);
+                case STVerticalAlignRun.INT_BASELINE:
+                    return Font.SS_NONE;
+                case STVerticalAlignRun.INT_SUBSCRIPT:
+                    return Font.SS_SUB;
+                case STVerticalAlignRun.INT_SUPERSCRIPT:
+                    return Font.SS_SUPER;
+                default:
+                    throw new RuntimeException("Wrong offset value " + val);
             }
-        }
-        else
+        } else
             return Font.SS_NONE;
     }
 
-     public byte getUnderline() {
-	 /*
-         CTUnderlineProperty underline = ctFont.sizeOfUArray() == 0 ? null : ctFont.getUArray(0);
-         return underline == null ? (byte)FontUnderline.NONE.getValue().intValue() : (byte)FontUnderline.valueOf(underline.getVal()).getValue().intValue();
-         */
-	    CTUnderlineProperty underline=ctFont.sizeOfUArray()==0?null:ctFont.getUArray(0);
-	        if(underline!=null){
-		    FontUnderline fontUnderline=FontUnderline.valueOf(underline.getVal());
-	             switch (fontUnderline.getValue().intValue()) {
-	            case STUnderlineValues.INT_DOUBLE:
-	                return Font.U_DOUBLE;
-	            case STUnderlineValues.INT_DOUBLE_ACCOUNTING:
-	                return Font.U_DOUBLE_ACCOUNTING;
-
-	            case STUnderlineValues.INT_SINGLE_ACCOUNTING:
-	                return Font.U_SINGLE_ACCOUNTING;
-
-	            case STUnderlineValues.INT_NONE:
-	                return Font.U_NONE;
-
-	            case STUnderlineValues.INT_SINGLE:
-	            default:
-	                return Font.U_SINGLE;
-	            }
-	        }
-	        return Font.U_NONE;
-    }
-
-     /**
-      * Set characters in bold face font style.
-      * If omitted, the default value is true.
-      */
-     public void setBold(boolean bold) {
-         CTBooleanProperty ctBold=ctFont.sizeOfBArray()==0?ctFont.addNewB():ctFont.getBArray(0);
-         ctBold.setVal(true);
-      }
+    /**
+     * get type of text underlining to use
+     *
+     * @return byte - underlining type
+     * @see FontUnderline
+     */
+    public byte getUnderline() {
+        CTUnderlineProperty underline = ctFont.sizeOfUArray() == 0 ? null : ctFont.getUArray(0);
+        if (underline != null) {
+            FontUnderline fontUnderline = FontUnderline.valueOf(underline.getVal());
+            switch (fontUnderline.getValue().intValue()) {
+                case STUnderlineValues.INT_DOUBLE:
+                    return Font.U_DOUBLE;
+                case STUnderlineValues.INT_DOUBLE_ACCOUNTING:
+                    return Font.U_DOUBLE_ACCOUNTING;
+
+                case STUnderlineValues.INT_SINGLE_ACCOUNTING:
+                    return Font.U_SINGLE_ACCOUNTING;
+
+                case STUnderlineValues.INT_NONE:
+                    return Font.U_NONE;
+
+                case STUnderlineValues.INT_SINGLE:
+                default:
+                    return Font.U_SINGLE;
+            }
+        }
+        return Font.U_NONE;
+    }
 
-     
+    /**
+     * set a boolean value for the boldness to use. If omitted, the default value is true.
+     *
+     * @param bold - boldness to use
+     */
+    public void setBold(boolean bold) {
+        CTBooleanProperty ctBold = ctFont.sizeOfBArray() == 0 ? ctFont.addNewB() : ctFont.getBArray(0);
+        ctBold.setVal(true);
+    }
+
+    /**
+     * set character-set to use.
+     *
+     * @param charset - charset
+     * @see FontCharset
+     */
     public void setCharSet(byte charset) {
-         CTIntProperty charsetProperty=ctFont.sizeOfCharsetArray()==0?ctFont.addNewCharset():ctFont.getCharsetArray(0);
+        CTIntProperty charsetProperty = ctFont.sizeOfCharsetArray() == 0 ? ctFont.addNewCharset() : ctFont.getCharsetArray(0);
         switch (charset) {
-        case Font.ANSI_CHARSET:
-            charsetProperty.setVal(FontCharset.ANSI.getValue());
-            break;
-        case Font.SYMBOL_CHARSET:
-            charsetProperty.setVal(FontCharset.SYMBOL.getValue());
-            break;
-        case Font.DEFAULT_CHARSET:
-            charsetProperty.setVal(FontCharset.DEFAULT.getValue());
-            break;
-        default:
-            throw new RuntimeException("Attention: an attempt to set a type of unknow charset and charset");
+            case Font.ANSI_CHARSET:
+                charsetProperty.setVal(FontCharset.ANSI.getValue());
+                break;
+            case Font.SYMBOL_CHARSET:
+                charsetProperty.setVal(FontCharset.SYMBOL.getValue());
+                break;
+            case Font.DEFAULT_CHARSET:
+                charsetProperty.setVal(FontCharset.DEFAULT.getValue());
+                break;
+            default:
+                throw new RuntimeException("Attention: an attempt to set a type of unknow charset and charset");
         }
     }
 
-  
+    /**
+     * set character-set to use.
+     *
+     * @param charSet
+     */
     public void setCharSet(FontCharset charSet) {
-		setCharSet(charSet.getValue());
+        setCharSet(charSet.getValue());
     }
 
+    /**
+     * set the indexed color for the font
+     *
+     * @param color - color to use
+     * @see #DEFAULT_FONT_COLOR - Note: default font color
+     * @see IndexedColors
+     */
     public void setColor(short color) {
-         CTColor ctColor=ctFont.sizeOfColorArray()==0?ctFont.addNewColor():ctFont.getColorArray(0);
-
+        CTColor ctColor = ctFont.sizeOfColorArray() == 0 ? ctFont.addNewColor() : ctFont.getColorArray(0);
         switch (color) {
-        case Font.COLOR_NORMAL:{
-            ctColor.setIndexed(XSSFFont.DEFAULT_FONT_COLOR);
-            break;
-        }
-        case Font.COLOR_RED:{
-            ctColor.setIndexed(IndexedColors.RED.getIndex());
-            break;
-        }
-        default:
-            ctColor.setIndexed(color);
+            case Font.COLOR_NORMAL: {
+                ctColor.setIndexed(XSSFFont.DEFAULT_FONT_COLOR);
+                break;
+            }
+            case Font.COLOR_RED: {
+                ctColor.setIndexed(IndexedColors.RED.getIndex());
+                break;
+            }
+            default:
+                ctColor.setIndexed(color);
         }
     }
 
-
+    /**
+     * set the font height in points.
+     *
+     * @param height - height in points
+     */
     public void setFontHeight(short height) {
-	setFontHeight((double)height);
+        setFontHeight((double) height);
     }
 
+    /**
+     * set the font height in points.
+     *
+     * @param height - height in points
+     */
     public void setFontHeight(double height) {
-        CTFontSize fontSize=ctFont.sizeOfSzArray()==0?ctFont.addNewSz():ctFont.getSzArray(0);
+        CTFontSize fontSize = ctFont.sizeOfSzArray() == 0 ? ctFont.addNewSz() : ctFont.getSzArray(0);
         fontSize.setVal(height);
     }
 
+    /**
+     * set the font height in points.
+     *
+     * @link #setFontHeight
+     */
     public void setFontHeightInPoints(short height) {
-          setFontHeight((double)height);
+        setFontHeight(height);
     }
 
-
+    /**
+     * set the color for the font in Standard Alpha Red Green Blue color value
+     *
+     * @param color - color to use
+     */
     public void setRgbColor(XSSFColor color) {
-	CTColor ctColor=ctFont.sizeOfColorArray()==0?ctFont.addNewColor():ctFont.getColorArray(0);
-	ctColor.setRgb(color.getRgb());
+        CTColor ctColor = ctFont.sizeOfColorArray() == 0 ? ctFont.addNewColor() : ctFont.getColorArray(0);
+        ctColor.setRgb(color.getRgb());
     }
 
-     public void setThemeColor(short theme) {
-         CTColor ctColor=ctFont.sizeOfColorArray()==0?ctFont.addNewColor():ctFont.getColorArray(0);
-         ctColor.setTheme(theme);
-     }
-
+    /**
+     * set the theme color for the font to use
+     *
+     * @param theme - theme color to use
+     */
+    public void setThemeColor(short theme) {
+        CTColor ctColor = ctFont.sizeOfColorArray() == 0 ? ctFont.addNewColor() : ctFont.getColorArray(0);
+        ctColor.setTheme(theme);
+    }
+
+    /**
+     * set the name for the font (i.e. Arial).
+     * If the font doesn't exist (because it isn't installed on the system),
+     * or the charset is invalid for that font, then another font should
+     * be substituted.
+     * The string length for this attribute shall be 0 to 31 characters.
+     * Default font name is Calibri.
+     *
+     * @param name - value representing the name of the font to use
+     * @see #DEFAULT_FONT_NAME
+     */
     public void setFontName(String name) {
-	CTFontName fontName=ctFont.sizeOfNameArray()==0?ctFont.addNewName():ctFont.getNameArray(0);
-	fontName.setVal(name);
+        CTFontName fontName = ctFont.sizeOfNameArray() == 0 ? ctFont.addNewName() : ctFont.getNameArray(0);
+        fontName.setVal(name);
     }
 
+
+    /**
+     * set a boolean value for the property specifying whether to use italics or not
+     * If omitted, the default value is true.
+     *
+     * @param italic - value for italics or not
+     */
     public void setItalic(boolean italic) {
-         CTBooleanProperty bool=ctFont.sizeOfIArray()==0?ctFont.addNewI():ctFont.getIArray(0);
-          bool.setVal(italic);
+        CTBooleanProperty bool = ctFont.sizeOfIArray() == 0 ? ctFont.addNewI() : ctFont.getIArray(0);
+        bool.setVal(italic);
     }
 
+
+    /**
+     * set a boolean value for the property specifying whether to use a strikeout horizontal line through the text or not
+     * If omitted, the default value is true.
+     *
+     * @param strikeout - value for strikeout or not
+     */
     public void setStrikeout(boolean strikeout) {
-         CTBooleanProperty strike=ctFont.sizeOfStrikeArray()==0?ctFont.addNewStrike():ctFont.getStrikeArray(0);
-          strike.setVal(strikeout);
+        CTBooleanProperty strike = ctFont.sizeOfStrikeArray() == 0 ? ctFont.addNewStrike() : ctFont.getStrikeArray(0);
+        strike.setVal(strikeout);
     }
 
+    /**
+     * set normal,super or subscript, that representing the vertical-alignment setting.
+     * Setting this to either subscript or superscript shall make the font size smaller if a
+     * smaller font size is available.
+     *
+     * @param offset - offset type to use (none,super,sub)
+     * @see #SS_NONE
+     * @see #SS_SUPER
+     * @see #SS_SUB
+     */
     public void setTypeOffset(short offset) {
-        CTVerticalAlignFontProperty offsetProperty=ctFont.sizeOfVertAlignArray()==0?ctFont.addNewVertAlign(): ctFont.getVertAlignArray(0);
+        CTVerticalAlignFontProperty offsetProperty = ctFont.sizeOfVertAlignArray() == 0 ? ctFont.addNewVertAlign() : ctFont.getVertAlignArray(0);
         switch (offset) {
-        case Font.SS_NONE:
-            offsetProperty.setVal(STVerticalAlignRun.BASELINE);
-            break;
-        case Font.SS_SUB:
-            offsetProperty.setVal(STVerticalAlignRun.SUBSCRIPT);
-            break;
-        case Font.SS_SUPER:
-            offsetProperty.setVal(STVerticalAlignRun.SUPERSCRIPT);
-            break;
+            case Font.SS_NONE:
+                offsetProperty.setVal(STVerticalAlignRun.BASELINE);
+                break;
+            case Font.SS_SUB:
+                offsetProperty.setVal(STVerticalAlignRun.SUBSCRIPT);
+                break;
+            case Font.SS_SUPER:
+                offsetProperty.setVal(STVerticalAlignRun.SUPERSCRIPT);
+                break;
         }
     }
 
+    /**
+     * set the style of underlining that is used.
+     * The none style is equivalent to not using underlining at all.
+     *
+     * @param underline - underline type to use
+     * @see FontUnderline
+     */
     public void setUnderline(byte underline) {
-         CTUnderlineProperty ctUnderline=ctFont.sizeOfUArray()==0?ctFont.addNewU():ctFont.getUArray(0);
+        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_NONE:
-            ctUnderline.setVal(FontUnderline.NONE.getValue());
-            break;
-        case Font.U_SINGLE:
-        default:
-            ctUnderline.setVal(FontUnderline.SINGLE.getValue());
-        break;
+            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_NONE:
+                ctUnderline.setVal(FontUnderline.NONE.getValue());
+                break;
+            case Font.U_SINGLE:
+            default:
+                ctUnderline.setVal(FontUnderline.SINGLE.getValue());
+                break;
         }
     }
-    
+
+    /**
+     * set an enumeration representing the style of underlining that is used.
+     * The none style is equivalent to not using underlining at all.
+     * The possible values for this attribute are defined by the FontUnderline
+     *
+     * @param underline - FontUnderline enum value
+     */
     public void setUnderline(FontUnderline underline) {
-        CTUnderlineProperty ctUnderline=ctFont.sizeOfUArray()==0?ctFont.addNewU():ctFont.getUArray(0);
+        CTUnderlineProperty ctUnderline = ctFont.sizeOfUArray() == 0 ? ctFont.addNewU() : ctFont.getUArray(0);
         ctUnderline.setVal(underline.getValue());
     }
-    
-    
-    public String toString(){
-	        return "org.apache.poi.xssf.usermodel.XSSFFont{" +
-               ctFont +
-              "}";
+
+
+    public String toString() {
+        return "org.apache.poi.xssf.usermodel.XSSFFont{" +
+                ctFont +
+                "}";
     }
-    
 
-     public long putFont(ArrayList<CTFont> fonts) {
+
+    public long putFont(ArrayList<CTFont> fonts) {
         //TODO
         /*
            * we need to implement a method equals to check that 2 instances of CTFont
            * are different by comparison of all font attributes.
            * NB: take a look to findFont method in XSSFWorkbook
            */
-         if(fonts.contains(ctFont)) {
-             return fonts.indexOf(ctFont);
+        if (fonts.contains(ctFont)) {
+            return fonts.indexOf(ctFont);
         }
-         fonts.add(ctFont);
+        fonts.add(ctFont);
         return fonts.size() - 1;
     }
 
-/*
-  this methds are used only for XSSFFont and aren't in Font interface
-  are used in method SthlesTable.createDefaultfont
- */
-
-    public FontScheme getScheme(){
-        CTFontScheme scheme=ctFont.sizeOfSchemeArray()==0?null:ctFont.getSchemeArray(0);
+    /**
+     * get the font scheme property.
+     * is used only in StylesTable to create the default instance of font
+     *
+     * @return FontScheme
+     * @see org.apache.poi.xssf.model.StylesTable#createDefaultFont()
+     */
+    public FontScheme getScheme() {
+        CTFontScheme scheme = ctFont.sizeOfSchemeArray() == 0 ? null : ctFont.getSchemeArray(0);
         return scheme == null ? FontScheme.NONE : FontScheme.valueOf(scheme.getVal());
     }
 
-    public void setScheme(FontScheme scheme){
-         CTFontScheme ctFontScheme=ctFont.sizeOfSchemeArray()==0?ctFont.addNewScheme():ctFont.getSchemeArray(0);
-         ctFontScheme.setVal(scheme.getValue());
+    /**
+     * set font scheme property
+     *
+     * @param scheme - FontScheme enum value
+     * @see FontScheme
+     */
+    public void setScheme(FontScheme scheme) {
+        CTFontScheme ctFontScheme = ctFont.sizeOfSchemeArray() == 0 ? ctFont.addNewScheme() : ctFont.getSchemeArray(0);
+        ctFontScheme.setVal(scheme.getValue());
+    }
+
+    /**
+     * get the font family to use.
+     *
+     * @return the font family to use
+     * @see FontFamily
+     */
+    public int getFamily() {
+        CTIntProperty family = ctFont.sizeOfFamilyArray() == 0 ? ctFont.addNewFamily() : ctFont.getFamilyArray(0);
+        return family == null ? FontFamily.NOT_APPLICABLE.getValue() : FontFamily.valueOf(family.getVal()).getValue();
+    }
+
+    /**
+     * Set 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.
+     *
+     * @param value - font family
+     * @see FontFamily
+     */
+    public void setFamily(int value) {
+        CTIntProperty family = ctFont.sizeOfFamilyArray() == 0 ? ctFont.addNewFamily() : ctFont.getFamilyArray(0);
+        family.setVal(value);
+    }
+
+    /**
+     * set an enumeration representing the font family this font belongs to.
+     * A font family is a set of fonts having common stroke width and serif characteristics.
+     *
+     * @param family font family
+     * @link #setFamily(int value)
+     */
+    public void setFamily(FontFamily family) {
+        setFamily(family.getValue());
     }
 
 
-      public int getFamily(){
-         CTIntProperty family = ctFont.sizeOfFamilyArray() == 0 ? ctFont.addNewFamily() : ctFont.getFamilyArray(0);
-         return family == null ? FontFamily.NOT_APPLICABLE.getValue() : FontFamily.valueOf(family.getVal()).getValue();
-      }
-
-      
-     public void setFamily(int value){
-         CTIntProperty family = ctFont.sizeOfFamilyArray() == 0 ? ctFont.addNewFamily() : ctFont.getFamilyArray(0);
-          family.setVal(value);
-     }
-      
-     public void setFamily(FontFamily family){
-	 setFamily(family.getValue());
-     }
-
-     
-    
 }

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=700844&r1=700843&r2=700844&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Wed Oct  1 10:15:02 2008
@@ -438,9 +438,28 @@
         return false;
     }
 
+
+    /**
+     * Get whether to display the guts or not,
+     * default value is true
+     *
+     * @return boolean - guts or no guts
+     */
     public boolean getDisplayGuts() {
-        // TODO Auto-generated method stub
-        return false;
+        CTSheetPr sheetPr = getSheetTypeSheetPr();
+        CTOutlinePr outlinePr = sheetPr.getOutlinePr() == null ? CTOutlinePr.Factory.newInstance() : sheetPr.getOutlinePr();
+        return outlinePr.getShowOutlineSymbols();
+    }
+
+    /**
+     * Set whether to display the guts or not
+     *
+     * @param value - guts or no guts
+     */
+    public void setDisplayGuts(boolean value) {
+        CTSheetPr sheetPr = getSheetTypeSheetPr();
+        CTOutlinePr outlinePr = sheetPr.getOutlinePr() == null ? sheetPr.addNewOutlinePr() : sheetPr.getOutlinePr();
+        outlinePr.setShowOutlineSymbols(value);
     }
 
     /**
@@ -1117,11 +1136,6 @@
         getSheetTypeSheetView().setShowGridLines(show);
     }
 
-    public void setDisplayGuts(boolean b) {
-        // TODO Auto-generated method stub
-
-    }
-
     public void setDisplayRowColHeadings(boolean show) {
         getSheetTypeSheetView().setShowRowColHeaders(show);
     }

Modified: poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=700844&r1=700843&r2=700844&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/branches/ooxml/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Wed Oct  1 10:15:02 2008
@@ -26,7 +26,6 @@
 import javax.xml.namespace.QName;
 import org.apache.poi.POIXMLDocument;
 import org.apache.poi.POIXMLDocumentPart;
-import org.apache.poi.POIXMLFactory;
 import org.apache.poi.ss.usermodel.Palette;
 import org.apache.poi.ss.usermodel.PictureData;
 import org.apache.poi.ss.usermodel.Row;
@@ -45,15 +44,7 @@
 import org.openxml4j.exceptions.OpenXML4JException;
 import org.openxml4j.opc.*;
 import org.openxml4j.opc.Package;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookView;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBookViews;
-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.CTSheet;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorkbook;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
-import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument;
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
 
 /**
  * High level representation of a SpreadsheetML workbook.  This is the first object most users
@@ -103,28 +94,28 @@
      */
     private MissingCellPolicy missingCellPolicy = Row.RETURN_NULL_AND_BLANK;
 
-	private static POILogger log = POILogFactory.getLogger(XSSFWorkbook.class);
+    private static POILogger log = POILogFactory.getLogger(XSSFWorkbook.class);
 
     /**
      * Create a new SpreadsheetML workbook.
      */
-	public XSSFWorkbook() {
+    public XSSFWorkbook() {
         super();
         try {
             newWorkbook();
         }catch (Exception e){
             throw new POIXMLException(e);
         }
-	}
+    }
 
     /**
      * Constructs a XSSFWorkbook object given a file name.
      *
      * @param      path   the file name.
      */
-	public XSSFWorkbook(String path) throws IOException {
-		this(openPackage(path));
-	}
+    public XSSFWorkbook(String path) throws IOException {
+        this(openPackage(path));
+    }
 
     /**
      * Constructs a XSSFWorkbook object given a OpenXML4J <code>Package</code> object,
@@ -157,14 +148,14 @@
     protected void initialize(Package pkg) throws IOException {
         super.initialize(pkg);
 
-		try {
+        try {
             //build the POIXMLDocumentPart tree, this workbook is the root
             read(new XSSFFactory());
 
             PackagePart corePart = getCorePart();
 
             WorkbookDocument doc = WorkbookDocument.Factory.parse(corePart.getInputStream());
-			this.workbook = doc.getWorkbook();
+            this.workbook = doc.getWorkbook();
 
             HashMap<String, XSSFSheet> shIdMap = new HashMap<String, XSSFSheet>();
             for(POIXMLDocumentPart p : getRelations()){
@@ -172,50 +163,50 @@
                 else if(p instanceof StylesSource) stylesSource = (StylesSource)p;
                 else if (p instanceof XSSFSheet) {
                     shIdMap.put(p.getPackageRelationship().getId(), (XSSFSheet)p);
-			    }
-			}
-			// Load individual sheets
+                }
+            }
+            // Load individual sheets
             sheets = new LinkedList<XSSFSheet>();
-			for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) {
+            for (CTSheet ctSheet : this.workbook.getSheets().getSheetArray()) {
                 String id = ctSheet.getId();
                 XSSFSheet sh = shIdMap.get(id);
                 sh.sheet = ctSheet;
                 if(sh == null) {
-					log.log(POILogger.WARN, "Sheet with name " + ctSheet.getName() + " and r:id " + ctSheet.getId()+ " was defined, but didn't exist in package, skipping");
-					continue;
-				}
+                    log.log(POILogger.WARN, "Sheet with name " + ctSheet.getName() + " and r:id " + ctSheet.getId()+ " was defined, but didn't exist in package, skipping");
+                    continue;
+                }
                 //initialize internal arrays of rows and columns
                 sh.initialize();
 
                 PackagePart sheetPart = sh.getPackagePart();
-				// Process external hyperlinks for the sheet,
-				//  if there are any
-				PackageRelationshipCollection hyperlinkRels =
-                	sheetPart.getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation());
+                // Process external hyperlinks for the sheet,
+                //  if there are any
+                PackageRelationshipCollection hyperlinkRels =
+                    sheetPart.getRelationshipsByType(XSSFRelation.SHEET_HYPERLINKS.getRelation());
                 sh.initHyperlinks(hyperlinkRels);
 
-				// Get the embeddings for the workbook
+                // Get the embeddings for the workbook
                 for(PackageRelationship rel : sheetPart.getRelationshipsByType(XSSFRelation.OLEEMBEDDINGS.getRelation()))
-					embedds.add(getTargetPart(rel)); // TODO: Add this reference to each sheet as well
+                    embedds.add(getTargetPart(rel)); // TODO: Add this reference to each sheet as well
 
                 for(PackageRelationship rel : sheetPart.getRelationshipsByType(XSSFRelation.PACKEMBEDDINGS.getRelation()))
-					embedds.add(getTargetPart(rel));
+                    embedds.add(getTargetPart(rel));
 
                 sheets.add(sh);
-			}
+            }
 
             if(sharedStringSource == null) {
                 //Create SST if it is missing
                 sharedStringSource = (SharedStringsTable)createRelationship(XSSFRelation.SHARED_STRINGS, SharedStringsTable.class);
-		    }
+            }
 
-		    // Process the named ranges
+            // Process the named ranges
             namedRanges = new LinkedList<XSSFName>();
             if(workbook.getDefinedNames() != null) {
                 for(CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameArray()) {
                     namedRanges.add(new XSSFName(ctName, this));
                 }
-		    }
+            }
 
         } catch (Exception e) {
             throw new POIXMLException(e);
@@ -249,71 +240,71 @@
 
         namedRanges = new LinkedList<XSSFName>();
         sheets = new LinkedList<XSSFSheet>();
-	}
+    }
+
+    /**
+     * Return the underlying XML bean
+     *
+     * @return the underlying CTWorkbook bean
+     */
+    public CTWorkbook getWorkbook() {
+        return this.workbook;
+    }
+
+    public int addPicture(byte[] pictureData, int format) {
+        // TODO Auto-generated method stub
+        return 0;
+    }
 
-	/**
-	 * Return the underlying XML bean
-	 *
-	 * @return the underlying CTWorkbook bean
-	 */
-	public CTWorkbook getWorkbook() {
-		return this.workbook;
-	}
-
-	public int addPicture(byte[] pictureData, int format) {
-		// TODO Auto-generated method stub
-		return 0;
-	}
-
-	public XSSFSheet cloneSheet(int sheetNum) {
-		XSSFSheet srcSheet = sheets.get(sheetNum);
-		String srcName = getSheetName(sheetNum);
-		if (srcSheet != null) {
-			XSSFSheet clonedSheet = srcSheet.cloneSheet();
-
-			sheets.add(clonedSheet);
-			CTSheet newcts = this.workbook.getSheets().addNewSheet();
-			newcts.set(clonedSheet.getSheet());
-
-			int i = 1;
-			while (true) {
-				//Try and find the next sheet name that is unique
-				String name = srcName;
-				String index = Integer.toString(i++);
-				if (name.length() + index.length() + 2 < 31) {
-					name = name + "("+index+")";
-				} else {
-					name = name.substring(0, 31 - index.length() - 2) + "(" +index + ")";
-				}
-
-				//If the sheet name is unique, then set it otherwise move on to the next number.
-				if (getSheetIndex(name) == -1) {
-					setSheetName(sheets.size() - 1, name);
-					break;
-				}
-			}
-			return clonedSheet;
-		}
-		return null;
-	}
+    public XSSFSheet cloneSheet(int sheetNum) {
+        XSSFSheet srcSheet = sheets.get(sheetNum);
+        String srcName = getSheetName(sheetNum);
+        if (srcSheet != null) {
+            XSSFSheet clonedSheet = srcSheet.cloneSheet();
+
+            sheets.add(clonedSheet);
+            CTSheet newcts = this.workbook.getSheets().addNewSheet();
+            newcts.set(clonedSheet.getSheet());
+
+            int i = 1;
+            while (true) {
+                //Try and find the next sheet name that is unique
+                String name = srcName;
+                String index = Integer.toString(i++);
+                if (name.length() + index.length() + 2 < 31) {
+                    name = name + "("+index+")";
+                } else {
+                    name = name.substring(0, 31 - index.length() - 2) + "(" +index + ")";
+                }
+
+                //If the sheet name is unique, then set it otherwise move on to the next number.
+                if (getSheetIndex(name) == -1) {
+                    setSheetName(sheets.size() - 1, name);
+                    break;
+                }
+            }
+            return clonedSheet;
+        }
+        return null;
+    }
 
     /**
      * Create a new XSSFCellStyle and add it to the workbook's style table
      *
      * @return the new XSSFCellStyle object
      */
-	public XSSFCellStyle createCellStyle() {
-		CTXf xf=CTXf.Factory.newInstance();
-		xf.setNumFmtId(0);
-		xf.setFontId(0);
-		xf.setFillId(0);
-		xf.setBorderId(0);
-		xf.setXfId(0);
-		int xfSize=((StylesTable)stylesSource)._getStyleXfsSize();
-		long indexXf=((StylesTable)stylesSource).putCellXf(xf);
-		XSSFCellStyle style = new XSSFCellStyle(new Long(indexXf-1).intValue(), xfSize-1, (StylesTable)stylesSource);
-		return style;
-	}
+    public XSSFCellStyle createCellStyle() {
+        CTXf xf=CTXf.Factory.newInstance();
+        xf.setNumFmtId(0);
+        xf.setFontId(0);
+        xf.setFillId(0);
+        xf.setBorderId(0);
+        xf.setXfId(0);
+        int xfSize=((StylesTable)stylesSource)._getStyleXfsSize();
+        long indexXf=((StylesTable)stylesSource).putCellXf(xf);
+        XSSFCellStyle style = new XSSFCellStyle(new Long(indexXf-1).intValue(), xfSize-1, (StylesTable)stylesSource);
+        return style;
+    }
 
     /**
      * Returns the instance of XSSFDataFormat for this workbook.
@@ -332,22 +323,22 @@
      *
      * @return new font object
      */
-	public XSSFFont createFont() {
-		XSSFFont font= new XSSFFont();
-		stylesSource.putFont(font);
-		return font;
-	}
+    public XSSFFont createFont() {
+        XSSFFont font= new XSSFFont();
+        stylesSource.putFont(font);
+        return font;
+    }
 
     /**
      * Creates a new named range and add it to the model
      *
      * @return named range high level
      */
-	public XSSFName createName() {
-		XSSFName name = new XSSFName(this);
-		namedRanges.add(name);
-		return name;
-	}
+    public XSSFName createName() {
+        XSSFName name = new XSSFName(this);
+        namedRanges.add(name);
+        return name;
+    }
 
     /**
      * create an XSSFSheet for this workbook, adds it to the sheets and returns
@@ -355,10 +346,10 @@
      *
      * @return XSSFSheet representing the new sheet.
      */
-	public XSSFSheet createSheet() {
-		String sheetname = "Sheet" + (sheets.size() + 1);
-		return createSheet(sheetname);
-	}
+    public XSSFSheet createSheet() {
+        String sheetname = "Sheet" + (sheets.size() + 1);
+        return createSheet(sheetname);
+    }
 
     /**
      * create an XSSFSheet for this workbook, adds it to the sheets and returns
@@ -367,90 +358,90 @@
      * @param sheetname  sheetname to set for the sheet, can't be duplicate, greater than 31 chars or contain /\?*[]
      * @return XSSFSheet representing the new sheet.
      */
-	public XSSFSheet createSheet(String sheetname) {
-		if (doesContainsSheetName( sheetname, sheets.size() ))
-	   		throw new IllegalArgumentException( "The workbook already contains a sheet of this name" );
+    public XSSFSheet createSheet(String sheetname) {
+        if (containsSheet( sheetname, sheets.size() ))
+               throw new IllegalArgumentException( "The workbook already contains a sheet of this name" );
 
         int sheetNumber = getNumberOfSheets() + 1;
         XSSFSheet wrapper = (XSSFSheet)createRelationship(XSSFRelation.WORKSHEET, XSSFSheet.class, sheetNumber);
         wrapper.setParent(this);
 
-		CTSheet sheet = addSheet(sheetname);
+        CTSheet sheet = addSheet(sheetname);
         wrapper.sheet = sheet;
         sheet.setId(wrapper.getPackageRelationship().getId());
         sheet.setSheetId(sheetNumber);
 
-		this.sheets.add(wrapper);
-		return wrapper;
-	}
+        this.sheets.add(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;
-	}
+    }
 
-	private CTSheet addSheet(String sheetname) {
-		validateSheetName(sheetname);
+    private CTSheet addSheet(String sheetname) {
+        validateSheetName(sheetname);
 
         CTSheet sheet = workbook.getSheets().addNewSheet();
-		sheet.setName(sheetname);
-		return sheet;
-	}
+        sheet.setName(sheetname);
+        return sheet;
+    }
 
     /**
      * Finds a font that matches the one with the supplied attributes
      */
-	public XSSFFont findFont(short boldWeight, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline) {
-		short fontNum=getNumberOfFonts();
-		for (short i = 0; i < fontNum; i++) {
-			XSSFFont xssfFont = getFontAt(i);
-
-			if (	(xssfFont.getBold() == (boldWeight == XSSFFont.BOLDWEIGHT_BOLD))
-					&& 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;
-	}
-
-	/**
-	 * Convenience method to get the active sheet.  The active sheet is is the sheet
-	 * which is currently displayed when the workbook is viewed in Excel.
-	 * 'Selected' sheet(s) is a distinct concept.
-	 */
-	public int getActiveSheetIndex() {
-		//activeTab (Active Sheet Index) Specifies an unsignedInt
-		//that contains the index to the active sheet in this book view.
-		Long index = workbook.getBookViews().getWorkbookViewArray(0).getActiveTab();
-		return index.intValue();
-	}
+    public XSSFFont findFont(short boldWeight, short color, short fontHeight, String name, boolean italic, boolean strikeout, short typeOffset, byte underline) {
+        short fontNum=getNumberOfFonts();
+        for (short i = 0; i < fontNum; i++) {
+            XSSFFont xssfFont = getFontAt(i);
+
+            if (	(xssfFont.getBold() == (boldWeight == XSSFFont.BOLDWEIGHT_BOLD))
+                    && 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;
+    }
+
+    /**
+     * Convenience method to get the active sheet.  The active sheet is is the sheet
+     * which is currently displayed when the workbook is viewed in Excel.
+     * 'Selected' sheet(s) is a distinct concept.
+     */
+    public int getActiveSheetIndex() {
+        //activeTab (Active Sheet Index) Specifies an unsignedInt
+        //that contains the index to the active sheet in this book view.
+        Long index = workbook.getBookViews().getWorkbookViewArray(0).getActiveTab();
+        return index.intValue();
+    }
 
     /**
      * Gets all embedded OLE2 objects from the Workbook.
      *
      * @return the list of embedded objects (a list of {@link org.openxml4j.opc.PackagePart} objects.)
      */
-	public List getAllEmbeddedObjects() {
+    public List getAllEmbeddedObjects() {
         return embedds;
-	}
+    }
 
     /**
      * Gets all pictures from the Workbook.
      *
      * @return the list of pictures (a list of {@link XSSFPictureData} objects.)
      */
-	public List<PictureData> getAllPictures() {
-		// In OOXML pictures are referred to in sheets
-		List<PictureData> pictures = new LinkedList<PictureData>();
+    public List<PictureData> getAllPictures() {
+        // In OOXML pictures are referred to in sheets
+        List<PictureData> pictures = new LinkedList<PictureData>();
         for(POIXMLDocumentPart p : getRelations()){
             if (p instanceof XSSFSheet) {
                 PackagePart sheetPart = p.getPackagePart();
@@ -471,22 +462,22 @@
 
             }
         }
-		return pictures;
-	}
+        return pictures;
+    }
+
+    public boolean getBackupFlag() {
+        // TODO Auto-generated method stub
+        return false;
+    }
 
-	public boolean getBackupFlag() {
-		// TODO Auto-generated method stub
-		return false;
-	}
-
-	public XSSFCellStyle getCellStyleAt(short idx) {
-		return (XSSFCellStyle)stylesSource.getStyleAt(idx);
-	}
-
-	public Palette getCustomPalette() {
-		// TODO Auto-generated method stub
-		return null;
-	}
+    public XSSFCellStyle getCellStyleAt(short idx) {
+        return (XSSFCellStyle)stylesSource.getStyleAt(idx);
+    }
+
+    public Palette getCustomPalette() {
+        // TODO Auto-generated method stub
+        return null;
+    }
 
     /**
      * Get the font at the given index number
@@ -494,9 +485,9 @@
      * @param idx  index number
      * @return XSSFFont at the index
      */
-	public XSSFFont getFontAt(short idx) {
-		return (XSSFFont)stylesSource.getFontAt(idx);
-	}
+    public XSSFFont getFontAt(short idx) {
+        return (XSSFFont)stylesSource.getFontAt(idx);
+    }
 
     /**
      * Gets the Named range at the given index number
@@ -504,9 +495,9 @@
      * @param index position of the named range
      * @return XSSFName at the index
      */
-	public XSSFName getNameAt(int index) {
-		return namedRanges.get(index);
-	}
+    public XSSFName getNameAt(int index) {
+        return namedRanges.get(index);
+    }
 
     /**
      * Gets the Named range name at the given index number,
@@ -516,9 +507,9 @@
      * @return named range name
      * @see #getNameAt(int)
      */
-	public String getNameName(int index) {
-		return getNameAt(index).getNameName();
-	}
+    public String getNameName(int index) {
+        return getNameAt(index).getNameName();
+    }
 
     /**
      * Gets the named range index by his name
@@ -536,64 +527,64 @@
             }
             i++;
         }
-		return -1;
-	}
+        return -1;
+    }
 
     /**
      * Get the number of styles the workbook contains
      *
      * @return count of cell styles
      */
-	public short getNumCellStyles() {
-		return (short) ((StylesTable)stylesSource).getNumCellStyles();
-	}
+    public short getNumCellStyles() {
+        return (short) ((StylesTable)stylesSource).getNumCellStyles();
+    }
 
     /**
      * Get the number of fonts in the this workbook
      *
      * @return number of fonts
      */
-	public short getNumberOfFonts() {
-		return (short)((StylesTable)stylesSource).getNumberOfFonts();
-	}
+    public short getNumberOfFonts() {
+        return (short)((StylesTable)stylesSource).getNumberOfFonts();
+    }
 
     /**
      * Get the number of named ranges in the this workbook
      *
      * @return number of named ranges
      */
-	public int getNumberOfNames() {
-		return namedRanges.size();
-	}
+    public int getNumberOfNames() {
+        return namedRanges.size();
+    }
 
     /**
      * Get the number of worksheets in the this workbook
      *
      * @return number of worksheets
      */
-	public int getNumberOfSheets() {
+    public int getNumberOfSheets() {
         return this.sheets.size();
-	}
+    }
 
-	public String getPrintArea(int sheetIndex) {
-		// TODO Auto-generated method stub
-		return null;
-	}
+    public String getPrintArea(int sheetIndex) {
+        // TODO Auto-generated method stub
+        return null;
+    }
 
     /**
      * deprecated May 2008
      * @deprecated - Misleading name - use getActiveSheetIndex()
      */
-	public short getSelectedTab() {
-		short i = 0;
-		for (XSSFSheet sheet : this.sheets) {
-			if (sheet.isSelected()) {
-				return i;
-			}
-			++i;
-		}
-		return -1;
-	}
+    public short getSelectedTab() {
+        short i = 0;
+        for (XSSFSheet sheet : this.sheets) {
+            if (sheet.isSelected()) {
+                return i;
+            }
+            ++i;
+        }
+        return -1;
+    }
 
     /**
      * Get sheet with the given name (case insensitive match)
@@ -601,15 +592,15 @@
      * @param name of the sheet
      * @return XSSFSheet with the name provided or <code>null</code> if it does not exist
      */
-	public XSSFSheet getSheet(String name) {
-		CTSheet[] sheets = this.workbook.getSheets().getSheetArray();
-		for (int i = 0 ; i < sheets.length ; ++i) {
-			if (name.equals(sheets[i].getName())) {
-				return this.sheets.get(i);
-			}
-		}
-		return null;
-	}
+    public XSSFSheet getSheet(String name) {
+        CTSheet[] sheets = this.workbook.getSheets().getSheetArray();
+        for (int i = 0 ; i < sheets.length ; ++i) {
+            if (name.equals(sheets[i].getName())) {
+                return this.sheets.get(i);
+            }
+        }
+        return null;
+    }
 
     /**
      * Get the XSSFSheet object at the given index.
@@ -617,9 +608,10 @@
      * @param index of the sheet number (0-based physical & logical)
      * @return XSSFSheet at the provided index
      */
-	public XSSFSheet getSheetAt(int index) {
-		return this.sheets.get(index);
-	}
+    public XSSFSheet getSheetAt(int index) {
+        validateSheetIndex(index);
+        return this.sheets.get(index);
+    }
 
     /**
      * Returns the index of the sheet by his name
@@ -627,15 +619,15 @@
      * @param name the sheet name
      * @return index of the sheet (0 based)
      */
-	public int getSheetIndex(String name) {
-		CTSheet[] sheets = this.workbook.getSheets().getSheetArray();
-		for (int i = 0 ; i < sheets.length ; ++i) {
-			if (name.equals(sheets[i].getName())) {
-				return i;
-			}
-		}
-		return -1;
-	}
+    public int getSheetIndex(String name) {
+        CTSheet[] sheets = this.workbook.getSheets().getSheetArray();
+        for (int i = 0 ; i < sheets.length ; ++i) {
+            if (name.equals(sheets[i].getName())) {
+                return i;
+            }
+        }
+        return -1;
+    }
 
     /**
      * Returns the index of the given sheet
@@ -643,14 +635,14 @@
      * @param sheet the sheet to look up
      * @return index of the sheet (0 based). <tt>-1</tt> if not found
      */
-	public int getSheetIndex(Sheet sheet) {
+    public int getSheetIndex(Sheet sheet) {
         int idx = 0;
         for(XSSFSheet sh : this){
             if(sh == sheet) return idx;
             idx++;
         }
         return -1;
-	}
+    }
 
     /**
      * Get the sheet name
@@ -658,13 +650,13 @@
      * @param sheetIx Number
      * @return Sheet name
      */
-	public String getSheetName(int sheetIx) {
+    public String getSheetName(int sheetIx) {
         validateSheetIndex(sheetIx);
-		return this.workbook.getSheets().getSheetArray(sheetIx).getName();
-	}
+        return this.workbook.getSheets().getSheetArray(sheetIx).getName();
+    }
 
     /**
-     * Allow foreach loops:
+     * Allows foreach loops:
      * <pre><code>
      * XSSFWorkbook wb = new XSSFWorkbook(package);
      * for(XSSFSheet sheet : wb){
@@ -675,28 +667,28 @@
     public Iterator<XSSFSheet> iterator() {
         return sheets.iterator();
     }
-	/**
-	 * Are we a normal workbook (.xlsx), or a
-	 *  macro enabled workbook (.xlsm)?
-	 */
-	public boolean isMacroEnabled() {
+    /**
+     * Are we a normal workbook (.xlsx), or a
+     *  macro enabled workbook (.xlsm)?
+     */
+    public boolean isMacroEnabled() {
         return getCorePart().getContentType().equals(XSSFRelation.MACROS_WORKBOOK.getContentType());
-	}
+    }
 
-	public void removeName(int index) {
-		// TODO Auto-generated method stub
+    public void removeName(int index) {
+        // TODO Auto-generated method stub
 
-	}
+    }
 
-	public void removeName(String name) {
-		// TODO Auto-generated method stub
+    public void removeName(String name) {
+        // TODO Auto-generated method stub
 
-	}
+    }
 
-	public void removePrintArea(int sheetIndex) {
-		// TODO Auto-generated method stub
+    public void removePrintArea(int sheetIndex) {
+        // TODO Auto-generated method stub
 
-	}
+    }
 
     /**
      * Removes sheet at the given index.<p/>
@@ -712,117 +704,130 @@
      *
      * @param index of the sheet  (0-based)
      */
-	public void removeSheetAt(int index) {
-		this.sheets.remove(index);
-		this.workbook.getSheets().removeSheet(index);
-	}
-
-	/**
-	 * Retrieves the current policy on what to do when
-	 *  getting missing or blank cells from a row.
-	 * The default is to return blank and null cells.
-	 *  {@link MissingCellPolicy}
-	 */
-	public MissingCellPolicy getMissingCellPolicy() {
-		return missingCellPolicy;
-	}
-	/**
-	 * Sets the policy on what to do when
-	 *  getting missing or blank cells from a row.
-	 * This will then apply to all calls to
-	 *  {@link Row#getCell(int)}}. See
-	 *  {@link MissingCellPolicy}
-	 */
-	public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) {
-		this.missingCellPolicy = missingCellPolicy;
-	}
-
-	/**
-	 * Convenience method to set the active sheet.  The active sheet is is the sheet
-	 * which is currently displayed when the workbook is viewed in Excel.
-	 * 'Selected' sheet(s) is a distinct concept.
-	 */
-	public void setActiveSheet(int index) {
-
-		validateSheetIndex(index);
-		//activeTab (Active Sheet Index) Specifies an unsignedInt that contains the index to the active sheet in this book view.
-		CTBookView[] arrayBook = workbook.getBookViews().getWorkbookViewArray();
-		for (int i = 0; i < arrayBook.length; i++) {
-			workbook.getBookViews().getWorkbookViewArray(i).setActiveTab(index);
-		}
-	}
-
-	private void validateSheetIndex(int index) {
-		int lastSheetIx = sheets.size() - 1;
-		if (index < 0 || index > lastSheetIx) {
-			throw new IllegalArgumentException("Sheet index ("
-					+ index +") is out of range (0.." +	lastSheetIx + ")");
-		}
-	}
-
-	public void setBackupFlag(boolean backupValue) {
-		// TODO Auto-generated method stub
-
-	}
-
-	/**
-	 * Gets the first tab that is displayed in the list of tabs in excel.
-	 *
-	 * @return integer that contains the index to the active sheet in this book view.
-	 */
-	public int getFirstVisibleTab() {
-		CTBookViews bookViews = workbook.getBookViews();
-		CTBookView bookView = bookViews.getWorkbookViewArray(0);
-		return (short) bookView.getActiveTab();
-	}
-
-	/**
-	 * Sets the first tab that is displayed in the list of tabs in excel.
-	 *
-	 * @param index integer that contains the index to the active sheet in this book view.
-	 */
-	public void setFirstVisibleTab(int index) {
-		CTBookViews bookViews = workbook.getBookViews();
-		CTBookView bookView= bookViews.getWorkbookViewArray(0);
-		bookView.setActiveTab(index);
-	}
-
-	public void setPrintArea(int sheetIndex, String reference) {
-		// TODO Auto-generated method stub
-
-	}
-
-	public void setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow) {
-		// TODO Auto-generated method stub
-
-	}
-
-	public void setRepeatingRowsAndColumns(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow) {
-		// TODO Auto-generated method stub
-
-	}
-
-	/**
-	 * We only set one sheet as selected for compatibility with HSSF.
-	 */
-	public void setSelectedTab(short index) {
-		for (int i = 0 ; i < this.sheets.size() ; ++i) {
-			XSSFSheet sheet = this.sheets.get(i);
-			sheet.setSelected(i == index);
-		}
-	}
+    public void removeSheetAt(int index) {
+        validateSheetIndex(index);
+        
+        this.sheets.remove(index);
+        this.workbook.getSheets().removeSheet(index);
+    }
+
+    /**
+     * Retrieves the current policy on what to do when
+     *  getting missing or blank cells from a row.
+     * The default is to return blank and null cells.
+     *  {@link MissingCellPolicy}
+     */
+    public MissingCellPolicy getMissingCellPolicy() {
+        return missingCellPolicy;
+    }
+    /**
+     * Sets the policy on what to do when
+     *  getting missing or blank cells from a row.
+     * This will then apply to all calls to
+     *  {@link Row#getCell(int)}}. See
+     *  {@link MissingCellPolicy}
+     */
+    public void setMissingCellPolicy(MissingCellPolicy missingCellPolicy) {
+        this.missingCellPolicy = missingCellPolicy;
+    }
+
+    /**
+     * Convenience method to set the active sheet.  The active sheet is is the sheet
+     * which is currently displayed when the workbook is viewed in Excel.
+     * 'Selected' sheet(s) is a distinct concept.
+     */
+    public void setActiveSheet(int index) {
+
+        validateSheetIndex(index);
+        //activeTab (Active Sheet Index) Specifies an unsignedInt that contains the index to the active sheet in this book view.
+        CTBookView[] arrayBook = workbook.getBookViews().getWorkbookViewArray();
+        for (int i = 0; i < arrayBook.length; i++) {
+            workbook.getBookViews().getWorkbookViewArray(i).setActiveTab(index);
+        }
+    }
+
+    /**
+     * Validate sheet index
+     *
+     * @param index the index to validate
+     * @throws IllegalArgumentException if the index is out of range (index
+     *            &lt; 0 || index &gt;= getNumberOfSheets()).
+    */
+    private void validateSheetIndex(int index) {
+        int lastSheetIx = sheets.size() - 1;
+        if (index < 0 || index > lastSheetIx) {
+            throw new IllegalArgumentException("Sheet index ("
+                    + index +") is out of range (0.." +	lastSheetIx + ")");
+        }
+    }
+
+    public void setBackupFlag(boolean backupValue) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+     * Gets the first tab that is displayed in the list of tabs in excel.
+     *
+     * @return integer that contains the index to the active sheet in this book view.
+     */
+    public int getFirstVisibleTab() {
+        CTBookViews bookViews = workbook.getBookViews();
+        CTBookView bookView = bookViews.getWorkbookViewArray(0);
+        return (short) bookView.getActiveTab();
+    }
+
+    /**
+     * Sets the first tab that is displayed in the list of tabs in excel.
+     *
+     * @param index integer that contains the index to the active sheet in this book view.
+     */
+    public void setFirstVisibleTab(int index) {
+        CTBookViews bookViews = workbook.getBookViews();
+        CTBookView bookView= bookViews.getWorkbookViewArray(0);
+        bookView.setActiveTab(index);
+    }
+
+    public void setPrintArea(int sheetIndex, String reference) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setPrintArea(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow) {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setRepeatingRowsAndColumns(int sheetIndex, int startColumn, int endColumn, int startRow, int endRow) {
+        // TODO Auto-generated method stub
+
+    }
+
+    /**
+     * We only set one sheet as selected for compatibility with HSSF.
+     */
+    public void setSelectedTab(short index) {
+        for (int i = 0 ; i < this.sheets.size() ; ++i) {
+            XSSFSheet sheet = this.sheets.get(i);
+            sheet.setSelected(i == index);
+        }
+    }
 
     /**
      * Set the sheet name.
      * Will throw IllegalArgumentException if the name is greater than 31 chars
      * or contains /\?*[]
+     *
      * @param sheet number (0 based)
+     * @see #validateSheetName(String)
      */
-	public void setSheetName(int sheet, String name) {
-		if (doesContainsSheetName(name, sheet ))
-			throw new IllegalArgumentException( "The workbook already contains a sheet of this name" );
-		this.workbook.getSheets().getSheetArray(sheet).setName(name);
-	}
+    public void setSheetName(int sheet, String name) {
+        validateSheetIndex(sheet);
+        validateSheetName(name);
+        if (containsSheet(name, sheet ))
+            throw new IllegalArgumentException( "The workbook already contains a sheet of this name" );
+        this.workbook.getSheets().getSheetArray(sheet).setName(name);
+    }
 
     /**
      * sets the order of appearance for a given sheet.
@@ -830,20 +835,20 @@
      * @param sheetname the name of the sheet to reorder
      * @param pos the position that we want to insert the sheet into (0 based)
      */
-	public void setSheetOrder(String sheetname, int pos) {
-		int idx = getSheetIndex(sheetname);
-		sheets.add(pos, sheets.remove(idx));
-		// Reorder CTSheets
-		XmlObject cts = this.workbook.getSheets().getSheetArray(idx).copy();
-		this.workbook.getSheets().removeSheet(idx);
-		CTSheet newcts = this.workbook.getSheets().insertNewSheet(pos);
-		newcts.set(cts);
-	}
+    public void setSheetOrder(String sheetname, int pos) {
+        int idx = getSheetIndex(sheetname);
+        sheets.add(pos, sheets.remove(idx));
+        // Reorder CTSheets
+        XmlObject cts = this.workbook.getSheets().getSheetArray(idx).copy();
+        this.workbook.getSheets().removeSheet(idx);
+        CTSheet newcts = this.workbook.getSheets().insertNewSheet(pos);
+        newcts.set(cts);
+    }
 
-	public void unwriteProtectWorkbook() {
-		// TODO Auto-generated method stub
+    public void unwriteProtectWorkbook() {
+        // TODO Auto-generated method stub
 
-	}
+    }
 
     /**
      * marshal named ranges from the {@link #namedRanges} collection to the underlying CTWorkbook bean
@@ -892,12 +897,12 @@
         save();
 
         getPackage().save(stream);
-	}
+    }
 
-	public void writeProtectWorkbook(String password, String username) {
-		// TODO Auto-generated method stub
+    public void writeProtectWorkbook(String password, String username) {
+        // TODO Auto-generated method stub
 
-	}
+    }
 
     /**
      * Returns SharedStringsTable - tha cache of string for this workbook
@@ -905,32 +910,32 @@
      * @return the shared string table
      */
     public SharedStringsTable getSharedStringSource() {
-		return this.sharedStringSource;
-	}
+        return this.sharedStringSource;
+    }
     //TODO do we really need setSharedStringSource?
     protected void setSharedStringSource(SharedStringsTable sharedStringSource) {
-		this.sharedStringSource = sharedStringSource;
-	}
+        this.sharedStringSource = sharedStringSource;
+    }
 
     /**
      * Return a object representing a collection of shared objects used for styling content,
      * e.g. fonts, cell styles, colors, etc.
      */
-	public StylesSource getStylesSource() {
-		return this.stylesSource;
-	}
+    public StylesSource getStylesSource() {
+        return this.stylesSource;
+    }
     //TODO do we really need setStylesSource?
-	protected void setStylesSource(StylesSource stylesSource) {
-		this.stylesSource = stylesSource;
-	}
+    protected void setStylesSource(StylesSource stylesSource) {
+        this.stylesSource = stylesSource;
+    }
 
     /**
      * Returns an object that handles instantiating concrete
      *  classes of the various instances for XSSF.
      */
-	public XSSFCreationHelper getCreationHelper() {
-		return new XSSFCreationHelper(this);
-	}
+    public XSSFCreationHelper getCreationHelper() {
+        return new XSSFCreationHelper(this);
+    }
 
     /**
      * Determines whether a workbook contains the provided sheet name.
@@ -939,15 +944,37 @@
      * @param excludeSheetIdx the sheet to exclude from the check or -1 to include all sheets in the check.
      * @return true if the sheet contains the name, false otherwise.
      */
-	private boolean doesContainsSheetName(String name, int excludeSheetIdx) {
-		CTSheet[] ctSheetArray = workbook.getSheets().getSheetArray();
-		for (int i = 0; i < ctSheetArray.length; i++) {
-			if (excludeSheetIdx != i && name.equalsIgnoreCase(ctSheetArray[i].getName()))
-				return true;
-		}
-		return false;
-	}
+    private boolean containsSheet(String name, int excludeSheetIdx) {
+        CTSheet[] ctSheetArray = workbook.getSheets().getSheetArray();
+        for (int i = 0; i < ctSheetArray.length; i++) {
+            if (excludeSheetIdx != i && name.equalsIgnoreCase(ctSheetArray[i].getName()))
+                return true;
+        }
+        return false;
+    }
 
+    /**
+     * Validates sheet name.
+     *
+     * <p>
+     * The character count <tt>MUST</tt> be greater than or equal to 1 and less than or equal to 31.
+     * The string MUST NOT contain the any of the following characters:
+     * <ul>
+     * <li> 0x0000 </li>
+     * <li> 0x0003 </li>
+     * <li> colon (:) </li>
+     * <li> backslash (\) </li>
+     * <li> asterisk (*) </li>
+     * <li> question mark (?) </li>
+     * <li> forward slash (/) </li>
+     * <li> opening square bracket ([) </li>
+     * <li> closing square bracket (]) </li>
+     * </ul>
+     * The string MUST NOT begin or end with the single quote (') character.
+     * </p>
+     *
+     * @param sheetName the name to validate
+     */
     private static void validateSheetName(String sheetName) {
         if (sheetName == null) {
             throw new IllegalArgumentException("sheetName must not be null");
@@ -975,4 +1002,17 @@
                     + ") found at index (" + i + ") in sheet name '" + sheetName + "'");
         }
      }
+
+    /**
+     * Gets a boolean value that indicates whether the date systems used in the workbook starts in 1904.
+     * <p>
+     * The default value is false, meaning that the workbook uses the 1900 date system,
+     * where 1/1/1900 is the first day in the system..
+     * </p>
+     * @return true if the date systems used in the workbook starts in 1904
+     */
+    protected boolean isDate1904(){
+        CTWorkbookPr workbookPr = workbook.getWorkbookPr();
+        return workbookPr != null && workbookPr.getDate1904();
+    }
 }

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java?rev=700844&r1=700843&r2=700844&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCell.java Wed Oct  1 10:15:02 2008
@@ -23,17 +23,21 @@
 
 import junit.framework.TestCase;
 
+import org.apache.poi.hssf.usermodel.HSSFCell;
+import org.apache.poi.hssf.usermodel.HSSFRichTextString;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Comment;
 import org.apache.poi.ss.usermodel.CreationHelper;
+import org.apache.poi.ss.usermodel.DataFormat;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
 import org.apache.poi.xssf.XSSFTestDataSamples;
 import org.apache.poi.xssf.model.CommentsTable;
-import org.apache.poi.xssf.model.SharedStringsTable;
 import org.apache.poi.xssf.model.SharedStringSource;
+import org.apache.poi.xssf.model.SharedStringsTable;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComment;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTComments;
@@ -108,6 +112,10 @@
         } catch (NumberFormatException e) {
             // success
         }
+        
+        cell.setCellValue(cal);
+        assertEquals(before1904,cell.getDateCellValue());
+        
     }
     
     public void testSetGetError() throws Exception {
@@ -379,4 +387,82 @@
     		fail();
     	} catch(IllegalArgumentException e) {}
     }
+    
+    
+    public void testHSSFXSSFToString(){
+	Workbook xwb = new XSSFWorkbook();
+    	Sheet xsheet = xwb.createSheet();
+    	XSSFCell xcell = (XSSFCell) xsheet.createRow(0).createCell((short)0);
+    	
+    	Workbook hwb=new HSSFWorkbook();
+    	Sheet hsheet=hwb.createSheet();
+    	HSSFCell hcell = (HSSFCell) hsheet.createRow(0).createCell((short)0);
+
+    	//BLANK
+    	assertEquals(hcell.toString(),xcell.toString());
+    	System.out.println("BLANK==> xssf="+xcell.toString() + " - hssf="+hcell.toString());
+    	//BOOLEAN
+    	xcell.setCellValue(true);
+    	xcell.setCellType(Cell.CELL_TYPE_BOOLEAN);
+    	hcell.setCellValue(true);
+    	hcell.setCellType(Cell.CELL_TYPE_BOOLEAN);
+    	System.out.println("BOOLEAN==> xssf="+xcell.toString() + " - hssf="+hcell.toString());
+    	assertEquals(hcell.toString(),xcell.toString());
+    	
+	//NUMERIC
+
+    	xcell.setCellValue(1234);
+    	xcell.setCellType(Cell.CELL_TYPE_NUMERIC);
+    	hcell.setCellValue(1234);
+    	hcell.setCellType(Cell.CELL_TYPE_NUMERIC);
+    	System.out.println("NUMERIC==> xssf="+xcell.toString() + " - hssf="+hcell.toString());
+    	assertEquals(hcell.toString(),xcell.toString());
+    	
+    	//DATE ********************
+    	
+    	Calendar cal = Calendar.getInstance();
+        cal.set(1903, 1, 8);
+    	xcell.setCellValue(cal.getTime());
+    	CellStyle xstyle=xwb.createCellStyle();
+        DataFormat format = xwb.createDataFormat();
+    	xstyle.setDataFormat(format.getFormat("YYYY-MM-DD"));
+    	xcell.setCellStyle(xstyle);
+
+    	hcell.setCellValue(cal.getTime());
+    	CellStyle hstyle=hwb.createCellStyle();
+        DataFormat hformat = hwb.createDataFormat();
+    	hstyle.setDataFormat(hformat.getFormat("YYYY-MM-DD"));
+    	hcell.setCellStyle(hstyle);
+    	
+    	System.out.println("DATE==> xssf="+xcell.toString() + " - hssf="+hcell.toString());
+    	assertEquals(hcell.toString(),xcell.toString());
+    	
+    	
+    	//STRING
+    	xcell.setCellValue(new XSSFRichTextString("text string"));
+    	xcell.setCellType(Cell.CELL_TYPE_STRING);
+    	hcell.setCellValue(new HSSFRichTextString("text string"));
+    	hcell.setCellType(Cell.CELL_TYPE_STRING);
+    	System.out.println("STRING==> xssf="+xcell.toString() + " - hssf="+hcell.toString());
+    	assertEquals(hcell.toString(),xcell.toString());
+    	
+    	//ERROR
+    	xcell.setCellErrorValue(Cell.ERROR_VALUE);
+    	xcell.setCellType(Cell.CELL_TYPE_ERROR);
+
+    	hcell.setCellErrorValue((byte)0);
+    	hcell.setCellType(Cell.CELL_TYPE_ERROR);
+
+    	System.out.println("ERROR==> xssf="+xcell.toString() + " - hssf="+hcell.toString());
+    	assertEquals(hcell.toString(),xcell.toString());
+    	
+    	//FORMULA
+    	xcell.setCellFormula("A1+B2");
+    	hcell.setCellValue("A1+B2");
+    	System.out.println("FORMULA==> xssf="+xcell.toString() + " - hssf="+hcell.toString());
+    	assertEquals(hcell.toString(),xcell.toString());
+    	
+    }
+    
+    
 }

Modified: poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java?rev=700844&r1=700843&r2=700844&view=diff
==============================================================================
--- poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java (original)
+++ poi/branches/ooxml/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java Wed Oct  1 10:15:02 2008
@@ -510,6 +510,14 @@
         assertFalse(sheet.isDisplayGridlines());
     }
     
+    public void testIsSetDisplayGuts() {
+        XSSFWorkbook workbook = new XSSFWorkbook();
+        XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");
+        assertTrue(sheet.getDisplayGuts());
+        sheet.setDisplayGuts(false);
+        assertFalse(sheet.getDisplayGuts());
+    }
+    
     public void testIsSetDisplayRowColHeadings() {
         XSSFWorkbook workbook = new XSSFWorkbook();
         XSSFSheet sheet = (XSSFSheet) workbook.createSheet("Sheet 1");



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org