]> source.dussan.org Git - poi.git/commitdiff
bug 59645: add Page Setup Print row and column headings support for Common SS
authorJaven O'Neal <onealj@apache.org>
Sun, 19 Jun 2016 18:20:23 +0000 (18:20 +0000)
committerJaven O'Neal <onealj@apache.org>
Sun, 19 Jun 2016 18:20:23 +0000 (18:20 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1749191 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/model/InternalSheet.java
src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
src/java/org/apache/poi/ss/usermodel/Sheet.java
src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java

index 76de9513620f7c4d8b9bd7f740ec778a29dbb491..9dd03a804321f7fd94487725300d73dd5f681c57 100644 (file)
@@ -103,6 +103,7 @@ public final class InternalSheet {
 
     private List<RecordBase>             _records;
     protected PrintGridlinesRecord       printGridlines    =     null;
+    protected PrintHeadersRecord         printHeaders      =     null;
     protected GridsetRecord              gridset           =     null;
     private   GutsRecord                 _gutsRecord;
     protected DefaultColWidthRecord      defaultcolwidth   =     new DefaultColWidthRecord();
@@ -313,6 +314,10 @@ public final class InternalSheet {
             {
                 printGridlines = (PrintGridlinesRecord) rec;
             }
+            else if ( recSid == PrintHeadersRecord.sid )
+            {
+                printHeaders = (PrintHeadersRecord) rec;
+            }
             else if ( recSid == GridsetRecord.sid )
             {
                 gridset = (GridsetRecord) rec;
@@ -455,7 +460,8 @@ public final class InternalSheet {
         records.add(createIteration() );
         records.add(createDelta() );
         records.add(createSaveRecalc() );
-        records.add(createPrintHeaders() );
+        printHeaders = createPrintHeaders();
+        records.add(printHeaders);
         printGridlines = createPrintGridlines();
         records.add( printGridlines );
         gridset = createGridset();
@@ -1344,6 +1350,24 @@ public final class InternalSheet {
     {
         printGridlines = newPrintGridlines;
     }
+    
+    /**
+     * Returns the PrintHeadersRecord.
+     * @return PrintHeadersRecord for the sheet.
+     */
+    public PrintHeadersRecord getPrintHeaders()
+    {
+        return printHeaders;
+    }
+
+    /**
+     * Sets the PrintHeadersRecord.
+     * @param newPrintHeaders The new PrintHeadersRecord for the sheet.
+     */
+    public void setPrintHeaders(PrintHeadersRecord newPrintHeaders)
+    {
+        printHeaders = newPrintHeaders;
+    }
 
     /**
      * Sets whether the sheet is selected
@@ -1510,6 +1534,22 @@ public final class InternalSheet {
     public boolean isDisplayRowColHeadings() {
         return windowTwo.getDisplayRowColHeadings();
     }
+    
+    /**
+     * Sets whether the RowColHeadings are shown in a viewer.
+     * @param show whether to show RowColHeadings or not
+     */
+    public void setPrintRowColHeadings(boolean show) {
+        windowTwo.setDisplayRowColHeadings(show);
+    }
+
+    /**
+     * Returns if RowColHeadings are displayed.
+     * @return whether RowColHeadings are displayed
+     */
+    public boolean isPrintRowColHeadings() {
+        return windowTwo.getDisplayRowColHeadings();
+    }
 
 
     /**
index a7063003a4057a3eb52f2938be3d7ef2f257100b..00124e6da1d96bdc7fa1998b437a837a8b80f2db 100644 (file)
@@ -1199,12 +1199,33 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
     /**
      * Turns on or off the printing of gridlines.
      *
-     * @param newPrintGridlines boolean to turn on or off the printing of
+     * @param show boolean to turn on or off the printing of
      *                          gridlines
      */
     @Override
-    public void setPrintGridlines(boolean newPrintGridlines) {
-        getSheet().getPrintGridlines().setPrintGridlines(newPrintGridlines);
+    public void setPrintGridlines(boolean show) {
+        getSheet().getPrintGridlines().setPrintGridlines(show);
+    }
+    
+    /**
+     * Returns whether row and column headings are printed.
+     *
+     * @return row and column headings are printed
+     */
+    @Override
+    public boolean isPrintRowAndColumnHeadings() {
+        return getSheet().getPrintHeaders().getPrintHeaders();
+    }
+
+    /**
+     * Turns on or off the printing of row and column headings.
+     *
+     * @param show boolean to turn on or off the printing of
+     *                          row and column headings
+     */
+    @Override
+    public void setPrintRowAndColumnHeadings(boolean show) {
+        getSheet().getPrintHeaders().setPrintHeaders(show);
     }
 
     /**
index cba701d9e6ffbb545afed456f195579fe9d68160..283628de345a7baeb4974cccc723adb448f1168a 100644 (file)
@@ -511,21 +511,35 @@ public interface Sheet extends Iterable<Row> {
      * Gets the flag indicating whether this sheet displays the lines
      * between rows and columns to make editing and reading easier.
      *
-     * @return <code>true</code> if this sheet displays gridlines.
-     * @see #isPrintGridlines() to check if printing of gridlines is turned on or off
+     * @return <code>true</code> if this sheet prints gridlines.
+     * @see #isDisplayGridlines() to check if gridlines are displayed on screen
      */
     boolean isPrintGridlines();
 
     /**
-     * Sets the flag indicating whether this sheet should display the lines
+     * Sets the flag indicating whether this sheet should print the lines
      * between rows and columns to make editing and reading easier.
-     * To turn printing of gridlines use {@link #setPrintGridlines(boolean)}
      *
-     *
-     * @param show <code>true</code> if this sheet should display gridlines.
-     * @see #setPrintGridlines(boolean)
+     * @param show <code>true</code> if this sheet should print gridlines.
+     * @see #setDisplayGridlines(boolean) to display gridlines on screen
      */
     void setPrintGridlines(boolean show);
+    
+    /**
+     * Gets the flag indicating whether this sheet prints the
+     * row and column headings when printing.
+     *
+     * @return <code>true</code> if this sheet prints row and column headings.
+     */
+    boolean isPrintRowAndColumnHeadings();
+
+    /**
+     * Sets the flag indicating whether this sheet should print
+     * row and columns headings when printing.
+     *
+     * @param show <code>true</code> if this sheet should print row and column headings.
+     */
+    void setPrintRowAndColumnHeadings(boolean show);
 
     /**
      * Gets the print setup object.
index 6962dae145d00f69ce0b1dfbed95b705a615fb6f..7d0b6fc74668802b5c3d274bfdcb874c257d596d 100644 (file)
@@ -704,11 +704,9 @@ public class SXSSFSheet implements Sheet, Cloneable
     }
 
     /**
-     * Gets the flag indicating whether this sheet displays the lines
-     * between rows and columns to make editing and reading easier.
+     * Returns whether gridlines are printed.
      *
-     * @return <code>true</code> if this sheet displays gridlines.
-     * @see #isPrintGridlines() to check if printing of gridlines is turned on or off
+     * @return whether gridlines are printed
      */
     @Override
     public boolean isPrintGridlines()
@@ -717,19 +715,37 @@ public class SXSSFSheet implements Sheet, Cloneable
     }
 
     /**
-     * Sets the flag indicating whether this sheet should display the lines
-     * between rows and columns to make editing and reading easier.
-     * To turn printing of gridlines use {@link #setPrintGridlines(boolean)}
+     * Turns on or off the printing of gridlines.
      *
-     *
-     * @param show <code>true</code> if this sheet should display gridlines.
-     * @see #setPrintGridlines(boolean)
+     * @param show boolean to turn on or off the printing of gridlines
      */
     @Override
     public void setPrintGridlines(boolean show)
     {
         _sh.setPrintGridlines(show);
     }
+    
+    /**
+     * Returns whether row and column headings are printed.
+     *
+     * @return whether row and column headings are printed
+     */
+    @Override
+    public boolean isPrintRowAndColumnHeadings()
+    {
+        return _sh.isPrintRowAndColumnHeadings();
+    }
+
+    /**
+     * Turns on or off the printing of row and column headings.
+     *
+     * @param show boolean to turn on or off the printing of row and column headings
+     */
+    @Override
+    public void setPrintRowAndColumnHeadings(boolean show)
+    {
+        _sh.setPrintRowAndColumnHeadings(show);
+    }
 
     /**
      * Gets the print setup object.
index 0dc1878a97100caab444ed6a4b1a2fb7e7848989..5df45e9078947483768b29ca3462fac9a8bc85c0 100644 (file)
@@ -1757,6 +1757,29 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
                 worksheet.getPrintOptions() : worksheet.addNewPrintOptions();
         opts.setGridLines(value);
     }
+    
+    /**
+     * Returns whether row and column headings are printed.
+     *
+     * @return whether row and column headings are printed
+     */
+    @Override
+    public boolean isPrintRowAndColumnHeadings() {
+        CTPrintOptions opts = worksheet.getPrintOptions();
+        return opts != null && opts.getHeadings();
+    }
+
+    /**
+     * Turns on or off the printing of row and column headings.
+     *
+     * @param value boolean to turn on or off the printing of row and column headings
+     */
+    @Override
+    public void setPrintRowAndColumnHeadings(boolean value) {
+        CTPrintOptions opts = worksheet.isSetPrintOptions() ?
+                worksheet.getPrintOptions() : worksheet.addNewPrintOptions();
+        opts.setHeadings(value);
+    }
 
     /**
      * Tests if there is a page break at the indicated row
index 6d8160638306b7841b2496c9fb909a595d4818aa..b1bff95a3fa72f315e2f9052b7b364a16df74bd8 100644 (file)
@@ -682,7 +682,7 @@ public abstract class BaseTestSheet {
     }
 
     /**
-     * Test basic display properties
+     * Test basic display and print properties
      */
     @Test
     public void sheetProperties() throws IOException {
@@ -704,6 +704,10 @@ public abstract class BaseTestSheet {
         assertFalse(sheet.isPrintGridlines());
         sheet.setPrintGridlines(true);
         assertTrue(sheet.isPrintGridlines());
+        
+        assertFalse(sheet.isPrintRowAndColumnHeadings());
+        sheet.setPrintRowAndColumnHeadings(true);
+        assertTrue(sheet.isPrintRowAndColumnHeadings());
 
         assertFalse(sheet.isDisplayFormulas());
         sheet.setDisplayFormulas(true);