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 2009/06/11 07:43:17 UTC

svn commit: r783636 - in /poi/tags/REL_3_5_BETA6/src: contrib/src/org/apache/poi/hssf/usermodel/contrib/ contrib/src/org/apache/poi/ss/ contrib/src/org/apache/poi/ss/usermodel/ contrib/src/org/apache/poi/ss/usermodel/contrib/ documentation/content/xdoc...

Author: yegor
Date: Thu Jun 11 05:43:16 2009
New Revision: 783636

URL: http://svn.apache.org/viewvc?rev=783636&view=rev
Log:
merged with trunk r783635

Added:
    poi/tags/REL_3_5_BETA6/src/contrib/src/org/apache/poi/ss/
      - copied from r783635, poi/trunk/src/contrib/src/org/apache/poi/ss/
    poi/tags/REL_3_5_BETA6/src/contrib/src/org/apache/poi/ss/usermodel/
      - copied from r783635, poi/trunk/src/contrib/src/org/apache/poi/ss/usermodel/
    poi/tags/REL_3_5_BETA6/src/contrib/src/org/apache/poi/ss/usermodel/contrib/
      - copied from r783635, poi/trunk/src/contrib/src/org/apache/poi/ss/usermodel/contrib/
    poi/tags/REL_3_5_BETA6/src/contrib/src/org/apache/poi/ss/usermodel/contrib/CellUtil.java
      - copied unchanged from r783635, poi/trunk/src/contrib/src/org/apache/poi/ss/usermodel/contrib/CellUtil.java
    poi/tags/REL_3_5_BETA6/src/contrib/src/org/apache/poi/ss/usermodel/contrib/RegionUtil.java
      - copied unchanged from r783635, poi/trunk/src/contrib/src/org/apache/poi/ss/usermodel/contrib/RegionUtil.java
    poi/tags/REL_3_5_BETA6/src/testcases/org/apache/poi/hssf/data/WrongFormulaRecordType.xls
      - copied unchanged from r783635, poi/trunk/src/testcases/org/apache/poi/hssf/data/WrongFormulaRecordType.xls
Modified:
    poi/tags/REL_3_5_BETA6/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFCellUtil.java
    poi/tags/REL_3_5_BETA6/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFRegionUtil.java
    poi/tags/REL_3_5_BETA6/src/documentation/content/xdocs/status.xml
    poi/tags/REL_3_5_BETA6/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/tags/REL_3_5_BETA6/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java
    poi/tags/REL_3_5_BETA6/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java

Modified: poi/tags/REL_3_5_BETA6/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFCellUtil.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_5_BETA6/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFCellUtil.java?rev=783636&r1=783635&r2=783636&view=diff
==============================================================================
--- poi/tags/REL_3_5_BETA6/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFCellUtil.java (original)
+++ poi/tags/REL_3_5_BETA6/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFCellUtil.java Thu Jun 11 05:43:16 2009
@@ -18,16 +18,13 @@
 package org.apache.poi.hssf.usermodel.contrib;
 
 
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFCellStyle;
 import org.apache.poi.hssf.usermodel.HSSFFont;
-import org.apache.poi.hssf.usermodel.HSSFRichTextString;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.contrib.CellUtil;
 
 /**
  *  Various utility functions that make working with a cells and rows easier.  The various
@@ -39,42 +36,7 @@
  *
  *@author     Eric Pugh epugh@upstate.com
  */
