poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n...@apache.org
Subject svn commit: r1144348 - in /poi/trunk/src: documentation/content/xdocs/ java/org/apache/poi/hssf/usermodel/ java/org/apache/poi/ss/usermodel/ ooxml/java/org/apache/poi/xssf/streaming/ ooxml/java/org/apache/poi/xssf/usermodel/ testcases/org/apache/poi/ss...
Date Fri, 08 Jul 2011 14:58:09 GMT
Author: nick
Date: Fri Jul  8 14:58:08 2011
New Revision: 1144348

URL: http://svn.apache.org/viewvc?rev=1144348&view=rev
Log:
Fix bug #51469 - XSSF support for row styles, to match existing HSSF functionality

Modified:
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/Row.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1144348&r1=1144347&r2=1144348&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Fri Jul  8 14:58:08 2011
@@ -34,6 +34,7 @@
 
     <changes>
         <release version="3.8-beta4" date="2011-??-??">
+           <action dev="poi-developers" type="add">51469 - XSSF support for row styles,
to match existing HSSF functionality</action>
            <action dev="poi-developers" type="fix">51476 - Correct XSSF cell formatting
in HTML export</action>
            <action dev="poi-developers" type="add">51486 - XWPF support for adding
new footnotes</action>
            <action dev="poi-developers" type="fix">48065 - Problems with save output
of HWPF (losing formatting)</action>

Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java?rev=1144348&r1=1144347&r2=1144348&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java Fri Jul  8 14:58:08 2011
@@ -24,6 +24,7 @@ import org.apache.poi.hssf.record.CellVa
 import org.apache.poi.hssf.record.ExtendedFormatRecord;
 import org.apache.poi.hssf.record.RowRecord;
 import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.SpreadsheetVersion;
 
@@ -593,6 +594,12 @@ public final class HSSFRow implements Ro
         row.setFormatted(true);
         row.setXFIndex(style.getIndex());
     }
+    /**
+     * Applies a whole-row cell styling to the row.
+     */
+    public void setRowStyle(CellStyle style) {
+        setRowStyle((HSSFCellStyle)style);
+    }
 
     /**
      * @return cell iterator of the physically defined cells.

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/Row.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/Row.java?rev=1144348&r1=1144347&r2=1144348&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/Row.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/Row.java Fri Jul  8 14:58:08 2011
@@ -17,7 +17,6 @@
 
 package org.apache.poi.ss.usermodel;
 
-import java.lang.Iterable;
 import java.util.Iterator;
 
 /**
@@ -178,6 +177,25 @@ public interface Row extends Iterable<Ce
     float getHeightInPoints();
 
     /**
+     * Is this row formatted? Most aren't, but some rows
+     *  do have whole-row styles. For those that do, you
+     *  can get the formatting from {@link #getRowStyle()}
+     */
+    boolean isFormatted();
+    
+    /**
+     * Returns the whole-row cell styles. Most rows won't
+     *  have one of these, so will return null. Call
+     *  {@link #isFormatted()} to check first.
+     */
+    CellStyle getRowStyle();
+    
+    /**
+     * Applies a whole-row cell styling to the row.
+     */
+    void setRowStyle(CellStyle style);
+    
+    /**
      * @return Cell iterator of the physically defined cells.  Note element 4 may
      * actually be row cell depending on how many are defined!
      */

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java?rev=1144348&r1=1144347&r2=1144348&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFRow.java Fri Jul  8 14:58:08
2011
@@ -17,12 +17,14 @@
 
 package org.apache.poi.xssf.streaming;
 
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
 import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
