View | Details | Raw Unified | Return to bug 45410
Collapse All | Expand All

(-)a/build.xml (-9 / +4 lines)
Lines 101-112 under the License. Link Here
101
  <property name="contrib.reports.test" location="build/contrib-test-results"/>
101
  <property name="contrib.reports.test" location="build/contrib-test-results"/>
102
  <property name="contrib.output.dir" location="build/contrib-classes"/>
102
  <property name="contrib.output.dir" location="build/contrib-classes"/>
103
  <property name="contrib.output.test.dir" location="build/contrib-test-classes"/>
103
  <property name="contrib.output.test.dir" location="build/contrib-test-classes"/>
104
  <property name="contrib.jar1.dir" location="${contrib.lib}/commons-beanutils-1.7.0.jar"/>
104
  <property name="contrib.jar1.dir" location="${contrib.lib}/commons-collections-3.2.jar"/>
105
  <property name="contrib.jar1.url" value="${repository}/commons-beanutils/jars/commons-beanutils-1.7.0.jar"/>
105
  <property name="contrib.jar1.url" value="${repository}/commons-collections/jars/commons-collections-3.2.jar"/>
106
  <property name="contrib.jar2.dir" location="${contrib.lib}/commons-collections-3.2.jar"/>
106
  <property name="contrib.jar2.dir" location="${contrib.lib}/commons-lang-2.1.jar"/>
107
  <property name="contrib.jar2.url" value="${repository}/commons-collections/jars/commons-collections-3.2.jar"/>
107
  <property name="contrib.jar2.url" value="${repository}/commons-lang/jars/commons-lang-2.1.jar"/>
108
  <property name="contrib.jar3.dir" location="${contrib.lib}/commons-lang-2.1.jar"/>
109
  <property name="contrib.jar3.url" value="${repository}/commons-lang/jars/commons-lang-2.1.jar"/>
110
  <property name="contrib.testokfile" location="build/contrib-testokfile.txt"/>
108
  <property name="contrib.testokfile" location="build/contrib-testokfile.txt"/>
111
109
112
  <!-- Examples: -->
110
  <!-- Examples: -->
Lines 149-155 under the License. Link Here
149
        <path refid="main.classpath"/>
147
        <path refid="main.classpath"/>
150
        <pathelement location="${contrib.jar1.dir}"/>
148
        <pathelement location="${contrib.jar1.dir}"/>
151
        <pathelement location="${contrib.jar2.dir}"/>
149
        <pathelement location="${contrib.jar2.dir}"/>
152
        <pathelement location="${contrib.jar3.dir}"/>
153
        <pathelement location="${main.output.dir}"/>
150
        <pathelement location="${main.output.dir}"/>
154
        <pathelement location="${main.output.test.dir}"/>
151
        <pathelement location="${main.output.test.dir}"/>
155
        <pathelement location="${scratchpad.output.dir}"/>
152
        <pathelement location="${scratchpad.output.dir}"/>
Lines 261-267 under the License. Link Here
261
                    <available file="${main.jar2.dir}"/>
258
                    <available file="${main.jar2.dir}"/>
262
                    <available file="${contrib.jar1.dir}"/>
259
                    <available file="${contrib.jar1.dir}"/>
263
                    <available file="${contrib.jar2.dir}"/>
260
                    <available file="${contrib.jar2.dir}"/>
264
                    <available file="${contrib.jar3.dir}"/>
265
                    <available file="${junit.jar1.dir}"/>
261
                    <available file="${junit.jar1.dir}"/>
266
                </and>
262
                </and>
267
                <isset property="disconnected"/>
263
                <isset property="disconnected"/>
Lines 275-281 under the License. Link Here
275
        <get src="${main.jar2.url}" dest="${main.jar2.dir}"/>
271
        <get src="${main.jar2.url}" dest="${main.jar2.dir}"/>
276
        <get src="${contrib.jar1.url}" dest="${contrib.jar1.dir}"/>
272
        <get src="${contrib.jar1.url}" dest="${contrib.jar1.dir}"/>
277
        <get src="${contrib.jar2.url}" dest="${contrib.jar2.dir}"/>
273
        <get src="${contrib.jar2.url}" dest="${contrib.jar2.dir}"/>
278
        <get src="${contrib.jar3.url}" dest="${contrib.jar3.dir}"/>
279
        <get src="${junit.jar1.url}" dest="${junit.jar1.dir}"/>
274
        <get src="${junit.jar1.url}" dest="${junit.jar1.dir}"/>
280
    </target>
275
    </target>
