You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ni...@apache.org on 2008/09/21 21:50:21 UTC

svn commit: r697599 - in /poi/trunk/src: documentation/content/xdocs/changes.xml documentation/content/xdocs/status.xml java/org/apache/poi/hssf/usermodel/HSSFRow.java testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java

Author: nick
Date: Sun Sep 21 12:50:21 2008
New Revision: 697599

URL: http://svn.apache.org/viewvc?rev=697599&view=rev
Log:
Apply part of patch from bug #16936, with the rest made more HSSFCell like - Initial support for whole-row cell styling

Added:
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java   (with props)
Modified:
    poi/trunk/src/documentation/content/xdocs/changes.xml
    poi/trunk/src/documentation/content/xdocs/status.xml
    poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java

Modified: poi/trunk/src/documentation/content/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/changes.xml?rev=697599&r1=697598&r2=697599&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/changes.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/changes.xml Sun Sep 21 12:50:21 2008
@@ -37,6 +37,7 @@
 
 		<!-- Don't forget to update status.xml too! -->
         <release version="3.2-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">16936 - Initial support for whole-row cell styling</action>
            <action dev="POI-DEVELOPERS" type="add">Update hssf.extractor.ExcelExtractor to optionally output blank cells too</action>
            <action dev="POI-DEVELOPERS" type="add">Include the sheet name in the output of examples.XLS2CSVmra</action>
            <action dev="POI-DEVELOPERS" type="fix">45784 - Support long chart titles in SeriesTextRecords</action>

Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=697599&r1=697598&r2=697599&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Sun Sep 21 12:50:21 2008
@@ -34,6 +34,7 @@
 	<!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.2-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="add">16936 - Initial support for whole-row cell styling</action>
            <action dev="POI-DEVELOPERS" type="add">Update hssf.extractor.ExcelExtractor to optionally output blank cells too</action>
            <action dev="POI-DEVELOPERS" type="add">Include the sheet name in the output of examples.XLS2CSVmra</action>
            <action dev="POI-DEVELOPERS" type="fix">45784 - Support long chart titles in SeriesTextRecords</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=697599&r1=697598&r2=697599&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 Sun Sep 21 12:50:21 2008
@@ -21,6 +21,7 @@
 import java.util.NoSuchElementException;
 
 import org.apache.poi.hssf.record.CellValueRecordInterface;
