Bug 8515

Summary: [Patch] Headers, Footers, Gridlines, and Print Setup
Product: POI Reporter: Shawn Laubach <shawn.laubach>
Component: HSSFAssignee: POI Developers List <dev>
Status: CLOSED FIXED    
Severity: normal CC: Philipp.Bolle, ramandeep21119
Priority: P3    
Version: 2.0-dev   
Target Milestone: ---   
Hardware: Other   
OS: other   
Attachments: User model to the header record
User model to the footer record
User model to the print setup record
Test File for Gridlines
Test File for Headers/Footers and PrintSetup
But in previous HSSFPrintSetup. This fixes it.
Updated HSSFSheet to not loop
Updated Patch

Description Shawn Laubach 2002-04-25 14:14:50 UTC
These are a set of additions to add and modify the page headers, footers, 
whether gridlines are printed, and the print setup which includes landscape 
mode, margins, and such.

Index: src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
===================================================================
RCS file: /home/cvspublic/jakarta-
poi/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java,v
retrieving revision 1.4
diff -u -r1.4 HSSFSheet.java
--- src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java	14 Mar 2002 
11:05:04 -0000	1.4
+++ src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java	25 Apr 2002 
13:30:34 -0000
@@ -756,4 +756,84 @@
         return (( WSBoolRecord ) sheet.findFirstRecordBySid(WSBoolRecord.sid))
             .getRowSumsRight();
     }