281
276
(-)a/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFCellUtil.java (-10 / +145 lines)
Lines 20-26 Link Here
20
package org.apache.poi.hssf.usermodel.contrib;
20
package org.apache.poi.hssf.usermodel.contrib;
21
21
22
22
23
import org.apache.commons.beanutils.PropertyUtils;
24
import org.apache.commons.lang.StringUtils;
23
import org.apache.commons.lang.StringUtils;
25
import org.apache.commons.lang.exception.NestableException;
24
import org.apache.commons.lang.exception.NestableException;
26
import org.apache.poi.hssf.usermodel.*;
25
import org.apache.poi.hssf.usermodel.*;
Lines 43-48 import java.util.Map; Link Here
43
public class HSSFCellUtil
42
public class HSSFCellUtil
44
{
43
{
45
44
45
    public static final String ALIGNMENT = "alignment";
46
    public static final String BORDER_BOTTOM = "borderBottom";
47
    public static final String BORDER_LEFT = "borderLeft";
48
    public static final String BORDER_RIGHT = "borderRight";
49
    public static final String BORDER_TOP = "borderTop";
50
    public static final String BOTTOM_BORDER_COLOR = "bottomBorderColor";
51
    public static final String DATA_FORMAT = "dataFormat";
52
    public static final String FILL_BACKGROUND_COLOR = "fillBackgroundColor";
53
    public static final String FILL_FOREGROUND_COLOR = "fillForegroundColor";
54
    public static final String FILL_PATTERN = "fillPattern";
55
    public static final String FONT = "font";
56
    public static final String HIDDEN = "hidden";
57
    public static final String INDENTION = "indention";
58
    public static final String LEFT_BORDER_COLOR = "leftBorderColor";
59
    public static final String LOCKED = "locked";
60
    public static final String RIGHT_BORDER_COLOR = "rightBorderColor";
61
    public static final String ROTATION = "rotation";
62
    public static final String TOP_BORDER_COLOR = "topBorderColor";
63
    public static final String VERTICAL_ALIGNMENT = "verticalAlignment";
64
    public static final String WRAP_TEXT = "wrapText";
65
46
    private static HashMap unicodeMappings = new HashMap();
66
    private static HashMap unicodeMappings = new HashMap();
47
67
48
68
Lines 135-141 public class HSSFCellUtil Link Here
135
     */
155
     */
136
    public static void setAlignment( HSSFCell cell, HSSFWorkbook workbook, short align ) throws NestableException
156
    public static void setAlignment( HSSFCell cell, HSSFWorkbook workbook, short align ) throws NestableException
137
    {
157
    {
138
        setCellStyleProperty( cell, workbook, "alignment", new Short( align ) );
158
        setCellStyleProperty( cell, workbook, ALIGNMENT, new Short( align ) );
139
    }
159
    }
140
160
141
    /**
161
    /**
Lines 148-154 public class HSSFCellUtil Link Here
148
     */
168
     */
149
    public static void setFont( HSSFCell cell, HSSFWorkbook workbook, HSSFFont font ) throws NestableException
169
    public static void setFont( HSSFCell cell, HSSFWorkbook workbook, HSSFFont font ) throws NestableException
150
    {
170
    {
151
        setCellStyleProperty( cell, workbook, "font", font );
171
        setCellStyleProperty( cell, workbook, FONT, font );
152
    }
172
    }
153
173
154
    /**
174
    /**
Lines 173-181 public class HSSFCellUtil Link Here
173
        {
193
        {
174
            HSSFCellStyle originalStyle = cell.getCellStyle();
194
            HSSFCellStyle originalStyle = cell.getCellStyle();
175
            HSSFCellStyle newStyle = null;
195
            HSSFCellStyle newStyle = null;
176
            Map values = PropertyUtils.describe( originalStyle );
196
            Map values = getFormatProperties( originalStyle );
177
            values.put( propertyName, propertyValue );
197
            values.put( propertyName, propertyValue );
178
            values.remove( "index" );
179
198
180
            // index seems like what  index the cellstyle is in the list of styles for a workbook.
199
            // index seems like what  index the cellstyle is in the list of styles for a workbook.
181
            // not good to compare on!
200
            // not good to compare on!
Lines 184-191 public class HSSFCellUtil Link Here
184
            for ( short i = 0; i < numberCellStyles; i++ )
203
            for ( short i = 0; i < numberCellStyles; i++ )
185
            {
204
            {
186
                HSSFCellStyle wbStyle = workbook.getCellStyleAt( i );
205
                HSSFCellStyle wbStyle = workbook.getCellStyleAt( i );
187
                Map wbStyleMap = PropertyUtils.describe( wbStyle );
206
                Map wbStyleMap = getFormatProperties( wbStyle );
188
                wbStyleMap.remove( "index" );
189
207
190
                if ( wbStyleMap.equals( values ) )
208
                if ( wbStyleMap.equals( values ) )
191
                {
209
                {
Lines 197-205 public class HSSFCellUtil Link Here
197
            if ( newStyle == null )
215
            if ( newStyle == null )
198
            {
216
            {
199
                newStyle = workbook.createCellStyle();
217
                newStyle = workbook.createCellStyle();
200
                newStyle.setFont( workbook.getFontAt( originalStyle.getFontIndex() ) );
218
                setFormatProperties( newStyle, workbook, values );
201
                PropertyUtils.copyProperties( newStyle, originalStyle );
202
                PropertyUtils.setProperty( newStyle, propertyName, propertyValue );
203
            }
219
            }
204
220
205
            cell.setCellStyle( newStyle );
221
            cell.setCellStyle( newStyle );
Lines 212-217 public class HSSFCellUtil Link Here
212
        }
228
        }
213
    }
229
    }
214
230
231
    /**
232
     * Returns a map containing the format properties of the given cell style.
233
     *
234
     * @param style cell style
235
     * @return map of format properties (String -> Object)
236
     * @see #setFormatProperties(HSSFCellStyle, Map)
237
     */
238
    private static Map getFormatProperties(HSSFCellStyle style) {
239
        Map properties = new HashMap();
240
        putShort( properties, ALIGNMENT, style.getAlignment() );
241
        putShort( properties, BORDER_BOTTOM, style.getBorderBottom() );
242
        putShort( properties, BORDER_LEFT, style.getBorderLeft() );
243
        putShort( properties, BORDER_RIGHT, style.getBorderRight() );
244
        putShort( properties, BORDER_TOP, style.getBorderTop() );
245
        putShort( properties, BOTTOM_BORDER_COLOR, style.getBottomBorderColor() );
246
        putShort( properties, DATA_FORMAT, style.getDataFormat() );
247
        putShort( properties, FILL_BACKGROUND_COLOR, style.getFillBackgroundColor() );
248
        putShort( properties, FILL_FOREGROUND_COLOR, style.getFillForegroundColor() );
249
        putShort( properties, FILL_PATTERN, style.getFillPattern() );
250
        putShort( properties, FONT, style.getFontIndex() );
251
        putBoolean( properties, HIDDEN, style.getHidden() );
252
        putShort( properties, INDENTION, style.getIndention() );
253
        putShort( properties, LEFT_BORDER_COLOR, style.getLeftBorderColor() );
254
        putBoolean( properties, LOCKED, style.getLocked() );
255
        putShort( properties, RIGHT_BORDER_COLOR, style.getRightBorderColor() );
256
        putShort( properties, ROTATION, style.getRotation() );
257
        putShort( properties, TOP_BORDER_COLOR, style.getTopBorderColor() );
258
        putShort( properties, VERTICAL_ALIGNMENT, style.getVerticalAlignment() );
259
        putBoolean( properties, WRAP_TEXT, style.getWrapText() );
260
        return properties;
261
    }
262
263
    /**
264
     * Sets the format properties of the given style based on the given map.
265
     *
266
     * @param style cell style
267
     * @param workbook parent workbook
268
     * @param properties map of format properties (String -> Object)
269
     * @see #getFormatProperties(HSSFCellStyle)
270
     */
271
    private static void setFormatProperties(
272
            HSSFCellStyle style, HSSFWorkbook workbook, Map properties) {
273
        style.setAlignment( getShort( properties, ALIGNMENT ) );
274
        style.setBorderBottom( getShort( properties, BORDER_BOTTOM ) );
275
        style.setBorderLeft( getShort( properties, BORDER_LEFT ) );
276
        style.setBorderRight( getShort( properties, BORDER_RIGHT ) );
277
        style.setBorderTop( getShort( properties, BORDER_TOP ) );
278
        style.setBottomBorderColor( getShort( properties, BOTTOM_BORDER_COLOR ) );
279
        style.setDataFormat( getShort( properties, DATA_FORMAT ) );
280
        style.setFillBackgroundColor( getShort( properties, FILL_BACKGROUND_COLOR ) );
281
        style.setFillForegroundColor( getShort( properties, FILL_FOREGROUND_COLOR ) );
282
        style.setFillPattern( getShort( properties, FILL_PATTERN ) );
283
        style.setFont( workbook.getFontAt( getShort( properties, FONT ) ) );
284
        style.setHidden( getBoolean( properties, HIDDEN ) );
285
        style.setIndention( getShort( properties, INDENTION ) );
286
        style.setLeftBorderColor( getShort( properties, LEFT_BORDER_COLOR ) );
287
        style.setLocked( getBoolean( properties, LOCKED ) );
288
        style.setRightBorderColor( getShort( properties, RIGHT_BORDER_COLOR ) );
289
        style.setRotation( getShort( properties, ROTATION ) );
290
        style.setTopBorderColor( getShort( properties, TOP_BORDER_COLOR ) );
291
        style.setVerticalAlignment( getShort( properties, VERTICAL_ALIGNMENT ) );
292
        style.setWrapText( getBoolean( properties, WRAP_TEXT ) );
293
    }
294
295
    /**
296
     * Utility method that returns the named short value form the given map.
297
     * Returns zero if the property does not exist, or is not a {@link Short}.
298
     *
299
     * @param properties map of named properties (String -> Object)
300
     * @param name property name
301
     * @return property value, or zero
302
     */
303
    private static short getShort(Map properties, String name) {
304
        Object value = properties.get( name );
305
        if ( value instanceof Short ) {
306
            return ((Short) value).shortValue();
307
        } else {
308
            return 0;
309
        }
310
    }
311
312
    /**
313
     * Utility method that returns the named boolean value form the given map.
314
     * Returns false if the property does not exist, or is not a {@link Boolean}.
315
     *
316
     * @param properties map of properties (String -> Object)
317
     * @param name property name
318
     * @return property value, or false
319
     */
320
    private static boolean getBoolean(Map properties, String name) {
321
        Object value = properties.get( name );
322
        if ( value instanceof Boolean ) {
323
            return ((Boolean) value).booleanValue();
324
        } else {
325
            return false;
326
        }
327
    }
328
329
    /**
330
     * Utility method that puts the named short value to the given map.
331
     *
332
     * @param properties map of properties (String -> Object)
333
     * @param name property name
334
     * @param value property value
335
     */
336
    private static void putShort(Map properties, String name, short value) {
337
        properties.put( name, new Short( value ) );
338
    }
339
340
    /**
341
     * Utility method that puts the named boolean value to the given map.
342
     *
343
     * @param properties map of properties (String -> Object)
344
     * @param name property name
345
     * @param value property value
346
     */
347
    private static void putBoolean(Map properties, String name, boolean value) {
348
        properties.put( name, new Boolean( value ) );
349
    }
215
350
216
    /**
351
    /**
217
     *  Looks for text in the cell that should be unicode, like &alpha; and provides the
352
     *  Looks for text in the cell that should be unicode, like &alpha; and provides the
(-)a/src/contrib/src/org/apache/poi/hssf/usermodel/contrib/HSSFRegionUtil.java (-9 / +16 lines)
Lines 60-66 public class HSSFRegionUtil Link Here
60
    for ( int i = rowStart; i <= rowEnd; i++ ) {
60
    for ( int i = rowStart; i <= rowEnd; i++ ) {
61
      HSSFRow row = HSSFCellUtil.getRow( i, sheet );
61
      HSSFRow row = HSSFCellUtil.getRow( i, sheet );
62
      HSSFCell cell = HSSFCellUtil.getCell( row, column );
62
      HSSFCell cell = HSSFCellUtil.getCell( row, column );
63
      HSSFCellUtil.setCellStyleProperty( cell, workbook, "borderLeft", new Short( border ) );
63
      HSSFCellUtil.setCellStyleProperty(
64
          cell, workbook, HSSFCellUtil.BORDER_LEFT, new Short( border ) );
64
    }
65
    }
65
  }
66
  }
66
67
Lines 83-89 public class HSSFRegionUtil Link Here
83
    for ( int i = rowStart; i <= rowEnd; i++ ) {
84
    for ( int i = rowStart; i <= rowEnd; i++ ) {
84
      HSSFRow row = HSSFCellUtil.getRow( i, sheet );
85
      HSSFRow row = HSSFCellUtil.getRow( i, sheet );
85
      HSSFCell cell = HSSFCellUtil.getCell( row, column );
86
      HSSFCell cell = HSSFCellUtil.getCell( row, column );
86
      HSSFCellUtil.setCellStyleProperty( cell, workbook, "leftBorderColor", new Short( color ) );
87
      HSSFCellUtil.setCellStyleProperty(
88
          cell, workbook, HSSFCellUtil.LEFT_BORDER_COLOR, new Short( color ) );
87
    }
89
    }
88
  }
90
  }
89
91
Lines 106-112 public class HSSFRegionUtil Link Here
106
      HSSFRow row = HSSFCellUtil.getRow( i, sheet );
108
      HSSFRow row = HSSFCellUtil.getRow( i, sheet );
107
      HSSFCell cell = HSSFCellUtil.getCell( row, column );
109
      HSSFCell cell = HSSFCellUtil.getCell( row, column );
108
110
109
      HSSFCellUtil.setCellStyleProperty( cell, workbook, "borderRight", new Short( border ) );
111
      HSSFCellUtil.setCellStyleProperty(
112
          cell, workbook, HSSFCellUtil.BORDER_RIGHT, new Short( border ) );
110
    }
113
    }
111
  }
114
  }
112
115
Lines 129-135 public class HSSFRegionUtil Link Here
129
    for ( int i = rowStart; i <= rowEnd; i++ ) {
132
    for ( int i = rowStart; i <= rowEnd; i++ ) {
130
      HSSFRow row = HSSFCellUtil.getRow( i, sheet );
133
      HSSFRow row = HSSFCellUtil.getRow( i, sheet );
131
      HSSFCell cell = HSSFCellUtil.getCell( row, column );
134
      HSSFCell cell = HSSFCellUtil.getCell( row, column );
132
      HSSFCellUtil.setCellStyleProperty( cell, workbook, "rightBorderColor", new Short( color ) );
135
      HSSFCellUtil.setCellStyleProperty(
136
          cell, workbook, HSSFCellUtil.RIGHT_BORDER_COLOR, new Short( color ) );
133
    }
137
    }
134
  }
138
  }
135
139
Lines 151-157 public class HSSFRegionUtil Link Here
151
    for ( int i = colStart; i <= colEnd; i++ ) {
155
    for ( int i = colStart; i <= colEnd; i++ ) {
152
156
153
      HSSFCell cell = HSSFCellUtil.getCell( row, i );
157
      HSSFCell cell = HSSFCellUtil.getCell( row, i );
154
      HSSFCellUtil.setCellStyleProperty( cell, workbook, "borderBottom", new Short( border ) );
158
      HSSFCellUtil.setCellStyleProperty(
159
          cell, workbook, HSSFCellUtil.BORDER_BOTTOM, new Short( border ) );
155
    }
160
    }
156
  }
161
  }
157
162
Lines 173-179 public class HSSFRegionUtil Link Here
173
    HSSFRow row = HSSFCellUtil.getRow( rowIndex, sheet );
178
    HSSFRow row = HSSFCellUtil.getRow( rowIndex, sheet );
174
    for ( int i = colStart; i <= colEnd; i++ ) {
179
    for ( int i = colStart; i <= colEnd; i++ ) {
175
      HSSFCell cell = HSSFCellUtil.getCell( row, i );
180
      HSSFCell cell = HSSFCellUtil.getCell( row, i );
176
      HSSFCellUtil.setCellStyleProperty( cell, workbook, "bottomBorderColor", new Short( color ) );
181
      HSSFCellUtil.setCellStyleProperty(
182
          cell, workbook, HSSFCellUtil.BOTTOM_BORDER_COLOR, new Short( color ) );
177
    }
183
    }
178
  }
184
  }
179
185
Lines 196-202 public class HSSFRegionUtil Link Here
196
    for ( int i = colStart; i <= colEnd; i++ ) {
202
    for ( int i = colStart; i <= colEnd; i++ ) {
197
203
198
      HSSFCell cell = HSSFCellUtil.getCell( row, i );
204
      HSSFCell cell = HSSFCellUtil.getCell( row, i );
199
      HSSFCellUtil.setCellStyleProperty( cell, workbook, "borderTop", new Short( border ) );
205
      HSSFCellUtil.setCellStyleProperty(
206
          cell, workbook, HSSFCellUtil.BORDER_TOP, new Short( border ) );
200
    }
207
    }
201
  }
208
  }
202
209
Lines 218-224 public class HSSFRegionUtil Link Here
218
    HSSFRow row = HSSFCellUtil.getRow( rowIndex, sheet );
225
    HSSFRow row = HSSFCellUtil.getRow( rowIndex, sheet );
219
    for ( int i = colStart; i <= colEnd; i++ ) {
226
    for ( int i = colStart; i <= colEnd; i++ ) {
220
      HSSFCell cell = HSSFCellUtil.getCell( row, i );
227
      HSSFCell cell = HSSFCellUtil.getCell( row, i );
221
      HSSFCellUtil.setCellStyleProperty( cell, workbook, "topBorderColor", new Short( color ) );
228
      HSSFCellUtil.setCellStyleProperty(
229
          cell, workbook, HSSFCellUtil.TOP_BORDER_COLOR, new Short( color ) );
222
230
223
    }
231
    }
224
  }
232
  }
225
- 

Return to bug 45410