+import org.apache.poi.hssf.record.ExtendedFormatRecord;
 import org.apache.poi.hssf.record.RowRecord;
 
 /**
@@ -519,6 +520,33 @@
             return -1;
         return cellnum;
     }
+    
+    /**
+     * 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.getFormatted();
+    }
+    /**
+     * Returns the whole-row cell styles. Most rows won't
+     *  have one of these, so will return null. Call
+     *  {@link #isFormatted()} to check first.
+     */
+    public HSSFCellStyle getRowStyle() {
+    	if(!isFormatted()) { return null; }
+        short styleIndex = row.getXFIndex();
+        ExtendedFormatRecord xf = book.getWorkbook().getExFormatAt(styleIndex);
+        return new HSSFCellStyle(styleIndex, xf, book);
+    }
+    /**
+     * Applies a whole-row cell styling to the row.
+     */
+    public void setRowStyle(HSSFCellStyle style) {
+    	row.setFormatted(true);
+    	row.setXFIndex(style.getIndex());
+    }
 
     /**
      * Used to specify the different possible policies

Added: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java?rev=697599&view=auto
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java (added)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java Sun Sep 21 12:50:21 2008
@@ -0,0 +1,204 @@
+/* ====================================================================
+   Copyright 2002-2004   Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+        
+
+/*
+ * TestRowStyle.java
+ *
+ * Created on May 20, 2005
+ */
+package org.apache.poi.hssf.usermodel;
+
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.poi.hssf.HSSFTestDataSamples;
+import org.apache.poi.util.TempFile;
+
+/**
+ * Class to test row styling functionality
+ *
+ * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
+ */
+
+public class TestRowStyle
+    extends TestCase
+{
+
+    /** Creates a new instance of TestCellStyle */
+
+    public TestRowStyle(String name)
+    {
+        super(name);
+    }
+
+    /**
+     * TEST NAME:  Test Write Sheet Font <P>
+     * OBJECTIVE:  Test that HSSF can create a simple spreadsheet with numeric and string values and styled with fonts.<P>
+     * SUCCESS:    HSSF creates a sheet.  Filesize matches a known good.  HSSFSheet objects
+     *             Last row, first row is tested against the correct values (99,0).<P>
+     * FAILURE:    HSSF does not create a sheet or excepts.  Filesize does not match the known good.
+     *             HSSFSheet last row or first row is incorrect.             <P>
+     *
+     */
+
+    public void testWriteSheetFont()
+        throws IOException
+    {
+        HSSFWorkbook     wb   = new HSSFWorkbook();
+        HSSFSheet        s    = wb.createSheet();
+        HSSFRow          r    = null;
+        HSSFCell         c    = null;
+        HSSFFont         fnt  = wb.createFont();
+        HSSFCellStyle    cs   = wb.createCellStyle();
+
+        fnt.setColor(HSSFFont.COLOR_RED);
+        fnt.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
+        cs.setFont(fnt);
+        for (short rownum = ( short ) 0; rownum < 100; rownum++)
+        {
+            r = s.createRow(rownum);
+            r.setRowStyle(cs);
+            r.createCell(0);
+        }
+        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        		
+        SanityChecker sanityChecker = new SanityChecker();
+        sanityChecker.checkHSSFWorkbook(wb);
+        assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
+        assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
+    }
+
+    /**
+     * Tests that is creating a file with a date or an calendar works correctly.
+     */
+    public void testDataStyle()
+            throws Exception
+    {
+        HSSFWorkbook     wb   = new HSSFWorkbook();
+        HSSFSheet        s    = wb.createSheet();
+        HSSFCellStyle    cs   = wb.createCellStyle();
+        HSSFRow row = s.createRow((short)0);
+
+        // with Date:
+        cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
+        row.setRowStyle(cs);
+        row.createCell(0);
+
+
+        // with Calendar:
+        row = s.createRow((short)1);
+        cs.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy"));
+        row.setRowStyle(cs);
+        row.createCell(0);
+
+        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        
+        SanityChecker sanityChecker = new SanityChecker();
+        sanityChecker.checkHSSFWorkbook(wb);
+
+        assertEquals("LAST ROW ", 1, s.getLastRowNum());
+        assertEquals("FIRST ROW ", 0, s.getFirstRowNum());
+
+    }
+
+    /**
+     * TEST NAME:  Test Write Sheet Style <P>
+     * OBJECTIVE:  Test that HSSF can create a simple spreadsheet with numeric and string values and styled with colors
+     *             and borders.<P>
+     * SUCCESS:    HSSF creates a sheet.  Filesize matches a known good.  HSSFSheet objects
+     *             Last row, first row is tested against the correct values (99,0).<P>
+     * FAILURE:    HSSF does not create a sheet or excepts.  Filesize does not match the known good.
+     *             HSSFSheet last row or first row is incorrect.             <P>
+     *
+     */
+
+    public void testWriteSheetStyle()
+        throws IOException
+    {
+        HSSFWorkbook     wb   = new HSSFWorkbook();
+        HSSFSheet        s    = wb.createSheet();
+        HSSFRow          r    = null;
+        HSSFFont         fnt  = wb.createFont();
+        HSSFCellStyle    cs   = wb.createCellStyle();
+        HSSFCellStyle    cs2  = wb.createCellStyle();
+
+        cs.setBorderBottom(HSSFCellStyle.BORDER_THIN);
+        cs.setBorderLeft(HSSFCellStyle.BORDER_THIN);
+        cs.setBorderRight(HSSFCellStyle.BORDER_THIN);
+        cs.setBorderTop(HSSFCellStyle.BORDER_THIN);
+        cs.setFillForegroundColor(( short ) 0xA);
+        cs.setFillPattern(( short ) 1);
+        fnt.setColor(( short ) 0xf);
+        fnt.setItalic(true);
+        cs2.setFillForegroundColor(( short ) 0x0);
+        cs2.setFillPattern(( short ) 1);
+        cs2.setFont(fnt);
+        for (short rownum = ( short ) 0; rownum < 100; rownum++)
+        {
+            r = s.createRow(rownum);
+            r.setRowStyle(cs);
+            r.createCell(0);
+
+            rownum++;
+            if (rownum >= 100) break; // I feel too lazy to check if this isreqd :-/ 
+            
+            r = s.createRow(rownum);
+            r.setRowStyle(cs2);
+            r.createCell(0);
+        }
+        wb = HSSFTestDataSamples.writeOutAndReadBack(wb);
+        
+        SanityChecker sanityChecker = new SanityChecker();
+        sanityChecker.checkHSSFWorkbook(wb);
+        assertEquals("LAST ROW == 99", 99, s.getLastRowNum());
+        assertEquals("FIRST ROW == 0", 0, s.getFirstRowNum());
+        
+        s    = wb.getSheetAt(0);
+        assertNotNull("Sheet is not null", s);
+        
+        for (short rownum = ( short ) 0; rownum < 100; rownum++)
+        {
+            r = s.getRow(rownum);
+            assertNotNull("Row is not null", r);
+            
+            cs = r.getRowStyle();
+            assertEquals("FillForegroundColor for row: ", cs.getBorderBottom(), HSSFCellStyle.BORDER_THIN);
+            assertEquals("FillPattern for row: ", cs.getBorderLeft(), HSSFCellStyle.BORDER_THIN);
+            assertEquals("FillForegroundColor for row: ", cs.getBorderRight(), HSSFCellStyle.BORDER_THIN);
+            assertEquals("FillPattern for row: ", cs.getBorderTop(), HSSFCellStyle.BORDER_THIN);
+            assertEquals("FillForegroundColor for row: ", cs.getFillForegroundColor(), 0xA);
+            assertEquals("FillPattern for row: ", cs.getFillPattern(), (short) 0x1);
+            
+            rownum++;
+            if (rownum >= 100) break; // I feel too lazy to check if this isreqd :-/ 
+            
+            r = s.getRow(rownum);
+            assertNotNull("Row is not null", r);
+            cs2 = r.getRowStyle();
+            assertEquals("FillForegroundColor for row: ", cs2.getFillForegroundColor(), (short) 0x0);
+            assertEquals("FillPattern for row: ", cs2.getFillPattern(), (short) 0x1);
+        }
+    }
+
+    public static void main(String [] ignored_args)
+    {
+        System.out
+            .println("Testing org.apache.poi.hssf.usermodel.HSSFCellStyle");
+        junit.textui.TestRunner.run(TestCellStyle.class);
+    }
+}

Propchange: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestRowStyle.java
------------------------------------------------------------------------------
    svn:eol-style = native



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