📄 sheetsettings.java
字号:
/*********************************************************************
*
* Copyright (C) 2002 Andrew Khan
*
* 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
***************************************************************************/
package jxl;
import common.Assert;
import jxl.format.PageOrientation;
import jxl.format.PaperSize;
/**
* This is a bean which client applications may use to get/set various
* properties which are associated with a particular worksheet, such
* as headers and footers, page orientation etc.
*/
public final class SheetSettings
{
/**
* The page orientation
*/
private PageOrientation orientation;
/**
* The paper size for printing
*/
private PaperSize paperSize;
/**
* Indicates whether or not this sheet is protected
*/
private boolean sheetProtected;
/**
* Indicates whether or not this sheet is hidden
*/
private boolean hidden;
/**
* Indicates whether or not this sheet is selected
*/
private boolean selected;
/**
* The header
*/
private HeaderFooter header;
/**
* The margin allocated for any page headers, in inches
*/
private double headerMargin;
/**
* The footer
*/
private HeaderFooter footer;
/**
* The margin allocated for any page footers, in inches
*/
private double footerMargin;
/**
* The scale factor used when printing
*/
private int scaleFactor;
/**
* The zoom factor used when viewing. Note the difference between
* this and the scaleFactor which is used when printing
*/
private int zoomFactor;
/**
* The page number at which to commence printing
*/
private int pageStart;
/**
* The number of pages into which this excel sheet is squeezed widthwise
*/
private int fitWidth;
/**
* The number of pages into which this excel sheet is squeezed heightwise
*/
private int fitHeight;
/**
* The horizontal print resolution
*/
private int horizontalPrintResolution;
/**
* The vertical print resolution
*/
private int verticalPrintResolution;
/**
* The margin from the left hand side of the paper in inches
*/
private double leftMargin;
/**
* The margin from the right hand side of the paper in inches
*/
private double rightMargin;
/**
* The margin from the top of the paper in inches
*/
private double topMargin;
/**
* The margin from the bottom of the paper in inches
*/
private double bottomMargin;
/**
* Indicates whether to fit the print to the pages or scale the output
* This field is manipulated indirectly by virtue of the setFitWidth/Height
* methods
*/
private boolean fitToPages;
/**
* Indicates whether grid lines should be displayed
*/
private boolean showGridLines;
/**
* Indicates whether grid lines should be printed
*/
private boolean printGridLines;
/**
* Indicates whether sheet headings should be printed
*/
private boolean printHeaders;
/**
* Indicates whether the sheet should display zero values
*/
private boolean displayZeroValues;
/**
* The password for protected sheets
*/
private String password;
/**
* The password hashcode - used when copying sheets
*/
private int passwordHash;
/**
* The default column width, in characters
*/
private int defaultColumnWidth;
/**
* The default row height, in 1/20th of a point
*/
private int defaultRowHeight;
/**
* The horizontal freeze pane
*/
private int horizontalFreeze;
/**
* The vertical freeze position
*/
private int verticalFreeze;
/**
* The number of copies to print
*/
private int copies;
// ***
// The defaults
// **
private static final PageOrientation defaultOrientation =
PageOrientation.PORTRAIT;
private static final PaperSize defaultPaperSize = PaperSize.A4;
private static final double defaultHeaderMargin = 0.5;
private static final double defaultFooterMargin = 0.5;
private static final int defaultPrintResolution = 0x12c;
private static final double defaultWidthMargin = 0.75;
private static final double defaultHeightMargin = 1;
private static final int defaultDefaultColumnWidth = 8;
private static final int defaultZoomFactor = 100;
// The publicly accessible values
/**
* The default value for the default row height
*/
public static final int DEFAULT_DEFAULT_ROW_HEIGHT = 0xff;
/**
* Default constructor
*/
public SheetSettings()
{
orientation = defaultOrientation;
paperSize = defaultPaperSize;
sheetProtected = false;
hidden = false;
selected = false;
headerMargin = defaultHeaderMargin;
footerMargin = defaultFooterMargin;
horizontalPrintResolution = defaultPrintResolution;
verticalPrintResolution = defaultPrintResolution;
leftMargin = defaultWidthMargin;
rightMargin = defaultWidthMargin;
topMargin = defaultHeightMargin;
bottomMargin = defaultHeightMargin;
fitToPages = false;
showGridLines = true;
printGridLines = false;
printHeaders = false;
displayZeroValues = true;
defaultColumnWidth = defaultDefaultColumnWidth;
defaultRowHeight = DEFAULT_DEFAULT_ROW_HEIGHT;
zoomFactor = defaultZoomFactor;
horizontalFreeze = 0;
verticalFreeze = 0;
copies = 1;
header = new HeaderFooter();
footer = new HeaderFooter();
}
/**
* Copy constructor. Called when copying sheets
* @param copy the settings to copy
*/
public SheetSettings(SheetSettings copy)
{
Assert.verify(copy != null);
orientation = copy.orientation;
paperSize = copy.paperSize;
sheetProtected = copy.sheetProtected;
hidden = copy.hidden;
selected = false; // don't copy the selected flag
headerMargin = copy.headerMargin;
footerMargin = copy.footerMargin;
scaleFactor = copy.scaleFactor;
pageStart = copy.pageStart;
fitWidth = copy.fitWidth;
fitHeight = copy.fitHeight;
horizontalPrintResolution = copy.horizontalPrintResolution;
verticalPrintResolution = copy.verticalPrintResolution;
leftMargin = copy.leftMargin;
rightMargin = copy.rightMargin;
topMargin = copy.topMargin;
bottomMargin = copy.bottomMargin;
fitToPages = copy.fitToPages;
password = copy.password;
passwordHash = copy.passwordHash;
defaultColumnWidth = copy.defaultColumnWidth;
defaultRowHeight = copy.defaultRowHeight;
zoomFactor = copy.zoomFactor;
showGridLines = copy.showGridLines;
displayZeroValues = copy.displayZeroValues;
horizontalFreeze = copy.horizontalFreeze;
verticalFreeze = copy.verticalFreeze;
copies = copy.copies;
header = new HeaderFooter(copy.header);
footer = new HeaderFooter(copy.footer);
}
/**
* Sets the paper orientation for printing this sheet
*
* @param po the orientation
*/
public void setOrientation(PageOrientation po)
{
orientation = po;
}
/**
* Accessor for the orientation
*
* @return the orientation
*/
public PageOrientation getOrientation()
{
return orientation;
}
/**
* Sets the paper size to be used when printing this sheet
*
* @param ps the paper size
*/
public void setPaperSize(PaperSize ps)
{
paperSize = ps;
}
/**
* Accessor for the paper size
*
* @return the paper size
*/
public PaperSize getPaperSize()
{
return paperSize;
}
/**
* Queries whether this sheet is protected (ie. read only)
*
* @return TRUE if this sheet is read only, FALSE otherwise
*/
public boolean isProtected()
{
return sheetProtected;
}
/**
* Sets the protected (ie. read only) status of this sheet
*
* @param p the protected status
*/
public void setProtected(boolean p)
{
sheetProtected = p;
}
/**
* Sets the margin for any page headers
*
* @param d the margin in inches
*/
public void setHeaderMargin(double d)
{
headerMargin = d;
}
/**
* Accessor for the header margin
*
* @return the header margin
*/
public double getHeaderMargin()
{
return headerMargin;
}
/**
* Sets the margin for any page footer
*
* @param d the footer margin in inches
*/
public void setFooterMargin(double d)
{
footerMargin = d;
}
/**
* Accessor for the footer margin
*
* @return the footer margin
*/
public double getFooterMargin()
{
return footerMargin;
}
/**
* Sets the hidden status of this worksheet
*
* @param h the hidden flag
*/
public void setHidden(boolean h)
{
hidden = h;
}
/**
* Accessor for the hidden nature of this sheet
*
* @return TRUE if this sheet is hidden, FALSE otherwise
*/
public boolean isHidden()
{
return hidden;
}
/**
* Sets this sheet to be when it is opened in excel
*
* @deprecated use overloaded version which takes a boolean
*/
public void setSelected()
{
setSelected(true);
}
/**
* Sets this sheet to be when it is opened in excel
*
* @param s sets whether this sheet is selected or not
*/
public void setSelected(boolean s)
{
selected = s;
}
/**
* Accessor for the selected nature of the sheet
*
* @return TRUE if this sheet is selected, FALSE otherwise
*/
public boolean isSelected()
{
return selected;
}
/**
* Sets the scale factor for this sheet to be used when printing. The
* parameter is a percentage, therefore setting a scale factor of 100 will
* print at normal size, 50 half size, 200 double size etc
*
* @param sf the scale factor as a percentage
*/
public void setScaleFactor(int sf)
{
scaleFactor = sf;
fitToPages = false;
}
/**
* Accessor for the scale factor
*
* @return the scale factor
*/
public int getScaleFactor()
{
return scaleFactor;
}
/**
* Sets the page number at which to commence printing
*
* @param ps the page start number
*/
public void setPageStart(int ps)
{
pageStart = ps;
}
/**
* Accessor for the page start
*
* @return the page start
*/
public int getPageStart()
{
return pageStart;
}
/**
* Sets the number of pages widthwise which this sheet should be
* printed into
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -