⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sheetsettings.java

📁 专业为java开发的用于和excel交互的api函数。可以方便访问excel
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************
*
*      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;
import jxl.biff.SheetRangeImpl;
import jxl.Range;

/**
 * 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 the view mode
   */
  private boolean pageBreakPreviewMode;

  /**
   * 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;

  /**
   * Vertical centre flag
   */
  private boolean verticalCentre;

  /**
   * Horizontal centre flag
   */
  private boolean horizontalCentre;

  /**
   * The number of copies to print
   */
  private int copies;

  /**
   * Automatic formula calculation
   */
  private boolean automaticFormulaCalculation;

  /**
   * Recalculate the formulas before save
   */
  private boolean recalculateFormulasBeforeSave;

  /**
   * The magnification factor for use during page break preview mode (in 
   * percent)
   */
  private int pageBreakPreviewMagnification;

  /**
   * The magnification factor for use during normal mode (in percent)
   */
  private int normalMagnification;

  /**
   * The print area
   */
  private Range printArea;

  /**
   * The print row titles
   */
  private Range printTitlesRow;

  /**
   * The print column titles
   */
  private Range printTitlesCol;
    
  /**
   * A handle to the sheet - used internally for ranges
   */
  private Sheet sheet;

  // ***
  // The defaults
  // **
  private static final PageOrientation DEFAULT_ORIENTATION =
    PageOrientation.PORTRAIT;
  private static final PaperSize DEFAULT_PAPER_SIZE = PaperSize.A4;
  private static final double DEFAULT_HEADER_MARGIN = 0.5;
  private static final double DEFAULT_FOOTER_MARGIN = 0.5;
  private static final int    DEFAULT_PRINT_RESOLUTION = 0x12c;
  private static final double DEFAULT_WIDTH_MARGIN     = 0.75;
  private static final double DEFAULT_HEIGHT_MARGIN    = 1;

  private static final int DEFAULT_DEFAULT_COLUMN_WIDTH = 8;
  private static final int DEFAULT_ZOOM_FACTOR = 100;
  private static final int DEFAULT_NORMAL_MAGNIFICATION = 100;
  private static final int DEFAULT_PAGE_BREAK_PREVIEW_MAGNIFICATION = 60;

  // 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(Sheet s)
  {
    sheet = s; // for internal use, when accessing ranges
    orientation        = DEFAULT_ORIENTATION;
    paperSize          = DEFAULT_PAPER_SIZE;
    sheetProtected     = false;
    hidden             = false;
    selected           = false;
    headerMargin       = DEFAULT_HEADER_MARGIN;
    footerMargin       = DEFAULT_FOOTER_MARGIN;
    horizontalPrintResolution = DEFAULT_PRINT_RESOLUTION;
    verticalPrintResolution   = DEFAULT_PRINT_RESOLUTION;
    leftMargin         = DEFAULT_WIDTH_MARGIN;
    rightMargin        = DEFAULT_WIDTH_MARGIN;
    topMargin          = DEFAULT_HEIGHT_MARGIN;
    bottomMargin       = DEFAULT_HEIGHT_MARGIN;
    fitToPages         = false;
    showGridLines      = true;
    printGridLines     = false;
    printHeaders       = false;
    pageBreakPreviewMode = false;
    displayZeroValues  = true;
    defaultColumnWidth = DEFAULT_DEFAULT_COLUMN_WIDTH;
    defaultRowHeight   = DEFAULT_DEFAULT_ROW_HEIGHT;
    zoomFactor         = DEFAULT_ZOOM_FACTOR;
    pageBreakPreviewMagnification = DEFAULT_PAGE_BREAK_PREVIEW_MAGNIFICATION;
    normalMagnification = DEFAULT_NORMAL_MAGNIFICATION;
    horizontalFreeze   = 0;
    verticalFreeze     = 0;
    copies             = 1;
    header             = new HeaderFooter();
    footer             = new HeaderFooter();
    automaticFormulaCalculation = true;
    recalculateFormulasBeforeSave = true;
  }

  /**
   * Copy constructor.  Called when copying sheets
   * @param copy the settings to copy
   */
  public SheetSettings(SheetSettings copy, Sheet s)
  {
    Assert.verify(copy != null);

    sheet = s;  // for internal use when accessing ranges
    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;
    pageBreakPreviewMagnification = copy.pageBreakPreviewMagnification;
    normalMagnification = copy.normalMagnification;
    showGridLines      = copy.showGridLines;
    displayZeroValues  = copy.displayZeroValues;
    pageBreakPreviewMode = copy.pageBreakPreviewMode;
    horizontalFreeze   = copy.horizontalFreeze;
    verticalFreeze     = copy.verticalFreeze;
    horizontalCentre   = copy.horizontalCentre;
    verticalCentre     = copy.verticalCentre;
    copies             = copy.copies;
    header             = new HeaderFooter(copy.header);
    footer             = new HeaderFooter(copy.footer);
    automaticFormulaCalculation = copy.automaticFormulaCalculation;
    recalculateFormulasBeforeSave = copy.recalculateFormulasBeforeSave;

    if (copy.printArea != null)
    {
      printArea = new SheetRangeImpl
        (sheet,
         copy.getPrintArea().getTopLeft().getColumn(),
         copy.getPrintArea().getTopLeft().getRow(),
         copy.getPrintArea().getBottomRight().getColumn(),
         copy.getPrintArea().getBottomRight().getRow());
    }
    
    if (copy.printTitlesRow != null)
    {
      printTitlesRow = new SheetRangeImpl
        (sheet,
         copy.getPrintTitlesRow().getTopLeft().getColumn(),
         copy.getPrintTitlesRow().getTopLeft().getRow(),
         copy.getPrintTitlesRow().getBottomRight().getColumn(),
         copy.getPrintTitlesRow().getBottomRight().getRow());
    }    

    if (copy.printTitlesCol != null)
    {
      printTitlesCol = new SheetRangeImpl
        (sheet,
         copy.getPrintTitlesCol().getTopLeft().getColumn(),
         copy.getPrintTitlesCol().getTopLeft().getRow(),
         copy.getPrintTitlesCol().getBottomRight().getColumn(),
         copy.getPrintTitlesCol().getBottomRight().getRow());
    }    
  }

  /**
   * 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
   *
   * @param fw the number of pages
   */
  public void setFitWidth(int fw)
  {
    fitWidth = fw;
    fitToPages = true;
  }

  /**
   * Accessor for the fit width
   *
   * @return the number of pages this sheet will be printed into widthwise
   */
  public int getFitWidth()
  {
    return fitWidth;
  }

  /**
   * Sets the number of pages vertically that this sheet will be printed into
   *
   * @param fh the number of pages this sheet will be printed into heightwise
   */
  public void setFitHeight(int fh)
  {
    fitHeight = fh;
    fitToPages = true;
  }

  /**
   * Accessor for the fit height
   *
   * @return the number of pages this sheet will be printed into heightwise
   */
  public int getFitHeight()
  {
    return fitHeight;
  }

  /**
   * Sets the horizontal print resolution
   *
   * @param hpw the print resolution
   */
  public void setHorizontalPrintResolution(int hpw)
  {
    horizontalPrintResolution = hpw;
  }

  /**
   * Accessor for the horizontal print resolution
   *
   * @return the horizontal print resolution
   */
  public int getHorizontalPrintResolution()
  {
    return horizontalPrintResolution;
  }

  /**
   * Sets the vertical print reslution
   *
   * @param vpw the vertical print resolution
   */
  public void setVerticalPrintResolution(int vpw)
  {
    verticalPrintResolution = vpw;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -