diff --git a/src/java/org/apache/poi/hssf/model/InternalSheet.java b/src/java/org/apache/poi/hssf/model/InternalSheet.java index 76de95136..9dd03a804 100644 --- a/src/java/org/apache/poi/hssf/model/InternalSheet.java +++ b/src/java/org/apache/poi/hssf/model/InternalSheet.java @@ -103,6 +103,7 @@ public final class InternalSheet { private List _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(); + } /** diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index a7063003a..00124e6da 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -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); } /** diff --git a/src/java/org/apache/poi/ss/usermodel/Sheet.java b/src/java/org/apache/poi/ss/usermodel/Sheet.java index cba701d9e..283628de3 100644 --- a/src/java/org/apache/poi/ss/usermodel/Sheet.java +++ b/src/java/org/apache/poi/ss/usermodel/Sheet.java @@ -511,21 +511,35 @@ public interface Sheet extends Iterable { * Gets the flag indicating whether this sheet displays the lines * between rows and columns to make editing and reading easier. * - * @return true if this sheet displays gridlines. - * @see #isPrintGridlines() to check if printing of gridlines is turned on or off + * @return true 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 true if this sheet should display gridlines. - * @see #setPrintGridlines(boolean) + * @param show true 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 true 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 true if this sheet should print row and column headings. + */ + void setPrintRowAndColumnHeadings(boolean show); /** * Gets the print setup object. diff --git a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java index 6962dae14..7d0b6fc74 100644 --- a/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/streaming/SXSSFSheet.java @@ -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 true 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 true 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. diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index 0dc1878a9..5df45e907 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -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 diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java index 6d8160638..b1bff95a3 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java @@ -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);