+import org.apache.poi.xssf.usermodel.XSSFCellStyle;
 
 /**
  * Streaming version of XSSFRow implementing the "BigGridDemo" strategy.
@@ -34,6 +36,7 @@ public class SXSSFRow implements Row
     SXSSFSheet _sheet;
     SXSSFCell[] _cells;
     int _maxColumn=-1;
+    short _style=-1;
     short _height=-1;
     boolean _zHeight = false;
 
@@ -330,6 +333,37 @@ public class SXSSFRow implements Row
     {
         return (float)(_height==-1?getSheet().getDefaultRowHeightInPoints():(float)_height/20.0);
     }
+    
+    /**
+     * Is this row formatted? Most aren't, but some rows
+     *  do have whole-row styles. For those that do, you
+     *  can get the formatting from {@link #getRowStyle()}
+     */
+    public boolean isFormatted() {
+        return _style > -1;
+    }
+    /**
+     * Returns the whole-row cell style. Most rows won't
+     *  have one of these, so will return null. Call
+     *  {@link #isFormatted()} to check first.
+     */
+    public CellStyle getRowStyle() {
+       if(!isFormatted()) return null;
+       
+       return getSheet().getWorkbook().getCellStyleAt(_style);
+    }
+    
+    /**
+     * Applies a whole-row cell styling to the row.
+     */
+    public void setRowStyle(CellStyle style) {
+       if(style == null) {
+          _style = -1;
+          return;
+       } else {
+          _style = style.getIndex();
+       }
+    }
 
     /**
      * @return Cell iterator of the physically defined cells.  Note element 4 may

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java?rev=1144348&r1=1144347&r2=1144348&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java Fri Jul  8 14:58:08
2011
@@ -1317,6 +1317,10 @@ public class SXSSFSheet implements Sheet
                 _out.write(" customHeight=\"true\"  ht=\""+row.getHeightInPoints()+"\"");
             if(row.getZeroHeight())
                 _out.write(" hidden=\"true\"");
+            if(row.isFormatted()) {
+                _out.write(" s=\"" + row._style + "\"");
+                _out.write(" customFormat=\"1\"");
+            }
             _out.write(">\n");
             this._rownum = rownum;
             _rowContainedNullCells=false;

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java?rev=1144348&r1=1144347&r2=1144348&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java Fri Jul  8 14:58:08
2011
@@ -22,12 +22,14 @@ import java.util.TreeMap;
 
 import org.apache.poi.ss.SpreadsheetVersion;
 import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellStyle;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.util.CellReference;
 import org.apache.poi.util.Internal;
 import org.apache.poi.util.POILogFactory;
 import org.apache.poi.util.POILogger;
 import org.apache.poi.xssf.model.CalculationChain;
+import org.apache.poi.xssf.model.StylesTable;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCell;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRow;
 
@@ -356,6 +358,53 @@ public class XSSFRow implements Row, Com
     }
 
     /**
+     * Is this row formatted? Most aren't, but some rows
+     *  do have whole-row styles. For those that do, you
+     *  can get the formatting from {@link #getRowStyle()}
+     */
+    public boolean isFormatted() {
+        return _row.isSetS();
+    }
+    /**
+     * Returns the whole-row cell style. Most rows won't
+     *  have one of these, so will return null. Call
+     *  {@link #isFormatted()} to check first.
+     */
+    public XSSFCellStyle getRowStyle() {
+       if(!isFormatted()) return null;
+       
+       StylesTable stylesSource = getSheet().getWorkbook().getStylesSource();
+       if(stylesSource.getNumCellStyles() > 0) {
+           return stylesSource.getStyleAt((int)_row.getS());
+       } else {
+          return null;
+       }
+    }
+    
+    /**
+     * Applies a whole-row cell styling to the row.
+     * If the value is null then the style information is removed,
+     *  causing the cell to used the default workbook style.
+     */
+    public void setRowStyle(CellStyle style) {
+        if(style == null) {
+           if(_row.isSetS()) {
+              _row.unsetS();
+              _row.unsetCustomFormat();
+           }
+        } else {
+            StylesTable styleSource = getSheet().getWorkbook().getStylesSource();
+            
+            XSSFCellStyle xStyle = (XSSFCellStyle)style;
+            xStyle.verifyBelongsToStylesSource(styleSource);
+
+            long idx = styleSource.putStyle(xStyle);
+            _row.setS(idx);
+            _row.setCustomFormat(true);
+        }
+    }
+    
+    /**
      * Remove the Cell from this row.
      *
      * @param cell the cell to remove

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java?rev=1144348&r1=1144347&r2=1144348&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestRow.java Fri Jul  8 14:58:08
2011
@@ -386,4 +386,42 @@ public abstract class BaseTestRow extend
         assertTrue(cell2 == it.next());
         assertEquals(Cell.CELL_TYPE_STRING, cell5.getCellType());
     }
+    
+    public void testRowStyle() {
+       Workbook workbook = _testDataProvider.createWorkbook();
+       Sheet sheet = workbook.createSheet("test");
+       Row row1 = sheet.createRow(0);
+       Row row2 = sheet.createRow(1);
+       
+       // Won't be styled currently
+       assertEquals(false, row1.isFormatted());
+       assertEquals(false, row2.isFormatted());
+       assertEquals(null, row1.getRowStyle());
+       assertEquals(null, row2.getRowStyle());
+       
+       // Style one
+       CellStyle style = workbook.createCellStyle();
+       style.setDataFormat((short)4);
+       row2.setRowStyle(style);
+       
+       // Check
+       assertEquals(false, row1.isFormatted());
+       assertEquals(true, row2.isFormatted());
+       assertEquals(null, row1.getRowStyle());
+       assertEquals(style, row2.getRowStyle());
+       
+       // Save, load and re-check
+       workbook = _testDataProvider.writeOutAndReadBack(workbook);
+       sheet = workbook.getSheetAt(0);
+
+       row1 = sheet.getRow(0);
+       row2 = sheet.getRow(1);
+       style = workbook.getCellStyleAt(style.getIndex());
+       
+       assertEquals(false, row1.isFormatted());
+       assertEquals(true, row2.isFormatted());
+       assertEquals(null, row1.getRowStyle());
+       assertEquals(style, row2.getRowStyle());
+       assertEquals(4, style.getDataFormat());
+    }
 }



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


Mime
View raw message