Class XlsWorkbook
- Namespace
- Spire.Xls.Core.Spreadsheet
- Assembly
- Spire.XLS.dll
public class XlsWorkbook : XlsObject, IDisposable, IWorkbook, IExcelApplication
- Inheritance
-
XlsWorkbook
- Implements
- Inherited Members
Fields
DEF_BAD_SHEET_NAME
public const string DEF_BAD_SHEET_NAME = "#REF"
Field Value
DEF_COMENT_PARSE_COLOR
public static readonly Color DEF_COMENT_PARSE_COLOR
Field Value
DEF_FIRST_USER_COLOR
public const int DEF_FIRST_USER_COLOR = 8
Field Value
Properties
ActiveSheet
Returns an object that represents the active sheet (the sheet on top) in the active workbook or in the specified window or workbook. Returns Nothing if no sheet is active. Read-only.
public IWorksheet ActiveSheet { get; }
Property Value
ActiveSheetIndex
Gets / sets index of the active sheet.
public int ActiveSheetIndex { get; set; }
Property Value
AddInFunctions
Returns collection of all workbook's add-in functions. Read-only.
public IAddInFunctions AddInFunctions { get; }
Property Value
Allow3DRangesInDataValidation
Indicates whether to allow usage of 3D ranges in DataValidation list property (MS Excel doesn't allow).
public bool Allow3DRangesInDataValidation { get; set; }
Property Value
ArgumentsSeparator
Formula arguments separator.
public string ArgumentsSeparator { get; }
Property Value
Author
Returns or sets the author of the comment. Read-only String.
public string Author { get; set; }
Property Value
BuiltInDocumentProperties
Returns collection that represents all the built-in document properties
for the specified workbook. Read-only.
//Create workbookWorkbook workbook = new Workbook();workbook.LoadFromFile("Sample.xlsx");//Get the built in document propertiesIBuiltInDocumentProperties builtInDocumentProperties = workbook.DocumentProperties;
public IBuiltInDocumentProperties BuiltInDocumentProperties { get; }
Property Value
Charts
Collection of the chart objects.
public ICharts Charts { get; }
Property Value
Chartsheets
public List<ChartSheet> Chartsheets { get; }
Property Value
CodeName
Name which is used by macros to access the workbook items.
public string CodeName { get; set; }
Property Value
CurrentHeaderId
public int CurrentHeaderId { get; set; }
Property Value
CurrentObjectId
public int CurrentObjectId { get; set; }
Property Value
CurrentShapeId
public int CurrentShapeId { get; set; }
Property Value
CustomDocumentProperties
Returns collection that represents all the custom document properties
for the specified workbook. Read-only.
//Create workbookWorkbook workbook = new Workbook();workbook.LoadFromFile("Sample.xlsx");//Get the document propertiesICustomDocumentProperties documentProperties = workbook.CustomDocumentProperties;
public ICustomDocumentProperties CustomDocumentProperties { get; }
Property Value
DataConns
public DataConnections DataConns { get; }
Property Value
Date1904
True if the workbook uses the 1904 date system. Read / write Boolean.
public bool Date1904 { get; set; }
Property Value
DefaultXFIndex
public int DefaultXFIndex { get; set; }
Property Value
DetectDateTimeInValue
Indicates whether library should try to detect string value passed to Value (and Value2) property as DateTime. Setting this property to false can increase performance greatly for such operations especially on Framework 1.0 and 1.1. Default value is true.
public bool DetectDateTimeInValue { get; set; }
Property Value
DisableMacrosStart
This Property allows users to disable load of macros from document. Excel on file open will simply skip macros and will work as if document does not contain them. This options works only when file contains macros (HasMacros property is True).
public bool DisableMacrosStart { get; set; }
Property Value
DisplayWorkbookTabs
Indicates whether tabs are visible.
public bool DisplayWorkbookTabs { get; set; }
Property Value
DisplayedTab
Index of tab which will be displayed on document open.
public int DisplayedTab { get; set; }
Property Value
ExternalLinks
public ExternalLinkCollection ExternalLinks { get; }
Property Value
FirstCharSize
public int FirstCharSize { get; set; }
Property Value
FullFileName
public string FullFileName { get; }
Property Value
HasDuplicatedNames
public bool HasDuplicatedNames { get; set; }
Property Value
HasMacros
True indicate that opened workbook contains VBA macros.
public bool HasMacros { get; }
Property Value
InnerAddInFunctions
public XlsAddInFunctionsCollection InnerAddInFunctions { get; }
Property Value
InnerFonts
public XlsFontsCollection InnerFonts { get; }
Property Value
InnerPalette
public List<Color> InnerPalette { get; }
Property Value
InnerWorksheets
protected XlsWorksheetsCollection InnerWorksheets { get; }
Property Value
IsCellProtection
True if cell is protected.
public bool IsCellProtection { get; }
Property Value
IsDisplayPrecision
True if cell is protected.
public bool IsDisplayPrecision { get; set; }
Property Value
IsHScrollBarVisible
Gets or sets a value indicating whether to display horizontal scroll bar.
//Create workbookWorkbook workbook = new Workbook();//Hide horizontal scroll barworkbook.IsHScrollBarVisible = false;//Save to fileworkbook.SaveToFile("IsHScrollBarVisible.xlsx");
public bool IsHScrollBarVisible { get; set; }
Property Value
IsLoaded
public bool IsLoaded { get; }
Property Value
IsRightToLeft
Indicates whether worksheet is displayed right to left.
public bool IsRightToLeft { get; set; }
Property Value
IsVScrollBarVisible
Gets or sets a value indicating whether to display vertical scroll bar.
//Create workbookWorkbook workbook = new Workbook();//Hide vertical scroll barworkbook.IsVScrollBarVisible = false;//Save to fileworkbook.SaveToFile("IsVScrollBarVisible.xlsx");
public bool IsVScrollBarVisible { get; set; }
Property Value
IsWindowProtection
True if window is protected.
public bool IsWindowProtection { get; }
Property Value
Loading
public bool Loading { get; }
Property Value
MaxColumnCount
Returns maximum column count for each worksheet in this workbook. Read-only.
public int MaxColumnCount { get; }
Property Value
MaxDigitWidth
public double MaxDigitWidth { get; }
Property Value
MaxIndent
public int MaxIndent { get; }
Property Value
MaxRowCount
Returns maximum row count for each worksheet in this workbook. Read-only.
public int MaxRowCount { get; }
Property Value
MaxXFCount
public int MaxXFCount { get; }
Property Value
Names
For an ReservedHandle object, returns a Names collection that represents
all the names in the active workbook. For a Workbook object, returns
a Names collection that represents all the names in the specified
workbook (including all worksheet-specific names).
//Create workbookWorkbook workbook = new Workbook();workbook.LoadFromFile("Sample.xlsx");//Get namesINameRanges names = workbook.NameRanges;
public INameRanges Names { get; }
Property Value
ObjectCount
public int ObjectCount { get; }
Property Value
Objects
protected XlsWorkbookObjectsCollection Objects { get; }
Property Value
OleSize
public IXLSRange OleSize { get; set; }
Property Value
Palette
Get Palette of colors which an Excel document can have. Here is a table of color indexes to places in the color tool box provided by Excel application:
| | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ---+---------------------------------------- |1 | 00 | 51 | 50 | 49 | 47 | 10 | 53 | 54 | |2 | 08 | 45 | 11 | 09 | 13 | 04 | 46 | 15 | |3 | 02 | 44 | 42 | 48 | 41 | 40 | 12 | 55 | |4 | 06 | 43 | 05 | 03 | 07 | 32 | 52 | 14 | |5 | 37 | 39 | 35 | 34 | 33 | 36 | 38 | 01 | ---+---------------------------------------- |6 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | |7 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
//Create worksheetWorkbook workbook = new Workbook();Worksheet worksheet = workbook.Worksheets[0];//Get colorsSystem.Drawing.Color[] colors = workbook.Colors;//Get colorSystem.Drawing.Color color = colors[2];//Set colorworksheet["B2"].Style.Color = color;//Save to fileworkbook.SaveToFile("CellFormats.xlsx");
public Color[] Palette { get; }
Property Value
- Color[]
PasswordToOpen
Gets / sets password to encrypt document.
public string PasswordToOpen { get; set; }
Property Value
ReadOnly
True if the workbook has been opened as Read-only. Read-only Boolean.
public bool ReadOnly { get; }
Property Value
ReadOnlyRecommended
True to display a message when the file is opened, recommending that the file be opened as read-only.
public bool ReadOnlyRecommended { get; set; }
Property Value
RowSeparator
Gets / sets row separator for array parsing.
public string RowSeparator { get; }
Property Value
Saved
True if no changes have been made to the specified workbook since it was last saved. Read/write Boolean.
public bool Saved { get; set; }
Property Value
Saving
public bool Saving { get; }
Property Value
SecondCharSize
public int SecondCharSize { get; set; }
Property Value
StandardFont
Returns or sets the name of the standard font. Read/write String.
//Create worksheetWorkbook workbook = new Workbook();Worksheet worksheet = workbook.Worksheets[0];//Set textworksheet["B2"].Text = "Text";//Set standard fontworkbook.DefaultFontName = "Arial";//Set standard font sizeworkbook.DefaultFontSize = 18;//Save to fileworkbook.SaveToFile("CellFormats.xlsx");
public string StandardFont { get; set; }
Property Value
StandardFontSize
Returns or sets the standard font size, in points. Read/write.
//Create worksheetWorkbook workbook = new Workbook();Worksheet worksheet = workbook.Worksheets[0];//Set textworksheet["B2"].Text = "Text";//Set standard fontworkbook.DefaultFontName = "Arial";//Set standard font sizeworkbook.DefaultFontSize = 18;//Save to fileworkbook.SaveToFile("CellFormats.xlsx");
public double StandardFontSize { get; set; }
Property Value
StandardRowHeight
public double StandardRowHeight { get; set; }
Property Value
StandardRowHeightInPixels
public int StandardRowHeightInPixels { get; set; }
Property Value
Styles
Returns a Styles collection that represents all the styles
in the specified workbook. Read-only.
//Create worksheetWorkbook workbook = new Workbook();Worksheet worksheet = workbook.Worksheets[0];//Set stylesIStyles styles = workbook.Styles;
public IStyles Styles { get; }
Property Value
TabSheets
Returns collection of tab sheets. Read-only.
public ITabSheets TabSheets { get; }
Property Value
ThrowOnUnknownNames
Indicates whether exception should be thrown when unknown name was found in a formula.
public bool ThrowOnUnknownNames { get; set; }
Property Value
Version
Gets / sets excel version.
public ExcelVersion Version { get; set; }
Property Value
Worksheets
Returns a Sheets collection that represents all the worksheets in the specified workbook. Read-only Sheets object.
public IWorksheets Worksheets { get; }
Property Value
Methods
Activate()
Activates the first window associated with the workbook.
[Obsolete("the method is not implemented")]
public void Activate()
AddFont(IFont)
public IFont AddFont(IFont fontToAdd)
Parameters
fontToAdd
IFont
Returns
Clone()
[Obsolete("the method is not implemented")]
public IWorkbook Clone()
Returns
Close()
Closes the object without saving.
public void Close()
Close(bool)
public void Close(bool saveChanges)
Parameters
saveChanges
bool
Close(bool, string)
public void Close(bool SaveChanges, string Filename)
Parameters
Close(string)
Closes the object and saves changes into specified file.
public void Close(string Filename)
Parameters
Filename
stringFile name in which workbook will be saved if SaveChanges is true.
ColorDistance(Color, Color)
protected double ColorDistance(Color color1, Color color2)
Parameters
Returns
ContainsFont(XlsFont)
public bool ContainsFont(XlsFont font)
Parameters
font
XlsFont
Returns
ConvertUnits(double, MeasureUnits, MeasureUnits)
public double ConvertUnits(double value, MeasureUnits from, MeasureUnits to)
Parameters
value
doublefrom
MeasureUnitsto
MeasureUnits
Returns
CopyToClipboard()
Copies workbook to the clipboard.
[Obsolete("the method is not implemented")]
public void CopyToClipboard()
CopyToClipboard(XlsWorksheet)
protected void CopyToClipboard(XlsWorksheet sheet)
Parameters
sheet
XlsWorksheet
CreateFont()
public IFont CreateFont()
Returns
CreateFont(IFont)
public IFont CreateFont(IFont baseFont)
Parameters
baseFont
IFont
Returns
CreateFont(IFont, bool)
public IFont CreateFont(IFont baseFont, bool bAddToCollection)
Parameters
Returns
CreateFont(string, float, int)
public IFont CreateFont(string familyName, float size, int fontStyles)
Parameters
Returns
CreateTemplateMarkersProcessor()
public IMarkersDesigner CreateTemplateMarkersProcessor()
Returns
DecodeName(string)
public string DecodeName(string name)
Parameters
name
string
Returns
Dispose()
Dispose object and free resources.
public override void Dispose()
EncodeName(string)
public string EncodeName(string strName)
Parameters
strName
string
Returns
FileWidthToPixels(double)
public double FileWidthToPixels(double fileWidth)
Parameters
fileWidth
double
Returns
FindAll(bool)
public CellRange[] FindAll(bool findValue)
Parameters
findValue
bool
Returns
FindAll(DateTime)
public CellRange[] FindAll(DateTime findValue)
Parameters
findValue
DateTime
Returns
FindAll(double, FindType)
public CellRange[] FindAll(double findValue, FindType flags)
Parameters
Returns
FindAll(string, FindType)
public CellRange[] FindAll(string findValue, FindType flags)
Parameters
Returns
FindAll(TimeSpan)
public CellRange[] FindAll(TimeSpan findValue)
Parameters
findValue
TimeSpan
Returns
FindOne(bool)
public IXLSRange FindOne(bool findValue)
Parameters
findValue
bool
Returns
FindOne(DateTime)
public IXLSRange FindOne(DateTime findValue)
Parameters
findValue
DateTime
Returns
FindOne(double, FindType)
public IXLSRange FindOne(double findValue, FindType flags)
Parameters
Returns
FindOne(string, FindType)
public IXLSRange FindOne(string findValue, FindType flags)
Parameters
Returns
FindOne(TimeSpan)
public IXLSRange FindOne(TimeSpan findValue)
Parameters
findValue
TimeSpan
Returns
GetBookIndex(int)
public int GetBookIndex(int referenceIndex)
Parameters
referenceIndex
int
Returns
GetMaxDigitWidth()
public double GetMaxDigitWidth()
Returns
GetNearestColor(Color)
public ExcelColors GetNearestColor(Color color)
Parameters
color
Color
Returns
GetNearestColor(Color, int)
public ExcelColors GetNearestColor(Color color, int iStartIndex)
Parameters
Returns
GetNearestColor(int, int, int)
public ExcelColors GetNearestColor(int r, int g, int b)
Parameters
Returns
GetPaletteColor(ExcelColors)
public Color GetPaletteColor(ExcelColors color)
Parameters
color
ExcelColors
Returns
InitializeCollections()
protected void InitializeCollections()
IsExternalReference(int)
public bool IsExternalReference(int reference)
Parameters
reference
int
Returns
IsFormatted(int)
public bool IsFormatted(int xfIndex)
Parameters
xfIndex
int
Returns
Paste()
protected void Paste()
PixelsToWidth(double)
public double PixelsToWidth(double pixels)
Parameters
pixels
double
Returns
Protect(bool, bool)
public void Protect(bool bIsProtectWindow, bool bIsProtectContent)
Parameters
Protect(bool, bool, string)
public void Protect(bool bIsProtectWindow, bool bIsProtectContent, string password)
Parameters
Replace(string, DataColumn, bool)
public void Replace(string oldValue, DataColumn newValues, bool isFieldNamesShown)
Parameters
oldValue
stringnewValues
DataColumnisFieldNamesShown
bool
Replace(string, DataTable, bool)
public void Replace(string oldValue, DataTable newValues, bool isFieldNamesShown)
Parameters
Replace(string, DateTime)
public void Replace(string oldValue, DateTime newValue)
Parameters
Replace(string, double)
public void Replace(string oldValue, double newValue)
Parameters
Replace(string, double[], bool)
public void Replace(string oldValue, double[] newValues, bool isVertical)
Parameters
Replace(string, int[], bool)
public void Replace(string oldValue, int[] newValues, bool isVertical)
Parameters
Replace(string, string)
public void Replace(string oldValue, string newValue)
Parameters
Replace(string, string[], bool)
public void Replace(string oldValue, string[] newValues, bool isVertical)
Parameters
ResetPalette()
Recover palette to default values.
//Create worksheetWorkbook workbook = new Workbook();Worksheet worksheet = workbook.Worksheets[0];//Get colorsSystem.Drawing.Color[] colors = workbook.Colors;//Check colorConsole.WriteLine(colors[2].Name);//Set colorcolors[2] = System.Drawing.Color.Yellow;//Reset paletteworkbook.ResetPalette();//Check colorConsole.WriteLine(workbook.Colors[2].Name);//Save to fileworkbook.SaveToFile("CellFormats.xlsx");
public void ResetPalette()
Save()
Saves changes to the specified workbook.
//Load workbookWorkbook workbook = new Workbook();workbook.LoadFromFile("Sample.xlsx");//Save to fileworkbook.Save();
public void Save()
SaveAs(Stream)
public void SaveAs(Stream stream)
Parameters
stream
Stream
SaveAs(Stream, ExcelSaveType)
public void SaveAs(Stream stream, ExcelSaveType saveType)
Parameters
stream
StreamsaveType
ExcelSaveType
SaveAs(Stream, ExcelSaveType, ExcelVersion)
public void SaveAs(Stream stream, ExcelSaveType saveType, ExcelVersion version)
Parameters
stream
StreamsaveType
ExcelSaveTypeversion
ExcelVersion
SaveAs(Stream, string)
public void SaveAs(Stream stream, string separator)
Parameters
SaveAs(string)
public void SaveAs(string FileName)
Parameters
FileName
string
SaveAs(string, ExcelSaveType)
public void SaveAs(string fileName, ExcelSaveType saveType)
Parameters
fileName
stringsaveType
ExcelSaveType
SaveAs(string, ExcelSaveType, ExcelVersion)
public void SaveAs(string fileName, ExcelSaveType saveType, ExcelVersion version)
Parameters
fileName
stringsaveType
ExcelSaveTypeversion
ExcelVersion
SaveAs(string, string)
public void SaveAs(string fileName, string separator)
Parameters
SaveAs(string, string, bool)
public void SaveAs(string fileName, string separator, bool addQuotationsForStringValue)
Parameters
SaveAsEmfStream(int, Stream, int, int, int, int)
public void SaveAsEmfStream(int sheetIndex, Stream EmfStream, int firstRow, int firstColumn, int lastRow, int lastColumn)
Parameters
SaveAsHtml(string, HTMLOptions)
[Obsolete("the method is not implemented")]
public void SaveAsHtml(string fileName, HTMLOptions saveOption)
Parameters
fileName
stringsaveOption
HTMLOptions
SaveAsImageOrXps(Stream, FileFormat)
public void SaveAsImageOrXps(Stream stream, FileFormat fileFormat)
Parameters
stream
StreamfileFormat
FileFormat
SaveAsImageOrXps(string, FileFormat)
public void SaveAsImageOrXps(string fileName, FileFormat fileFormat)
Parameters
fileName
stringfileFormat
FileFormat
SaveAsImages(int, int, int, int, int, float, float)
public Stream SaveAsImages(int sheetIndex, int firstRow, int firstColumn, int lastRow, int lastColumn, float dpiX, float dpiY)
Parameters
Returns
SaveAsImages(int, float, float)
public Stream SaveAsImages(int sheetIndex, float dpiX, float dpiY)
Parameters
Returns
SaveAsImages(float, float)
public Stream[] SaveAsImages(float dpiX, float dpiY)
Parameters
Returns
- Stream[]
SaveAsSkImages(int, float, float)
public SKBitmap SaveAsSkImages(int sheetIndex, float dpiX, float dpiY)
Parameters
Returns
- SKBitmap
SaveChartAsImage(ChartSheet, ConverterSetting)
public Stream SaveChartAsImage(ChartSheet chartsheet, ConverterSetting imageOrPrintOptions)
Parameters
chartsheet
ChartSheetimageOrPrintOptions
ConverterSetting
Returns
SaveChartAsImage(Worksheet, ConverterSetting)
public Stream[] SaveChartAsImage(Worksheet worksheet, ConverterSetting imageOrPrintOptions)
Parameters
worksheet
WorksheetimageOrPrintOptions
ConverterSetting
Returns
- Stream[]
SaveChartAsImage(Worksheet, int, ConverterSetting)
public Stream SaveChartAsImage(Worksheet worksheet, int chartIndex, ConverterSetting imageOrPrintOptions)
Parameters
worksheet
WorksheetchartIndex
intimageOrPrintOptions
ConverterSetting
Returns
SaveToPdf(Stream)
public void SaveToPdf(Stream stream)
Parameters
stream
Stream
SaveToPdf(string)
public void SaveToPdf(string fileName)
Parameters
fileName
string
SaveToXlsm(Stream)
public void SaveToXlsm(Stream stream)
Parameters
stream
Stream
SaveToXlsm(string)
public void SaveToXlsm(string fileName)
Parameters
fileName
string
SetActiveWorksheet(XlsWorksheetBase)
public void SetActiveWorksheet(XlsWorksheetBase sheet)
Parameters
sheet
XlsWorksheetBase
SetChanged()
public void SetChanged()
SetColorOrGetNearest(Color)
public ExcelColors SetColorOrGetNearest(Color color)
Parameters
color
Color
Returns
SetColorOrGetNearest(int, int, int)
public ExcelColors SetColorOrGetNearest(int r, int g, int b)
Parameters
Returns
SetMaxDigitWidth(int)
public void SetMaxDigitWidth(int w)
Parameters
w
int
SetPaletteColor(int, Color)
public void SetPaletteColor(int index, Color color)
Parameters
SetSeparators(char, char)
public void SetSeparators(char argumentsSeparator, char arrayRowsSeparator)
Parameters
SetWriteProtectionPassword(string)
public void SetWriteProtectionPassword(string password)
Parameters
password
string
SplitPageInfo(ConverterSetting)
public List<Dictionary<int, PageColRow>> SplitPageInfo(ConverterSetting converterSetting)
Parameters
converterSetting
ConverterSetting
Returns
Unprotect()
Unprotects workbook.
public void Unprotect()
Unprotect(string)
public void Unprotect(string password)
Parameters
password
string
WidthToFileWidth(double)
public double WidthToFileWidth(double width)
Parameters
width
double