+
+    /**
+     * Returns whether gridlines are printed.
+     * @return Gridlines are printed
+     */
+    public boolean getPrintGridlines() {
+        Iterator i = getSheet().getRecords().iterator();
+        while (i.hasNext()) {
+            Record r = (Record)i.next();
+            if (r.getSid() == PrintGridlinesRecord.sid) {
+                PrintGridlinesRecord pgr = (PrintGridlinesRecord)r;
+                return pgr.getPrintGridlines();
+            }
+        }
+        return false;
+    }
+
+    /**
+     * Turns on or off the printing of gridlines.
+     * @param newPrintGridlines boolean to turn on or off the printing of
+     * gridlines
+     */
+    public void setPrintGridlines(boolean newPrintGridlines) {
+        Iterator i = getSheet().getRecords().iterator();
+        while (i.hasNext()) {
+            Record r = (Record)i.next();
+            if (r.getSid() == PrintGridlinesRecord.sid) {
+                PrintGridlinesRecord pgr = (PrintGridlinesRecord)r;
+                pgr.setPrintGridlines(newPrintGridlines);
+            }
+        }
+    }
+
+    /**
+     * Gets the print setup object.
+     * @return The user model for the print setup object.
+     */
+    public HSSFPrintSetup getPrintSetup() {
+        Iterator i = getSheet().getRecords().iterator();
+        while (i.hasNext()) {
+            Record r = (Record)i.next();
+            if (r.getSid() == PrintSetupRecord.sid) {
+                PrintSetupRecord psr = (PrintSetupRecord)r;
+                return new HSSFPrintSetup(psr);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Gets the user model for the document header.
+     * @return The Document header.
+     */
+    public HSSFHeader getHeader() {
+        Iterator i = getSheet().getRecords().iterator();
+        while (i.hasNext()) {
+            Record r = (Record)i.next();
+            if (r.getSid() == HeaderRecord.sid) {
+                HeaderRecord hr = (HeaderRecord)r;
+                return new HSSFHeader(hr);
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Gets the user model for the document footer.
+     * @return The Document footer.
+     */
+    public HSSFFooter getFooter() {
+        Iterator i = getSheet().getRecords().iterator();
+        while (i.hasNext()) {
+            Record r = (Record)i.next();
+            if (r.getSid() == FooterRecord.sid) {
+                FooterRecord hr = (FooterRecord)r;
+                return new HSSFFooter(hr);
+            }
+        }
+        return null;
+    }
 }
Comment 1 Shawn Laubach 2002-04-25 14:17:14 UTC
Created attachment 1694 [details]
User model to the header record
Comment 2 Shawn Laubach 2002-04-25 14:17:37 UTC
Created attachment 1695 [details]
User model to the footer record
Comment 3 Shawn Laubach 2002-04-25 14:17:58 UTC
Created attachment 1696 [details]
User model to the print setup record
Comment 4 Andy Oliver 2002-04-25 14:21:26 UTC
This is great stuff.  I'll put it in my to-do queue if Glen doesn't beat me to
it.   Any chance we can get a unit test for this?  (I know it seems like we're
fanatics but so far we've found that those things that don't get unit tested get
broken as the software gets patched....and no one tends to notice until much
later).  It should be fairly simple to figure out how to do one by going too
src/testcases/org/apache/poi/hssf/..... and looking at a TestXXXX class.  Just
copy it and do the same for these features.  If you don't, I will eventually,
but I think there is a consensus among HSSF committers that no new
un-unit-tested code should make it into a production release.  (nothing
official...just I think we agree ;-) )
Comment 5 Shawn Laubach 2002-04-25 17:15:17 UTC
Created attachment 1701 [details]
Test File for Gridlines
Comment 6 Shawn Laubach 2002-04-25 17:15:48 UTC
Created attachment 1702 [details]
Test File for Headers/Footers and PrintSetup
Comment 7 Shawn Laubach 2002-04-25 17:16:32 UTC
Created attachment 1703 [details]
But in previous HSSFPrintSetup.  This fixes it.
Comment 8 Andy Oliver 2002-04-29 18:00:11 UTC
will apply shortly.
Comment 9 Andy Oliver 2002-04-29 18:01:35 UTC
*** Bug 7864 has been marked as a duplicate of this bug. ***
Comment 10 Andy Oliver 2002-04-30 04:21:07 UTC
after puting this in I get this:

Created dir: D:\andy\homestuff\jakarta-poi\build\testcases
Compiling 87 source files to D:\andy\homestuff\jakarta-poi\build\testcases
D:\andy\homestuff\jakarta-poi\src\testcases\org\apache\poi\hssf\usermodel\TestGr
idlines.java:103: cannot resolve symbol
symbol  : method setPrintGridlines  (boolean)
location: class org.apache.poi.hssf.usermodel.HSSFSheet
        s.setPrintGridlines(true);
         ^
D:\andy\homestuff\jakarta-poi\src\testcases\org\apache\poi\hssf\usermodel\TestHe
adersFootersPrintSetup.java:121: cannot resolve symbol
symbol  : method getHeader  ()
location: class org.apache.poi.hssf.usermodel.HSSFSheet
        h = s.getHeader();
             ^
D:\andy\homestuff\jakarta-poi\src\testcases\org\apache\poi\hssf\usermodel\TestHe
adersFootersPrintSetup.java:126: cannot resolve symbol
symbol  : method getFooter  ()
location: class org.apache.poi.hssf.usermodel.HSSFSheet
        f = s.getFooter();
             ^
D:\andy\homestuff\jakarta-poi\src\testcases\org\apache\poi\hssf\usermodel\TestHe
adersFootersPrintSetup.java:162: cannot resolve symbol
symbol  : method getPrintSetup  ()
location: class org.apache.poi.hssf.usermodel.HSSFSheet
        ps = s.getPrintSetup();
              ^
D:\andy\homestuff\jakarta-poi\src\testcases\org\apache\poi\hssf\usermodel\TestHe
adersFootersPrintSetup.java:218: cannot resolve symbol
symbol  : method getPrintSetup  ()
location: class org.apache.poi.hssf.usermodel.HSSFSheet
        ps = s.getPrintSetup();
              ^
D:\andy\homestuff\jakarta-poi\src\testcases\org\apache\poi\hssf\usermodel\TestHe
adersFootersPrintSetup.java:240: cannot resolve symbol
symbol  : method getFooter  ()
location: class org.apache.poi.hssf.usermodel.HSSFSheet
        f = s.getFooter();
             ^
6 errors

BUILD FAILED
D:\andy\homestuff\jakarta-poi\tools\cents\junit.cent\xbuild.xml:27: Compile fail
ed; see the compiler error output for details.


Forget a file?  Submit patch with "cvs diff -u" for HSSFSheet.  Thanks -Andy
Comment 11 Shawn Laubach 2002-04-30 13:42:40 UTC
The patch is part of the original bug comments.  I can attach it as a file if 
needed.
Comment 12 Andy Oliver 2002-04-30 15:24:54 UTC
Sorry I'd overlooked that patch in that description.  Okay I can't commit this
as is.  Here is the deal, shoving that looping code into HSSFSheet would
drastically affect performance.  The approach I would suggest is putting the
code for dealing with the record in org.apache.poi.hssf.model.Sheet and have
HSSFSheet access it from there.  Furthermore, have the Sheet contain some
reference variables that are loaded when the sheet is loaded or when a footer or
header is created.  There are more than one example (I think) on how to do this
in that file.  If you cna provide a patch that follows that convention versus
looping through the records in the usermodel I'll apply it.  thanks, -Andy
Comment 13 Andy Oliver 2002-04-30 19:22:18 UTC
if you do a "cvs update" -- the problem should take care of itself.  Merge and
conflicts and send the patch.  Should happen mostly automatically as this code
isn't in any rapidly changing code.
Comment 14 Shawn Laubach 2002-04-30 20:03:07 UTC
Created attachment 1746 [details]
Updated HSSFSheet to not loop
Comment 15 Shawn Laubach 2002-04-30 20:04:35 UTC
I've added a new patch that updates Sheet and HSSFSheet to not do looping to 
grab the needed records.  Did run into a problem with indention changing in my 
editor so that there are more diffs than necessary.  I checked however and 
there was nothing that did more that change the spacing.
Comment 16 Andy Oliver 2002-04-30 22:33:04 UTC
yum that patch looks much better.
Comment 17 Andy Oliver 2002-05-01 03:37:40 UTC
After applying this TestHSSFSheet went into an infinite loop.  Can you run
./build.sh clean compile test and see if you get the same?
Comment 18 Shawn Laubach 2002-05-01 15:06:15 UTC
I'll check it out.
Comment 19 Shawn Laubach 2002-05-01 15:20:46 UTC
When I run it, it gives me no errors and everything runs fine.  Could it be 
because of the diff having more differences than are required?  How do you 
indent the code?  Could I try the same thing and see what I get for the diffs 
then?
Comment 20 Andy Oliver 2002-05-01 15:48:35 UTC
indent the code?  Tell you what.  Lets try this one more time.  Attach a zip
file with all of you current .java files, including the directory relative to
jakarta-poi module (so src/java/org/apache/poi/hssf/usermodel/HSSFFooter).  Then
make sure your up to date.  attach a patch of the deltas.  

Lastly try checking out clean and applying your own patch.  run the clean
compile tests targets in order.  I swear even if I have to retype this we'll get
this in!  ;-).

(I tried it pre-patch, then with patch and well with patch it hung on the unit
tests)
Comment 21 Shawn Laubach 2002-05-02 02:57:53 UTC
Created attachment 1757 [details]
Updated Patch
Comment 22 Shawn Laubach 2002-05-02 03:00:06 UTC
I've added the most resent patch that I based on the most recent code.  I just 
copied the lines I added over and tested with everything.  The original files 
attached are OK but the patch only tries to change the necessary lines.  I've 
compiled and ran all the tests and they all passed OK.  I hope this works this 
time.
Comment 23 Shawn Laubach 2002-05-03 02:51:41 UTC
I created a new patch.  I then did a new checkout and downloaded the files from 
the bug report.  Next, I applied the patch, compiled the code and ran the 
tests.  Everything worked just fine.
Comment 24 Andy Oliver 2002-05-03 04:59:15 UTC
applied....unit tests passed...please cross check... thanks for the patience -Andy
Comment 25 Shawn Laubach 2002-07-27 18:32:58 UTC
Verified.