Added features to test and change the display of gridlines, formulas, and row/column headings. This is in reference to bug 21884. Started keeping track of the WindowTwoRecord reference to easy update without a search. Modified other procedures to use the reference where possible.
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/branches/REL_2_BRANCH@353243 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
466f9aa1d3
commit
b6967b691a
@ -108,6 +108,7 @@ public class Sheet implements Model
|
|||||||
protected HeaderRecord header = null;
|
protected HeaderRecord header = null;
|
||||||
protected FooterRecord footer = null;
|
protected FooterRecord footer = null;
|
||||||
protected PrintGridlinesRecord printGridlines = null;
|
protected PrintGridlinesRecord printGridlines = null;
|
||||||
|
protected WindowTwoRecord windowTwo = null;
|
||||||
protected MergeCellsRecord merged = null;
|
protected MergeCellsRecord merged = null;
|
||||||
protected Margin margins[] = null;
|
protected Margin margins[] = null;
|
||||||
protected ArrayList mergedRecords = new ArrayList();
|
protected ArrayList mergedRecords = new ArrayList();
|
||||||
@ -282,6 +283,10 @@ public class Sheet implements Model
|
|||||||
{
|
{
|
||||||
retval.selection = (SelectionRecord) rec;
|
retval.selection = (SelectionRecord) rec;
|
||||||
}
|
}
|
||||||
|
else if ( rec.getSid() == WindowTwoRecord.sid )
|
||||||
|
{
|
||||||
|
retval.windowTwo = (WindowTwoRecord) rec;
|
||||||
|
}
|
||||||
|
|
||||||
if (rec != null)
|
if (rec != null)
|
||||||
{
|
{
|
||||||
@ -408,7 +413,7 @@ public class Sheet implements Model
|
|||||||
retval.dims = ( DimensionsRecord ) retval.createDimensions();
|
retval.dims = ( DimensionsRecord ) retval.createDimensions();
|
||||||
retval.dimsloc = 19;
|
retval.dimsloc = 19;
|
||||||
records.add(retval.dims);
|
records.add(retval.dims);
|
||||||
records.add(retval.createWindowTwo());
|
records.add(retval.windowTwo = retval.createWindowTwo());
|
||||||
retval.setLoc(records.size() - 1);
|
retval.setLoc(records.size() - 1);
|
||||||
retval.selection =
|
retval.selection =
|
||||||
(SelectionRecord) retval.createSelection();
|
(SelectionRecord) retval.createSelection();
|
||||||
@ -2037,7 +2042,7 @@ public class Sheet implements Model
|
|||||||
* @return record containing a WindowTwoRecord
|
* @return record containing a WindowTwoRecord
|
||||||
*/
|
*/
|
||||||
|
|
||||||
protected Record createWindowTwo()
|
protected WindowTwoRecord createWindowTwo()
|
||||||
{
|
{
|
||||||
WindowTwoRecord retval = new WindowTwoRecord();
|
WindowTwoRecord retval = new WindowTwoRecord();
|
||||||
|
|
||||||
@ -2338,7 +2343,6 @@ public class Sheet implements Model
|
|||||||
* @param sel True to select the sheet, false otherwise.
|
* @param sel True to select the sheet, false otherwise.
|
||||||
*/
|
*/
|
||||||
public void setSelected(boolean sel) {
|
public void setSelected(boolean sel) {
|
||||||
WindowTwoRecord windowTwo = (WindowTwoRecord) findFirstRecordBySid(WindowTwoRecord.sid);
|
|
||||||
windowTwo.setSelected(sel);
|
windowTwo.setSelected(sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2437,9 +2441,8 @@ public class Sheet implements Model
|
|||||||
}
|
}
|
||||||
records.add(loc+1, pane);
|
records.add(loc+1, pane);
|
||||||
|
|
||||||
WindowTwoRecord windowRecord = (WindowTwoRecord) records.get(loc);
|
windowTwo.setFreezePanes(true);
|
||||||
windowRecord.setFreezePanes(true);
|
windowTwo.setFreezePanesNoSplit(true);
|
||||||
windowRecord.setFreezePanesNoSplit(true);
|
|
||||||
|
|
||||||
SelectionRecord sel = (SelectionRecord) findFirstRecordBySid(SelectionRecord.sid);
|
SelectionRecord sel = (SelectionRecord) findFirstRecordBySid(SelectionRecord.sid);
|
||||||
// SelectionRecord sel2 = (SelectionRecord) sel.clone();
|
// SelectionRecord sel2 = (SelectionRecord) sel.clone();
|
||||||
@ -2487,9 +2490,8 @@ public class Sheet implements Model
|
|||||||
r.setActivePane((short) activePane);
|
r.setActivePane((short) activePane);
|
||||||
records.add(loc+1, r);
|
records.add(loc+1, r);
|
||||||
|
|
||||||
WindowTwoRecord windowRecord = (WindowTwoRecord) records.get(loc);
|
windowTwo.setFreezePanes(false);
|
||||||
windowRecord.setFreezePanes(false);
|
windowTwo.setFreezePanesNoSplit(false);
|
||||||
windowRecord.setFreezePanesNoSplit(false);
|
|
||||||
|
|
||||||
SelectionRecord sel = (SelectionRecord) findFirstRecordBySid(SelectionRecord.sid);
|
SelectionRecord sel = (SelectionRecord) findFirstRecordBySid(SelectionRecord.sid);
|
||||||
// SelectionRecord sel2 = (SelectionRecord) sel.clone();
|
// SelectionRecord sel2 = (SelectionRecord) sel.clone();
|
||||||
@ -2523,6 +2525,54 @@ public class Sheet implements Model
|
|||||||
this.selection = selection;
|
this.selection = selection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the gridlines are shown in a viewer.
|
||||||
|
* @param show whether to show gridlines or not
|
||||||
|
*/
|
||||||
|
public void setDisplayGridlines(boolean show) {
|
||||||
|
windowTwo.setDisplayGridlines(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if gridlines are displayed.
|
||||||
|
* @return whether gridlines are displayed
|
||||||
|
*/
|
||||||
|
public boolean isDisplayGridlines() {
|
||||||
|
return windowTwo.getDisplayGridlines();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the formulas are shown in a viewer.
|
||||||
|
* @param show whether to show formulas or not
|
||||||
|
*/
|
||||||
|
public void setDisplayFormulas(boolean show) {
|
||||||
|
windowTwo.setDisplayFormulas(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if formulas are displayed.
|
||||||
|
* @return whether formulas are displayed
|
||||||
|
*/
|
||||||
|
public boolean isDisplayFormulas() {
|
||||||
|
return windowTwo.getDisplayFormulas();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the RowColHeadings are shown in a viewer.
|
||||||
|
* @param show whether to show RowColHeadings or not
|
||||||
|
*/
|
||||||
|
public void setDisplayRowColHeadings(boolean show) {
|
||||||
|
windowTwo.setDisplayRowColHeadings(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if RowColHeadings are displayed.
|
||||||
|
* @return whether RowColHeadings are displayed
|
||||||
|
*/
|
||||||
|
public boolean isDisplayRowColHeadings() {
|
||||||
|
return windowTwo.getDisplayRowColHeadings();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the array of margins. If not created, will create.
|
* Returns the array of margins. If not created, will create.
|
||||||
*
|
*
|
||||||
@ -2533,5 +2583,4 @@ public class Sheet implements Model
|
|||||||
margins = new Margin[4];
|
margins = new Margin[4];
|
||||||
return margins;
|
return margins;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1085,5 +1085,51 @@ public class HSSFSheet
|
|||||||
getSheet().createSplitPane( xSplitPos, ySplitPos, topRow, leftmostColumn, activePane );
|
getSheet().createSplitPane( xSplitPos, ySplitPos, topRow, leftmostColumn, activePane );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the gridlines are shown in a viewer.
|
||||||
|
* @param show whether to show gridlines or not
|
||||||
|
*/
|
||||||
|
public void setDisplayGridlines(boolean show) {
|
||||||
|
sheet.setDisplayGridlines(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if gridlines are displayed.
|
||||||
|
* @return whether gridlines are displayed
|
||||||
|
*/
|
||||||
|
public boolean isDisplayGridlines() {
|
||||||
|
return sheet.isDisplayGridlines();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the formulas are shown in a viewer.
|
||||||
|
* @param show whether to show formulas or not
|
||||||
|
*/
|
||||||
|
public void setDisplayFormulas(boolean show) {
|
||||||
|
sheet.setDisplayFormulas(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if formulas are displayed.
|
||||||
|
* @return whether formulas are displayed
|
||||||
|
*/
|
||||||
|
public boolean isDisplayFormulas() {
|
||||||
|
return sheet.isDisplayFormulas();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets whether the RowColHeadings are shown in a viewer.
|
||||||
|
* @param show whether to show RowColHeadings or not
|
||||||
|
*/
|
||||||
|
public void setDisplayRowColHeadings(boolean show) {
|
||||||
|
sheet.setDisplayRowColHeadings(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns if RowColHeadings are displayed.
|
||||||
|
* @return whether RowColHeadings are displayed
|
||||||
|
*/
|
||||||
|
public boolean isDisplayRowColHeadings() {
|
||||||
|
return sheet.isDisplayRowColHeadings();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -318,8 +318,49 @@ public class TestHSSFSheet
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the display of gridlines, formulas, and rowcolheadings.
|
||||||
|
* @author Shawn Laubach (slaubach at apache dot org)
|
||||||
|
*/
|
||||||
|
public void testDisplayOptions() throws Exception {
|
||||||
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
|
HSSFSheet sheet = wb.createSheet();
|
||||||
|
|
||||||
|
File tempFile = File.createTempFile("display", "test.xls");
|
||||||
|
FileOutputStream stream = new FileOutputStream(tempFile);
|
||||||
|
wb.write(stream);
|
||||||
|
stream.close();
|
||||||
|
|
||||||
|
FileInputStream readStream = new FileInputStream(tempFile);
|
||||||
|
wb = new HSSFWorkbook(readStream);
|
||||||
|
sheet = wb.getSheetAt(0);
|
||||||
|
readStream.close();
|
||||||
|
|
||||||
|
assertEquals(sheet.isDisplayGridlines(), true);
|
||||||
|
assertEquals(sheet.isDisplayRowColHeadings(), true);
|
||||||
|
assertEquals(sheet.isDisplayFormulas(), false);
|
||||||
|
|
||||||
|
sheet.setDisplayGridlines(false);
|
||||||
|
sheet.setDisplayRowColHeadings(false);
|
||||||
|
sheet.setDisplayFormulas(true);
|
||||||
|
|
||||||
|
tempFile = File.createTempFile("display", "test.xls");
|
||||||
|
stream = new FileOutputStream(tempFile);
|
||||||
|
wb.write(stream);
|
||||||
|
stream.close();
|
||||||
|
|
||||||
|
readStream = new FileInputStream(tempFile);
|
||||||
|
wb = new HSSFWorkbook(readStream);
|
||||||
|
sheet = wb.getSheetAt(0);
|
||||||
|
readStream.close();
|
||||||
|
|
||||||
|
|
||||||
|
assertEquals(sheet.isDisplayGridlines(), false);
|
||||||
|
assertEquals(sheet.isDisplayRowColHeadings(), false);
|
||||||
|
assertEquals(sheet.isDisplayFormulas(), true);
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(java.lang.String[] args) {
|
public static void main(java.lang.String[] args) {
|
||||||
junit.textui.TestRunner.run(TestHSSFSheet.class);
|
junit.textui.TestRunner.run(TestHSSFSheet.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user