-public final class HSSFCellUtil
-{
-
-    public static final String ALIGNMENT = "alignment";
-    public static final String BORDER_BOTTOM = "borderBottom";
-    public static final String BORDER_LEFT = "borderLeft";
-    public static final String BORDER_RIGHT = "borderRight";
-    public static final String BORDER_TOP = "borderTop";
-    public static final String BOTTOM_BORDER_COLOR = "bottomBorderColor";
-    public static final String DATA_FORMAT = "dataFormat";
-    public static final String FILL_BACKGROUND_COLOR = "fillBackgroundColor";
-    public static final String FILL_FOREGROUND_COLOR = "fillForegroundColor";
-    public static final String FILL_PATTERN = "fillPattern";
-    public static final String FONT = "font";
-    public static final String HIDDEN = "hidden";
-    public static final String INDENTION = "indention";
-    public static final String LEFT_BORDER_COLOR = "leftBorderColor";
-    public static final String LOCKED = "locked";
-    public static final String RIGHT_BORDER_COLOR = "rightBorderColor";
-    public static final String ROTATION = "rotation";
-    public static final String TOP_BORDER_COLOR = "topBorderColor";
-    public static final String VERTICAL_ALIGNMENT = "verticalAlignment";
-    public static final String WRAP_TEXT = "wrapText";
-
-    private static UnicodeMapping unicodeMappings[];
-
-    private static final class UnicodeMapping {
-
-        public final String entityName;
-        public final String resolvedValue;
-
-        public UnicodeMapping(String pEntityName, String pResolvedValue) {
-            entityName = "&" + pEntityName + ";";
-            resolvedValue = pResolvedValue;
-        }
-    }
+public final class HSSFCellUtil {
 
     private HSSFCellUtil() {
         // no instances of this class
@@ -83,42 +45,26 @@
     /**
      *  Get a row from the spreadsheet, and create it if it doesn't exist.
      *
-     *@param  rowCounter  The 0 based row number
+     *@param  rowIndex  The 0 based row number
      *@param  sheet       The sheet that the row is part of.
      *@return             The row indicated by the rowCounter
      */
-    public static HSSFRow getRow( int rowCounter, HSSFSheet sheet )
-    {
-        HSSFRow row = sheet.getRow( rowCounter );
-        if ( row == null )
-        {
-            row = sheet.createRow( rowCounter );
-        }
-
-        return row;
+    public static HSSFRow getRow(int rowIndex, HSSFSheet sheet) {
+    	return (HSSFRow) CellUtil.getRow(rowIndex, sheet);
     }
 
-
     /**
-     * Get a specific cell from a row. If the cell doesn't exist, 
+     * Get a specific cell from a row. If the cell doesn't exist,
      *  then create it.
      *
      *@param  row     The row that the cell is part of
-     *@param  column  The column index that the cell is in.
+     *@param  columnIndex  The column index that the cell is in.
      *@return         The cell indicated by the column.
      */
-    public static HSSFCell getCell( HSSFRow row, int column )
-    {
-        HSSFCell cell = row.getCell( column );
-
-        if ( cell == null )
-        {
-            cell = row.createCell(column );
-        }
-        return cell;
+    public static HSSFCell getCell(HSSFRow row, int columnIndex) {
+        return (HSSFCell) CellUtil.getCell(row, columnIndex);
     }
 
-
     /**
      *  Creates a cell, gives it a value, and applies a style if provided
      *
@@ -128,20 +74,10 @@
      * @param  style   If the style is not null, then set
      * @return         A new HSSFCell
      */
-    public static HSSFCell createCell( HSSFRow row, int column, String value, HSSFCellStyle style )
-    {
-        HSSFCell cell = getCell( row, column );
-
-        cell.setCellValue(new HSSFRichTextString(value));
-        if ( style != null )
-        {
-            cell.setCellStyle( style );
-        }
-
-        return cell;
+    public static HSSFCell createCell(HSSFRow row, int column, String value, HSSFCellStyle style) {
+    	return (HSSFCell) CellUtil.createCell(row, column, value, style);
     }
 
-
     /**
      *  Create a cell, and give it a value.
      *
@@ -150,12 +86,10 @@
      *@param  value   The value of the cell
      *@return         A new HSSFCell.
      */
-    public static HSSFCell createCell( HSSFRow row, int column, String value )
-    {
+    public static HSSFCell createCell(HSSFRow row, int column, String value) {
         return createCell( row, column, value, null );
     }
 
-
     /**
      *  Take a cell, and align it.
      *
@@ -165,9 +99,8 @@
      *
      * @see HSSFCellStyle for alignment options
      */
-    public static void setAlignment( HSSFCell cell, HSSFWorkbook workbook, short align )
-    {
-        setCellStyleProperty( cell, workbook, ALIGNMENT, new Short( align ) );
+    public static void setAlignment(HSSFCell cell, HSSFWorkbook workbook, short align) {
+    	CellUtil.setAlignment(cell, workbook, align);
     }
 
     /**
@@ -177,9 +110,8 @@
      *@param  workbook               The workbook that is being worked with.
      *@param  font  The HSSFFont that you want to set...
      */
-    public static void setFont( HSSFCell cell, HSSFWorkbook workbook, HSSFFont font )
-    {
-        setCellStyleProperty( cell, workbook, FONT, font );
+    public static void setFont(HSSFCell cell, HSSFWorkbook workbook, HSSFFont font) {
+    	CellUtil.setFont(cell, workbook, font);
     }
 
     /**
@@ -195,158 +127,10 @@
      *@param  propertyValue          The value of the property that is to be
      *      changed.
      *@param  cell                   The cell that needs it's style changes
-     *@exception  NestableException  Thrown if an error happens.
      */
-    public static void setCellStyleProperty( HSSFCell cell, HSSFWorkbook workbook, String propertyName, Object propertyValue )
-    {
-            HSSFCellStyle originalStyle = cell.getCellStyle();
-            HSSFCellStyle newStyle = null;
-            Map values = getFormatProperties( originalStyle );
-            values.put( propertyName, propertyValue );
-
-            // index seems like what  index the cellstyle is in the list of styles for a workbook.
-            // not good to compare on!
-            short numberCellStyles = workbook.getNumCellStyles();
-
-            for ( short i = 0; i < numberCellStyles; i++ )
-            {
-                HSSFCellStyle wbStyle = workbook.getCellStyleAt( i );
-                Map wbStyleMap = getFormatProperties( wbStyle );
-
-                if ( wbStyleMap.equals( values ) )
-                {
-                    newStyle = wbStyle;
-                    break;
-                }
-            }
-
-            if ( newStyle == null )
-            {
-                newStyle = workbook.createCellStyle();
-                setFormatProperties( newStyle, workbook, values );
-            }
-
-            cell.setCellStyle( newStyle );
-    }
-
-    /**
-     * Returns a map containing the format properties of the given cell style.
-     *
-     * @param style cell style
-     * @return map of format properties (String -> Object)
-     * @see #setFormatProperties(HSSFCellStyle, Map)
-     */
-    private static Map getFormatProperties(HSSFCellStyle style) {
-        Map properties = new HashMap();
-        putShort( properties, ALIGNMENT, style.getAlignment() );
-        putShort( properties, BORDER_BOTTOM, style.getBorderBottom() );
-        putShort( properties, BORDER_LEFT, style.getBorderLeft() );
-        putShort( properties, BORDER_RIGHT, style.getBorderRight() );
-        putShort( properties, BORDER_TOP, style.getBorderTop() );
-        putShort( properties, BOTTOM_BORDER_COLOR, style.getBottomBorderColor() );
-        putShort( properties, DATA_FORMAT, style.getDataFormat() );
-        putShort( properties, FILL_BACKGROUND_COLOR, style.getFillBackgroundColor() );
-        putShort( properties, FILL_FOREGROUND_COLOR, style.getFillForegroundColor() );
-        putShort( properties, FILL_PATTERN, style.getFillPattern() );
-        putShort( properties, FONT, style.getFontIndex() );
-        putBoolean( properties, HIDDEN, style.getHidden() );
-        putShort( properties, INDENTION, style.getIndention() );
-        putShort( properties, LEFT_BORDER_COLOR, style.getLeftBorderColor() );
-        putBoolean( properties, LOCKED, style.getLocked() );
-        putShort( properties, RIGHT_BORDER_COLOR, style.getRightBorderColor() );
-        putShort( properties, ROTATION, style.getRotation() );
-        putShort( properties, TOP_BORDER_COLOR, style.getTopBorderColor() );
-        putShort( properties, VERTICAL_ALIGNMENT, style.getVerticalAlignment() );
-        putBoolean( properties, WRAP_TEXT, style.getWrapText() );
-        return properties;
-    }
-
-    /**
-     * Sets the format properties of the given style based on the given map.
-     *
-     * @param style cell style
-     * @param workbook parent workbook
-     * @param properties map of format properties (String -> Object)
-     * @see #getFormatProperties(HSSFCellStyle)
-     */
-    private static void setFormatProperties(
-            HSSFCellStyle style, HSSFWorkbook workbook, Map properties) {
-        style.setAlignment( getShort( properties, ALIGNMENT ) );
-        style.setBorderBottom( getShort( properties, BORDER_BOTTOM ) );
-        style.setBorderLeft( getShort( properties, BORDER_LEFT ) );
-        style.setBorderRight( getShort( properties, BORDER_RIGHT ) );
-        style.setBorderTop( getShort( properties, BORDER_TOP ) );
-        style.setBottomBorderColor( getShort( properties, BOTTOM_BORDER_COLOR ) );
-        style.setDataFormat( getShort( properties, DATA_FORMAT ) );
-        style.setFillBackgroundColor( getShort( properties, FILL_BACKGROUND_COLOR ) );
-        style.setFillForegroundColor( getShort( properties, FILL_FOREGROUND_COLOR ) );
-        style.setFillPattern( getShort( properties, FILL_PATTERN ) );
-        style.setFont( workbook.getFontAt( getShort( properties, FONT ) ) );
-        style.setHidden( getBoolean( properties, HIDDEN ) );
-        style.setIndention( getShort( properties, INDENTION ) );
-        style.setLeftBorderColor( getShort( properties, LEFT_BORDER_COLOR ) );
-        style.setLocked( getBoolean( properties, LOCKED ) );
-        style.setRightBorderColor( getShort( properties, RIGHT_BORDER_COLOR ) );
-        style.setRotation( getShort( properties, ROTATION ) );
-        style.setTopBorderColor( getShort( properties, TOP_BORDER_COLOR ) );
-        style.setVerticalAlignment( getShort( properties, VERTICAL_ALIGNMENT ) );
-        style.setWrapText( getBoolean( properties, WRAP_TEXT ) );
-    }
-
-    /**
-     * Utility method that returns the named short value form the given map.
-     * Returns zero if the property does not exist, or is not a {@link Short}.
-     *
-     * @param properties map of named properties (String -> Object)
-     * @param name property name
-     * @return property value, or zero
-     */
-    private static short getShort(Map properties, String name) {
-        Object value = properties.get( name );
-        if ( value instanceof Short ) {
-            return ((Short) value).shortValue();
-        } else {
-            return 0;
-        }
-    }
-
-    /**
-     * Utility method that returns the named boolean value form the given map.
-     * Returns false if the property does not exist, or is not a {@link Boolean}.
-     *
-     * @param properties map of properties (String -> Object)
-     * @param name property name
-     * @return property value, or false
-     */
-    private static boolean getBoolean(Map properties, String name) {
-        Object value = properties.get( name );
-        if ( value instanceof Boolean ) {
-            return ((Boolean) value).booleanValue();
-        } else {
-            return false;
-        }
-    }
-
-    /**
-     * Utility method that puts the named short value to the given map.
-     *
-     * @param properties map of properties (String -> Object)
-     * @param name property name
-     * @param value property value
-     */
-    private static void putShort(Map properties, String name, short value) {
-        properties.put( name, new Short( value ) );
-    }
-
-    /**
-     * Utility method that puts the named boolean value to the given map.
-     *
-     * @param properties map of properties (String -> Object)
-     * @param name property name
-     * @param value property value
-     */
-    private static void putBoolean(Map properties, String name, boolean value) {
-        properties.put( name, new Boolean( value ) );
+    public static void setCellStyleProperty(HSSFCell cell, HSSFWorkbook workbook,
+			String propertyName, Object propertyValue) {
+    	CellUtil.setCellStyleProperty(cell, workbook, propertyName, propertyValue);
     }
 
     /**
@@ -354,52 +138,10 @@
      *  unicode version of it.
      *
      *@param  cell  The cell to check for unicode values
-     *@return       transalted to unicode
+     *@return       translated to unicode
      */
-    public static HSSFCell translateUnicodeValues( HSSFCell cell )
-    {
-
-        String s = cell.getRichStringCellValue().getString(); 
-        boolean foundUnicode = false;
-        String lowerCaseStr = s.toLowerCase();
-
-        for (int i = 0; i < unicodeMappings.length; i++) {
-            UnicodeMapping entry = unicodeMappings[i];
-            String key = entry.entityName;
-            if ( lowerCaseStr.indexOf( key ) != -1 )
-            {
-                s =  s.replaceAll(key, entry.resolvedValue);
-                foundUnicode = true;
-            }
-        }
-        if ( foundUnicode )
-        {
-            cell.setCellValue(new HSSFRichTextString(s));
-        }
-        return cell;
-    }
-
-    static {
-        unicodeMappings = new UnicodeMapping[] {
-            um("alpha",   "\u03B1" ),
-            um("beta",    "\u03B2" ),
-            um("gamma",   "\u03B3" ),
-            um("delta",   "\u03B4" ),
-            um("epsilon", "\u03B5" ),
-            um("zeta",    "\u03B6" ),
-            um("eta",     "\u03B7" ),
-            um("theta",   "\u03B8" ),
-            um("iota",    "\u03B9" ),
-            um("kappa",   "\u03BA" ),
-            um("lambda",  "\u03BB" ),
-            um("mu",      "\u03BC" ),
-            um("nu",      "\u03BD" ),
-            um("xi",      "\u03BE" ),
-            um("omicron", "\u03BF" ),
-        };
-    }
-
-    private static UnicodeMapping um(String entityName, String resolvedValue) {
-        return new UnicodeMapping(entityName, resolvedValue);
+    public static HSSFCell translateUnicodeValues(HSSFCell cell){
+    	CellUtil.translateUnicodeValues(cell);
+    	return cell;
     }
 }

Modified: poi/tags/REL_3_5_BETA6/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFRegionUtil.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_5_BETA6/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFRegionUtil.java?rev=783636&r1=783635&r2=783636&view=diff
==============================================================================
--- poi/tags/REL_3_5_BETA6/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFRegionUtil.java (original)
+++ poi/tags/REL_3_5_BETA6/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFRegionUtil.java Thu Jun 11 05:43:16 2009
@@ -17,16 +17,15 @@
 
 package org.apache.poi.hssf.usermodel.contrib;
 
-import org.apache.poi.hssf.usermodel.HSSFCell;
-import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.usermodel.contrib.RegionUtil;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.ss.util.Region;
 
 /**
  * Various utility functions that make working with a region of cells easier.
- * 
+ *
  * @author Eric Pugh epugh@upstate.com
  */
 public final class HSSFRegionUtil {
@@ -34,25 +33,6 @@
 	private HSSFRegionUtil() {
 		// no instances of this class
 	}
-	/**
-	 * For setting the same property on many cells to the same value
-	 */
-	private static final class CellPropertySetter {
-
-		private final HSSFWorkbook _workbook;
-		private final String _propertyName;
-		private final Short _propertyValue;
-
-		public CellPropertySetter(HSSFWorkbook workbook, String propertyName, int value) {
-			_workbook = workbook;
-			_propertyName = propertyName;
-			_propertyValue = new Short((short)value);
-		}
-		public void setProperty(HSSFRow row, int column) {
-			HSSFCell cell = HSSFCellUtil.getCell(row, column);
-			HSSFCellUtil.setCellStyleProperty(cell, _workbook, _propertyName, _propertyValue);
-		}
-	}
 
 	private static CellRangeAddress toCRA(Region region) {
 		return Region.convertToCellRangeAddress(region);
@@ -68,7 +48,7 @@
 	/**
 	 * Sets the left border for a region of cells by manipulating the cell style
 	 * of the individual cells on the left
-	 * 
+	 *
 	 * @param border The new border
 	 * @param region The region that should have the border
 	 * @param workbook The workbook that the region is on.
@@ -76,14 +56,7 @@
 	 */
 	public static void setBorderLeft(int border, CellRangeAddress region, HSSFSheet sheet,
 			HSSFWorkbook workbook) {
-		int rowStart = region.getFirstRow();
-		int rowEnd = region.getLastRow();
-		int column = region.getFirstColumn();
-
-		CellPropertySetter cps = new CellPropertySetter(workbook, HSSFCellUtil.BORDER_LEFT, border);
-		for (int i = rowStart; i <= rowEnd; i++) {
-			cps.setProperty(HSSFCellUtil.getRow(i, sheet), column);
-		}
+		RegionUtil.setBorderLeft(border, region, sheet, workbook);
 	}
 
 	/**
@@ -95,7 +68,7 @@
 	}
 	/**
 	 * Sets the leftBorderColor attribute of the HSSFRegionUtil object
-	 * 
+	 *
 	 * @param color The color of the border
 	 * @param region The region that should have the border
 	 * @param workbook The workbook that the region is on.
@@ -103,14 +76,7 @@
 	 */
 	public static void setLeftBorderColor(int color, CellRangeAddress region, HSSFSheet sheet,
 			HSSFWorkbook workbook) {
-		int rowStart = region.getFirstRow();
-		int rowEnd = region.getLastRow();
-		int column = region.getFirstColumn();
-
-		CellPropertySetter cps = new CellPropertySetter(workbook, HSSFCellUtil.LEFT_BORDER_COLOR, color);
-		for (int i = rowStart; i <= rowEnd; i++) {
-			cps.setProperty(HSSFCellUtil.getRow(i, sheet), column);
-		}
+		RegionUtil.setLeftBorderColor(color, region, sheet, workbook);
 	}
 
 	/**
@@ -122,7 +88,7 @@
 	}
 	/**
 	 * Sets the borderRight attribute of the HSSFRegionUtil object
-	 * 
+	 *
 	 * @param border The new border
 	 * @param region The region that should have the border
 	 * @param workbook The workbook that the region is on.
@@ -130,14 +96,7 @@
 	 */
 	public static void setBorderRight(int border, CellRangeAddress region, HSSFSheet sheet,
 			HSSFWorkbook workbook) {
-		int rowStart = region.getFirstRow();
-		int rowEnd = region.getLastRow();
-		int column = region.getLastColumn();
-
-		CellPropertySetter cps = new CellPropertySetter(workbook, HSSFCellUtil.BORDER_RIGHT, border);
-		for (int i = rowStart; i <= rowEnd; i++) {
-			cps.setProperty(HSSFCellUtil.getRow(i, sheet), column);
-		}
+		RegionUtil.setBorderRight(border, region, sheet, workbook);
 	}
 
 	/**
@@ -149,7 +108,7 @@
 	}
 	/**
 	 * Sets the rightBorderColor attribute of the HSSFRegionUtil object
-	 * 
+	 *
 	 * @param color The color of the border
 	 * @param region The region that should have the border
 	 * @param workbook The workbook that the region is on.
@@ -157,14 +116,7 @@
 	 */
 	public static void setRightBorderColor(int color, CellRangeAddress region, HSSFSheet sheet,
 			HSSFWorkbook workbook) {
-		int rowStart = region.getFirstRow();
-		int rowEnd = region.getLastRow();
-		int column = region.getLastColumn();
-
-		CellPropertySetter cps = new CellPropertySetter(workbook, HSSFCellUtil.RIGHT_BORDER_COLOR, color);
-		for (int i = rowStart; i <= rowEnd; i++) {
-			cps.setProperty(HSSFCellUtil.getRow(i, sheet), column);
-		}
+		RegionUtil.setRightBorderColor(color, region, sheet, workbook);
 	}
 
 	/**
@@ -176,7 +128,7 @@
 	}
 	/**
 	 * Sets the borderBottom attribute of the HSSFRegionUtil object
-	 * 
+	 *
 	 * @param border The new border
 	 * @param region The region that should have the border
 	 * @param workbook The workbook that the region is on.
@@ -184,14 +136,7 @@
 	 */
 	public static void setBorderBottom(int border, CellRangeAddress region, HSSFSheet sheet,
 			HSSFWorkbook workbook) {
-		int colStart = region.getFirstColumn();
-		int colEnd = region.getLastColumn();
-		int rowIndex = region.getLastRow();
-		CellPropertySetter cps = new CellPropertySetter(workbook, HSSFCellUtil.BORDER_BOTTOM, border);
-		HSSFRow row = HSSFCellUtil.getRow(rowIndex, sheet);
-		for (int i = colStart; i <= colEnd; i++) {
-			cps.setProperty(row, i);
-		}
+		RegionUtil.setBorderBottom(border, region, sheet, workbook);
 	}
 
 	/**
@@ -203,7 +148,7 @@
 	}
 	/**
 	 * Sets the bottomBorderColor attribute of the HSSFRegionUtil object
-	 * 
+	 *
 	 * @param color The color of the border
 	 * @param region The region that should have the border
 	 * @param workbook The workbook that the region is on.
@@ -211,14 +156,7 @@
 	 */
 	public static void setBottomBorderColor(int color, CellRangeAddress region, HSSFSheet sheet,
 			HSSFWorkbook workbook) {
-		int colStart = region.getFirstColumn();
-		int colEnd = region.getLastColumn();
-		int rowIndex = region.getLastRow();
-		CellPropertySetter cps = new CellPropertySetter(workbook, HSSFCellUtil.BOTTOM_BORDER_COLOR, color);
-		HSSFRow row = HSSFCellUtil.getRow(rowIndex, sheet);
-		for (int i = colStart; i <= colEnd; i++) {
-			cps.setProperty(row, i);
-		}
+		RegionUtil.setBottomBorderColor(color, region, sheet, workbook);
 	}
 
 	/**
@@ -230,7 +168,7 @@
 	}
 	/**
 	 * Sets the borderBottom attribute of the HSSFRegionUtil object
-	 * 
+	 *
 	 * @param border The new border
 	 * @param region The region that should have the border
 	 * @param workbook The workbook that the region is on.
@@ -238,14 +176,7 @@
 	 */
 	public static void setBorderTop(int border, CellRangeAddress region, HSSFSheet sheet,
 			HSSFWorkbook workbook) {
-		int colStart = region.getFirstColumn();
-		int colEnd = region.getLastColumn();
-		int rowIndex = region.getFirstRow();
-		CellPropertySetter cps = new CellPropertySetter(workbook, HSSFCellUtil.BORDER_TOP, border);
-		HSSFRow row = HSSFCellUtil.getRow(rowIndex, sheet);
-		for (int i = colStart; i <= colEnd; i++) {
-			cps.setProperty(row, i);
-		}
+		RegionUtil.setBorderTop(border, region, sheet, workbook);
 	}
 
 	/**
@@ -257,7 +188,7 @@
 	}
 	/**
 	 * Sets the topBorderColor attribute of the HSSFRegionUtil object
-	 * 
+	 *
 	 * @param color The color of the border
 	 * @param region  The region that should have the border
 	 * @param workbook The workbook that the region is on.
@@ -265,13 +196,6 @@
 	 */
 	public static void setTopBorderColor(int color, CellRangeAddress region, HSSFSheet sheet,
 			HSSFWorkbook workbook) {
-		int colStart = region.getFirstColumn();
-		int colEnd = region.getLastColumn();
-		int rowIndex = region.getFirstRow();
-		CellPropertySetter cps = new CellPropertySetter(workbook, HSSFCellUtil.TOP_BORDER_COLOR, color);
-		HSSFRow row = HSSFCellUtil.getRow(rowIndex, sheet);
-		for (int i = colStart; i <= colEnd; i++) {
-			cps.setProperty(row, i);
-		}
+		RegionUtil.setTopBorderColor(color, region, sheet, workbook);
 	}
 }

Modified: poi/tags/REL_3_5_BETA6/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_5_BETA6/src/documentation/content/xdocs/status.xml?rev=783636&r1=783635&r2=783636&view=diff
==============================================================================
--- poi/tags/REL_3_5_BETA6/src/documentation/content/xdocs/status.xml (original)
+++ poi/tags/REL_3_5_BETA6/src/documentation/content/xdocs/status.xml Thu Jun 11 05:43:16 2009
@@ -35,6 +35,7 @@
         <release version="3.5-beta7" date="2009-??-??">
         </release>
         <release version="3.5-beta6" date="2009-06-??">
+           <action dev="POI-DEVELOPERS" type="fix">47294 - Fixed XSSFWorkbook#setRepeatingRowsAndColumns to tolerate sheet names with quotes</action>
            <action dev="POI-DEVELOPERS" type="fix">47309 - Fixed logic in HSSFCell.getCellComment to handle sheets with more than 65536 comments</action>
            <action dev="POI-DEVELOPERS" type="fix">46776 - Added clone() method to MulBlankRecord to fix crash in Sheet.cloneSheet()</action>
            <action dev="POI-DEVELOPERS" type="fix">47244 - Fixed HSSFSheet to handle missing header / footer records</action>

Modified: poi/tags/REL_3_5_BETA6/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_5_BETA6/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=783636&r1=783635&r2=783636&view=diff
==============================================================================
--- poi/tags/REL_3_5_BETA6/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (original)
+++ poi/tags/REL_3_5_BETA6/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java Thu Jun 11 05:43:16 2009
@@ -944,7 +944,9 @@
         CellReference colRef = new CellReference(sheetName, 0, startC, true, true);
         CellReference colRef2 = new CellReference(sheetName, 0, endC, true, true);
 
-        String c = "'" + sheetName + "'!$" + colRef.getCellRefParts()[2] + ":$" + colRef2.getCellRefParts()[2];
+        String escapedName = SheetNameFormatter.format(sheetName);
+
+        String c = escapedName + "!$" + colRef.getCellRefParts()[2] + ":$" + colRef2.getCellRefParts()[2];
 
         CellReference rowRef = new CellReference(sheetName, startR, 0, true, true);
         CellReference rowRef2 = new CellReference(sheetName, endR, 0, true, true);
@@ -952,7 +954,7 @@
         String r = "";
 
         if (!rowRef.getCellRefParts()[1].equals("0") && !rowRef2.getCellRefParts()[1].equals("0")) {
-            r = ",'" + sheetName + "'!$" + rowRef.getCellRefParts()[1] + ":$" + rowRef2.getCellRefParts()[1];
+            r = "," + escapedName + "!$" + rowRef.getCellRefParts()[1] + ":$" + rowRef2.getCellRefParts()[1];
         }
         return c + r;
     }

Modified: poi/tags/REL_3_5_BETA6/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_5_BETA6/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java?rev=783636&r1=783635&r2=783636&view=diff
==============================================================================
--- poi/tags/REL_3_5_BETA6/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java (original)
+++ poi/tags/REL_3_5_BETA6/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFName.java Thu Jun 11 05:43:16 2009
@@ -37,7 +37,7 @@
         // First test that setting RR&C for same sheet more than once only creates a
         // single  Print_Titles built-in record
         XSSFWorkbook wb = getTestDataProvider().createWorkbook();
-        XSSFSheet sheet = wb.createSheet("FirstSheet");
+        XSSFSheet sheet = wb.createSheet("First Sheet");
 
         // set repeating rows and columns twice for the first sheet
         for (int i = 0; i < 2; i++) {
@@ -48,7 +48,7 @@
         XSSFName nr1 = wb.getNameAt(0);
 
         assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr1.getNameName());
-        assertEquals("'FirstSheet'!$A:$A,'FirstSheet'!$1:$4", nr1.getRefersToFormula());
+        assertEquals("'First Sheet'!$A:$A,'First Sheet'!$1:$4", nr1.getRefersToFormula());
 
         // Save and re-open
         XSSFWorkbook nwb = XSSFTestDataSamples.writeOutAndReadBack(wb);
@@ -57,7 +57,7 @@
         nr1 = nwb.getNameAt(0);
 
         assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr1.getNameName());
-        assertEquals("'FirstSheet'!$A:$A,'FirstSheet'!$1:$4", nr1.getRefersToFormula());
+        assertEquals("'First Sheet'!$A:$A,'First Sheet'!$1:$4", nr1.getRefersToFormula());
 
         // check that setting RR&C on a second sheet causes a new Print_Titles built-in
         // name to be created
@@ -68,7 +68,7 @@
         XSSFName nr2 = nwb.getNameAt(1);
 
         assertEquals(XSSFName.BUILTIN_PRINT_TITLE, nr2.getNameName());
-        assertEquals("'SecondSheet'!$B:$C,'SecondSheet'!$1:$1", nr2.getRefersToFormula());
+        assertEquals("SecondSheet!$B:$C,SecondSheet!$1:$1", nr2.getRefersToFormula());
 
         nwb.setRepeatingRowsAndColumns(1, -1, -1, -1, -1);
     }

Modified: poi/tags/REL_3_5_BETA6/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java
URL: http://svn.apache.org/viewvc/poi/tags/REL_3_5_BETA6/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java?rev=783636&r1=783635&r2=783636&view=diff
==============================================================================
--- poi/tags/REL_3_5_BETA6/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java (original)
+++ poi/tags/REL_3_5_BETA6/src/testcases/org/apache/poi/ss/usermodel/BaseTestWorkbook.java Thu Jun 11 05:43:16 2009
@@ -293,6 +293,16 @@
         assertSame(row, cell.getRow());
     }
 
+    public void testSetRepeatingRowsAnsColumns(){
+        Workbook wb = getTestDataProvider().createWorkbook();
+        Sheet sheet1 = wb.createSheet();
+        wb.setRepeatingRowsAndColumns(wb.getSheetIndex(sheet1), 0, 0, 0, 3);
+
+        //must handle sheets with quotas, see Bugzilla #47294
+        Sheet sheet2 = wb.createSheet("My' Sheet");
+        wb.setRepeatingRowsAndColumns(wb.getSheetIndex(sheet2), 0, 0, 0, 3);
+    }
+
     /**
      * Tests that all of the unicode capable string fields can be set, written and then read back
      */



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