com.hfg.xml.msofficexml.xlsx.spreadsheetml.SsmlSheetView Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of com_hfg Show documentation
Show all versions of com_hfg Show documentation
com.hfg xml, html, svg, and bioinformatics utility library
package com.hfg.xml.msofficexml.xlsx.spreadsheetml;
import com.hfg.exception.InvalidValueException;
import com.hfg.xml.XMLTag;
import com.hfg.xml.msofficexml.xlsx.CellRef;
import com.hfg.xml.msofficexml.xlsx.ExcelIndexedColor;
import com.hfg.xml.msofficexml.xlsx.Xlsx;
import java.awt.Color;
//------------------------------------------------------------------------------
/**
Represents an Office Open XML sheet view (<ssml:sheetView>) tag.
@author J. Alex Taylor, hairyfatguy.com
*/
//------------------------------------------------------------------------------
// com.hfg XML/HTML Coding Library
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com
// [email protected]
//------------------------------------------------------------------------------
// Ex:
public class SsmlSheetView extends SsmlXMLTag
{
//###########################################################################
// PRIVATE FIELDS
//###########################################################################
private XMLTag mSelectionTag;
private SsmlPane mPane;
//###########################################################################
// CONSTRUCTORS
//###########################################################################
//---------------------------------------------------------------------------
public SsmlSheetView(Xlsx inXlsx)
{
super(SsmlXML.SHEET_VIEW, inXlsx);
// Set some default attributes
setTabSelected(true);
setViewType(SsmlSheetViewType.normal);
setWorkbookViewId(0);
setSelection(new CellRef("A1"));
}
//###########################################################################
// PUBLIC METHODS
//###########################################################################
//---------------------------------------------------------------------------
/**
Specifies the view type.
Default value is "normal".
*/
public SsmlSheetView setViewType(SsmlSheetViewType inValue)
{
if (inValue != null)
{
setAttribute(SsmlXML.VIEW_ATT, inValue.name());
}
else
{
removeAttribute(SsmlXML.VIEW_ATT);
}
return this;
}
//---------------------------------------------------------------------------
/**
Specifies the location of the top left visible cell in the bottom right pane (when in Left-to-Right mode).
*/
public SsmlSheetView setTopLeftCell(CellRef inValue)
{
if (inValue != null)
{
setAttribute(SsmlXML.TOP_LEFT_CELL_ATT, inValue.toString());
}
else
{
removeAttribute(SsmlXML.TOP_LEFT_CELL_ATT);
}
return this;
}
//---------------------------------------------------------------------------
/**
Specifies whether the sheet is in 'right to left' display mode.
When in this mode, Column A is on the far right, Column B ;is one column left of Column A, and so on.
Also, information in cells is displayed in the Right to Left format.
Default value is "false".
*/
public SsmlSheetView setRightToLeft(boolean inValue)
{
setAttribute(SsmlXML.RIGHT_TO_LEFT_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Specifies whether or not the sheet tab is selected.
Default value is "false".
*/
public SsmlSheetView setTabSelected(boolean inValue)
{
setAttribute(SsmlXML.TAB_SELECTED_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Specifies whether or not the ruler is displayed in Page Layout View.
Default value is "true".
*/
public SsmlSheetView showRuler(boolean inValue)
{
setAttribute(SsmlXML.SHOW_RULER_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Specifies whether or not to display zero values.
Default value is "true".
*/
public SsmlSheetView setShowZeros(boolean inValue)
{
setAttribute(SsmlXML.SHOW_ZEROS_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Specifies whether or not to display formulas.
Default value is "false".
*/
public SsmlSheetView setShowFormulas(boolean inValue)
{
setAttribute(SsmlXML.SHOW_FORMULAS_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Specifies whether or not to display grid lines.
Default value is "true".
*/
public SsmlSheetView setShowGridLines(boolean inValue)
{
setAttribute(SsmlXML.SHOW_GRID_LINES_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Specifies whether or not page layout view shall display margins.
False means do not display left, right, top (header), and bottom (footer) margins
(even when there is data in the header or footer).
Default value is "true".
*/
public SsmlSheetView setShowWhiteSpace(boolean inValue)
{
setAttribute(SsmlXML.SHOW_WHITE_SPACE_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Specifies whether or not the sheet has outline symbols visible.
This flag shall always override SheetPr element's outlinePr child element
whose attribute is named showOutlineSymbols when there is a conflict.
Default value is "true".
*/
public SsmlSheetView setShowOutlineSymbols(boolean inValue)
{
setAttribute(SsmlXML.SHOW_OUTLINE_SYMBOLS_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Specifies whether or not the consuming application should use the default grid
lines color (system dependent). Overrides any color specified in colorId.
Default value is "true".
*/
public SsmlSheetView setUseDefaultGridColor(boolean inValue)
{
setAttribute(SsmlXML.DEFAULT_GRID_COLOR, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Specifies whether or not to display row and column headers.
Default value is "true".
*/
public SsmlSheetView setShowRowColHeaders(boolean inValue)
{
setAttribute(SsmlXML.SHOW_ROW_COL_HEADERS_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Specifies whether or not to enable window protection.
Default value is "false".
*/
public SsmlSheetView setWindowProtection(boolean inValue)
{
setAttribute(SsmlXML.WINDOW_PROTECTION_ATT, inValue);
return this;
}
//---------------------------------------------------------------------------
/**
Specifies the color value for row/column text headings and gridlines.
The color specified will be mapped to the closest Excel indexed color value.
*/
public SsmlSheetView setColor(Color inValue)
{
if (inValue != null)
{
setAttribute(SsmlXML.COLOR_ID_ATT, (inValue instanceof ExcelIndexedColor ? (ExcelIndexedColor) inValue : ExcelIndexedColor.findNearestMatch(inValue)).getIndex());
// The default coloring needs to be turned off for this to work.
setUseDefaultGridColor(false);
}
else
{
removeAttribute(SsmlXML.COLOR_ID_ATT);
setUseDefaultGridColor(true);
}
return this;
}
//---------------------------------------------------------------------------
/**
Specifies the window zoom magnification for current view representing percent values.
This attribute is restricted to values ranging from 10 to 400. Horizontal & Vertical scale together.
Default value is 100.
*/
public SsmlSheetView setZoomScale(Integer inValue)
{
if (inValue != null)
{
if (inValue < 10
|| inValue > 400)
{
throw new InvalidValueException("The zoom scale value must be between 10 and 400 (%).");
}
setAttribute(SsmlXML.ZOOM_SCALE_ATT, inValue);
}
else
{
removeAttribute(SsmlXML.ZOOM_SCALE_ATT);
}
return this;
}
//---------------------------------------------------------------------------
/**
Specifies the zoom magnification when in normal view, representing percent values.
This attribute is restricted to values ranging from 10 to 400. Horizontal & Vertical scale together.
Default value is 0.
*/
public SsmlSheetView setNormalViewZoomScale(Integer inValue)
{
if (inValue != null)
{
if (inValue < 10
|| inValue > 400)
{
throw new InvalidValueException("The zoom scale value must be between 10 and 400 (%).");
}
setAttribute(SsmlXML.ZOOM_SCALE_NORMAL_ATT, inValue);
}
else
{
removeAttribute(SsmlXML.ZOOM_SCALE_NORMAL_ATT);
}
return this;
}
//---------------------------------------------------------------------------
/**
Specifies the zoom magnification when in page layout view, representing percent values.
This attribute is restricted to values ranging from 10 to 400. Horizontal & Vertical scale together.
Default value is 0.
*/
public SsmlSheetView setPageLayoutViewZoomScale(Integer inValue)
{
if (inValue != null)
{
if (inValue < 10
|| inValue > 400)
{
throw new InvalidValueException("The zoom scale value must be between 10 and 400 (%).");
}
setAttribute(SsmlXML.ZOOM_SCALE_PAGE_LAYOUT_VIEW_ATT, inValue);
}
else
{
removeAttribute(SsmlXML.ZOOM_SCALE_PAGE_LAYOUT_VIEW_ATT);
}
return this;
}
//---------------------------------------------------------------------------
/**
Specifies the zoom magnification when in page break preview, representing percent values.
This attribute is restricted to values ranging from 10 to 400. Horizontal & Vertical scale together.
Default value is 0.
*/
public SsmlSheetView setSheetLayoutViewZoomScale(Integer inValue)
{
if (inValue != null)
{
if (inValue < 10
|| inValue > 400)
{
throw new InvalidValueException("The zoom scale value must be between 10 and 400 (%).");
}
setAttribute(SsmlXML.ZOOM_SCALE_SHEET_LAYOUT_VIEW_ATT, inValue);
}
else
{
removeAttribute(SsmlXML.ZOOM_SCALE_SHEET_LAYOUT_VIEW_ATT);
}
return this;
}
//---------------------------------------------------------------------------
public SsmlSheetView setWorkbookViewId(Integer inValue)
{
if (inValue != null)
{
setAttribute(SsmlXML.WORKBOOK_VIEW_ID_ATT, inValue);
}
else
{
removeAttribute(SsmlXML.WORKBOOK_VIEW_ID_ATT);
}
return this;
}
//---------------------------------------------------------------------------
public SsmlSheetView setSelection(CellRef inValue)
{
if (null == mSelectionTag)
{
// Check it it has been added via addSubtag()...
mSelectionTag = getOptionalSubtagByName(SsmlXML.SELECTION);
if (null == mSelectionTag)
{
mSelectionTag = new XMLTag(SsmlXML.SELECTION);
addSubtag(mSelectionTag);
}
}
mSelectionTag.setAttribute(SsmlXML.ACTIVE_CELL_ATT, inValue.toString());
mSelectionTag.setAttribute(SsmlXML.SQUARE_REF_ATT, inValue.toString());
return this;
}
//---------------------------------------------------------------------------
public SsmlPane getPane()
{
if (null == mPane)
{
// Check it it has been added via addSubtag()...
mPane = getOptionalSubtagByName(SsmlXML.PANE);
if (null == mPane)
{
mPane = new SsmlPane(getParentDoc());
addSubtag(mPane);
}
}
return mPane;
}
}