📄 workbooksettings.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 java.io.File;
import java.util.HashMap;
import java.util.Locale;
import common.Logger;
import jxl.biff.CountryCode;
import jxl.biff.formula.FunctionNames;
/**
* This is a bean which client applications may use to set various advanced
* workbook properties. Use of this bean is not mandatory, and its absence
* will merely result in workbooks being read/written using the default
* settings
*/
public final class WorkbookSettings
{
/**
* The logger
*/
private static Logger logger = Logger.getLogger(WorkbookSettings.class);
/**
* The amount of memory allocated to store the workbook data when
* reading a worksheet. For processeses reading many small workbooks inside
* a WAS it might be necessary to reduce the default size
*/
private int initialFileSize;
/**
* The amount of memory allocated to the array containing the workbook
* data when its current amount is exhausted.
*/
private int arrayGrowSize;
/**
* Flag to indicate whether the drawing feature is enabled or not
* Drawings deactivated using -Djxl.nodrawings=true on the JVM command line
* Activated by default or by using -Djxl.nodrawings=false on the JVM command
* line
*/
private boolean drawingsDisabled;
/**
* Flag to indicate whether the name feature is enabled or not
* Names deactivated using -Djxl.nonames=true on the JVM command line
* Activated by default or by using -Djxl.nonames=false on the JVM command
* line
*/
private boolean namesDisabled;
/**
* Flag to indicate whether formula cell references should be adjusted
* following row/column insertion/deletion
*/
private boolean formulaReferenceAdjustDisabled;
/**
* Flag to indicate whether the system hint garbage collection
* is enabled or not.
* As a rule of thumb, it is desirable to enable garbage collection
* when reading large spreadsheets from a batch process or from the
* command line, but better to deactivate the feature when reading
* large spreadsheets within a WAS, as the calls to System.gc() not
* only garbage collect the junk in JExcelApi, but also in the
* webservers JVM and can cause significant slowdown
* GC deactivated using -Djxl.nogc=true on the JVM command line
* Activated by default or by using -Djxl.nogc=false on the JVM command line
*/
private boolean gcDisabled;
/**
* Flag to indicate whether the rationalization of cell formats is
* disabled or not.
* Rationalization is enabled by default, but may be disabled for
* performance reasons. It can be deactivated using -Djxl.norat=true on
* the JVM command line
*/
private boolean rationalizationDisabled;
/**
* Flag to indicate whether or not the merged cell checking has been
* disabled
*/
private boolean mergedCellCheckingDisabled;
/**
* Flag to indicate whether the copying of additional property sets
* are disabled
*/
private boolean propertySetsDisabled;
/**
* Flag to indicate that cell validation criteria are ignored
*/
private boolean cellValidationDisabled;
/**
* Flag to indicate whether or not to ignore blank cells when processing
* sheets. Cells which are identified as blank can still have associated
* cell formats which the processing program may still need to read
*/
private boolean ignoreBlankCells;
/**
* Flag to indicate whether auto filtering should be read/copied
*/
private boolean autoFilterDisabled;
/**
* Flag to indicate whether a temporary file should be used when
* writing out the workbook
*/
private boolean useTemporaryFileDuringWrite;
/**
* The directory for used for the temporary file during write. If this
* is NULL, the default system directory is used
*/
private File temporaryFileDuringWriteDirectory;
/**
* The locale. Normally this is the same as the system locale, but there
* may be cases (eg. where you are uploading many spreadsheets from foreign
* sources) where you may want to specify the locale on an individual
* worksheet basis
* The locale may also be specified on the command line using the lang and
* country System properties eg. -Djxl.lang=en -Djxl.country=UK for UK
* English
*/
private Locale locale;
/**
* The locale specific function names for this workbook
*/
private FunctionNames functionNames;
/**
* The character encoding used for reading non-unicode strings. This can
* be different from the default platform encoding if processing spreadsheets
* from abroad. This may also be set using the system property jxl.encoding
*/
private String encoding;
/**
* The character set used by the readable spreadsheeet
*/
private int characterSet;
/**
* The display language used by Excel (ISO 3166 mnemonic)
*/
private String excelDisplayLanguage;
/**
* The regional settings used by Excel (ISO 3166 mnemonic)
*/
private String excelRegionalSettings;
/**
* A hash map of function names keyed on locale
*/
private HashMap localeFunctionNames;
// **
// The default values
// **
private static final int DEFAULT_INITIAL_FILE_SIZE = 5 * 1024 * 1024;
// 5 megabytes
private static final int DEFAULT_ARRAY_GROW_SIZE = 1024 * 1024; // 1 megabyte
/**
* Default constructor
*/
public WorkbookSettings()
{
initialFileSize = DEFAULT_INITIAL_FILE_SIZE;
arrayGrowSize = DEFAULT_ARRAY_GROW_SIZE;
localeFunctionNames = new HashMap();
excelDisplayLanguage = CountryCode.USA.getCode();
excelRegionalSettings = CountryCode.UK.getCode();
// Initialize other properties from the system properties
try
{
boolean suppressWarnings = Boolean.getBoolean("jxl.nowarnings");
setSuppressWarnings(suppressWarnings);
drawingsDisabled = Boolean.getBoolean("jxl.nodrawings");
namesDisabled = Boolean.getBoolean("jxl.nonames");
gcDisabled = Boolean.getBoolean("jxl.nogc");
rationalizationDisabled = Boolean.getBoolean("jxl.norat");
mergedCellCheckingDisabled =
Boolean.getBoolean("jxl.nomergedcellchecks");
formulaReferenceAdjustDisabled =
Boolean.getBoolean("jxl.noformulaadjust");
propertySetsDisabled = Boolean.getBoolean("jxl.nopropertysets");
ignoreBlankCells = Boolean.getBoolean("jxl.ignoreblanks");
cellValidationDisabled = Boolean.getBoolean("jxl.nocellvalidation");
autoFilterDisabled = !Boolean.getBoolean("jxl.autofilter");
// autofilter currently disabled by default
useTemporaryFileDuringWrite =
Boolean.getBoolean("jxl.usetemporaryfileduringwrite");
String tempdir =
System.getProperty("jxl.temporaryfileduringwritedirectory");
if (tempdir != null)
{
temporaryFileDuringWriteDirectory = new File(tempdir);
}
encoding = System.getProperty("file.encoding");
}
catch (SecurityException e)
{
logger.warn("Error accessing system properties.", e);
}
// Initialize the locale to the system locale
try
{
if (System.getProperty("jxl.lang") == null ||
System.getProperty("jxl.country") == null)
{
locale = Locale.getDefault();
}
else
{
locale = new Locale(System.getProperty("jxl.lang"),
System.getProperty("jxl.country"));
}
if (System.getProperty("jxl.encoding") != null)
{
encoding = System.getProperty("jxl.encoding");
}
}
catch (SecurityException e)
{
logger.warn("Error accessing system properties.", e);
locale = Locale.getDefault();
}
}
/**
* Sets the amount of memory by which to increase the amount of
* memory allocated to storing the workbook data.
* For processeses reading many small workbooks
* inside a WAS it might be necessary to reduce the default size
* Default value is 1 megabyte
*
* @param sz the file size in bytes
*/
public void setArrayGrowSize(int sz)
{
arrayGrowSize = sz;
}
/**
* Accessor for the array grow size property
*
* @return the array grow size
*/
public int getArrayGrowSize()
{
return arrayGrowSize;
}
/**
* Sets the initial amount of memory allocated to store the workbook data
* when reading a worksheet. For processeses reading many small workbooks
* inside a WAS it might be necessary to reduce the default size
* Default value is 5 megabytes
*
* @param sz the file size in bytes
*/
public void setInitialFileSize(int sz)
{
initialFileSize = sz;
}
/**
* Accessor for the initial file size property
*
* @return the initial file size
*/
public int getInitialFileSize()
{
return initialFileSize;
}
/**
* Gets the drawings disabled flag
*
* @return TRUE if drawings are disabled, FALSE otherwise
*/
public boolean getDrawingsDisabled()
{
return drawingsDisabled;
}
/**
* Accessor for the disabling of garbage collection
*
* @return FALSE if JExcelApi hints for garbage collection, TRUE otherwise
*/
public boolean getGCDisabled()
{
return gcDisabled;
}
/**
* Accessor for the disabling of interpretation of named ranges
*
* @return FALSE if named cells are interpreted, TRUE otherwise
*/
public boolean getNamesDisabled()
{
return namesDisabled;
}
/**
* Disables the handling of names
*
* @param b TRUE to disable the names feature, FALSE otherwise
*/
public void setNamesDisabled(boolean b)
{
namesDisabled = b;
}
/**
* Disables the handling of drawings
*
* @param b TRUE to disable the names feature, FALSE otherwise
*/
public void setDrawingsDisabled(boolean b)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -