Table of Contents

Class Workbook

Namespace
Spire.Xls
Assembly
Spire.XLS.dll
public sealed class Workbook : IDisposable
Inheritance
Workbook
Implements
Inherited Members

Constructors

Workbook()

Create a new instance of workbook.

public Workbook()

Workbook(string, string)

Workbook use for Online

public Workbook(string sFrom = null, string sPassword = null)

Parameters

sFrom string
sPassword string

Properties

AIHelper

helper for call AI.

public static ExcelAI AIHelper { get; }

Property Value

ExcelAI

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 Worksheet ActiveSheet { get; }

Property Value

Worksheet

ActiveSheetIndex

Gets or sets index of the active worksheet.

public int ActiveSheetIndex { get; set; }

Property Value

int

AddInFunctions

Returns collection of add-in functions.

public AddInFunctionsCollection AddInFunctions { get; }

Property Value

AddInFunctionsCollection

Allow3DRangesInDataValidation

public bool Allow3DRangesInDataValidation { get; set; }

Property Value

bool

CalculationMode

Get or set calculation mode.

public ExcelCalculationMode CalculationMode { get; set; }

Property Value

ExcelCalculationMode

Charts

Returns a Sheets collection that represents all the chart sheets in the specified workbook. Read-only.

public ChartsCollection Charts { get; }

Property Value

ChartsCollection

Chartsheets

public List<ChartSheet> Chartsheets { get; }

Property Value

List<ChartSheet>

CheckComptiliblity

public bool CheckComptiliblity { get; set; }

Property Value

bool

CodeName

Name which used by macros to access to workbook items.

public string CodeName { get; set; }

Property Value

string

Colors

Returns colors in the palette for the workbook. The palette has 56 entries, each represented by an RGB value. Read/write Object. The following code illustrates how to access the default colors of excel color palette:

//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//Get colors
System.Drawing.Color[] colors = workbook.Colors;

//Get color
System.Drawing.Color color = colors[2];

//Set color
worksheet["B2"].Style.Color = color;

//Save to file
workbook.SaveToFile("CellFormats.xlsx");
public Color[] Colors { get; }

Property Value

Color[]

ConverterSetting

public ConverterSetting ConverterSetting { get; set; }

Property Value

ConverterSetting

CultureInfo

public CultureInfo CultureInfo { get; set; }

Property Value

CultureInfo

CustomDocumentProperties

Returns collection that represents all the custom document properties for the specified workbook. Read-only. The following code snippet illustrates how to get the custom document properties:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Get the document properties
ICustomDocumentProperties documentProperties = workbook.CustomDocumentProperties;
public ICustomDocumentProperties CustomDocumentProperties { get; }

Property Value

ICustomDocumentProperties

CustomFontFileDirectory

Sets the custom directory of font files.

public string[] CustomFontFileDirectory { get; set; }

Property Value

string[]

CustomFontFilePaths

Returns or sets the custom path of font files.

public string[] CustomFontFilePaths { get; set; }

Property Value

string[]

CustomTableStyles

public Dictionary<string, PivotTableStyle> CustomTableStyles { get; }

Property Value

Dictionary<string, PivotTableStyle>

DataConns

public DataConnections DataConns { get; }

Property Value

DataConnections

DataSorter

Gets Data sorter to sort the data..

public DataSorter DataSorter { get; }

Property Value

DataSorter

Date1904

True if the workbook uses the 1904 date system. Read/write Boolean.

public bool Date1904 { get; set; }

Property Value

bool

DefaultFontName

Returns or sets the name of the default font. The following code illustrates how to set the standard font for the workbook:

//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//Set text
worksheet["B2"].Text = "Text";

//Set standard font
workbook.DefaultFontName = "Arial";

//Set standard font size
workbook.DefaultFontSize = 18;

//Save to file
workbook.SaveToFile("CellFormats.xlsx");
public string DefaultFontName { get; set; }

Property Value

string

DefaultFontSize

Returns or sets the default font size. The following code illustrates how to set the standard font size for the workbook:

//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//Set text
worksheet["B2"].Text = "Text";

//Set standard font
workbook.DefaultFontName = "Arial";

//Set standard font size
workbook.DefaultFontSize = 18;

//Save to file
workbook.SaveToFile("CellFormats.xlsx");
public double DefaultFontSize { get; set; }

Property Value

double

DisableMacrosStart

Allows users to disable load of macros from document.

public bool DisableMacrosStart { get; set; }

Property Value

bool

DocumentProperties

Returns a BuiltInDocumentProperties collection that represents all the built-in document properties for the specified workbook. Read-only. The following code snippet illustrates how to get the built in document properties:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Get the built in document properties
IBuiltInDocumentProperties builtInDocumentProperties = workbook.DocumentProperties;
public BuiltInDocumentProperties DocumentProperties { get; }

Property Value

BuiltInDocumentProperties
public ExternalLinkCollection ExternalLinks { get; }

Property Value

ExternalLinkCollection

FileName

Gets file name.

public string FileName { get; }

Property Value

string

HasMacros

Indicates whether contains VBA macros.

public bool HasMacros { get; set; }

Property Value

bool

HasTrackedChanges

Indicates whether the workbook has any tracked changes

public bool HasTrackedChanges { get; }

Property Value

bool

IsCellProtection

Indicates whether cells are protected.

public bool IsCellProtection { get; }

Property Value

bool

IsDigitallySigned

Indicates whether this spreadsheet is digitally signed.

public bool IsDigitallySigned { get; }

Property Value

bool

IsHScrollBarVisible

Returns or sets whether show horizontal scroll bar. This sample shows how to hide horizontal scroll bar:

//Create workbook
Workbook workbook = new Workbook();

//Hide horizontal scroll bar
workbook.IsHScrollBarVisible = false;

//Save to file
workbook.SaveToFile("IsHScrollBarVisible.xlsx");
public bool IsHScrollBarVisible { get; set; }

Property Value

bool

IsHideWindow

Hide window

public bool IsHideWindow { get; set; }

Property Value

bool

IsRightToLeft

Indicates whether worksheet is displayed right to left.

public bool IsRightToLeft { get; set; }

Property Value

bool

IsSaved

Indicates whether workbook changes have been saved.

public bool IsSaved { get; set; }

Property Value

bool

IsVScrollBarVisible

Returns or sets whether show vertical scroll bar. This sample shows how to hide vertical scroll bar:

//Create workbook
Workbook workbook = new Workbook();

//Hide vertical scroll bar
workbook.IsVScrollBarVisible = false;

//Save to file
workbook.SaveToFile("IsVScrollBarVisible.xlsx");
public bool IsVScrollBarVisible { get; set; }

Property Value

bool

IsWindowProtection

Indicates window is protected.

public bool IsWindowProtection { get; }

Property Value

bool

MarkerDesigner

public MarkerDesigner MarkerDesigner { get; }

Property Value

MarkerDesigner

MaxColumnCount

public int MaxColumnCount { get; }

Property Value

int

MaxDigitWidth

public int MaxDigitWidth { get; }

Property Value

int

MaxRowCount

public int MaxRowCount { get; }

Property Value

int

MaxRowsOfSharedFormula

public int MaxRowsOfSharedFormula { get; set; }

Property Value

int

NameRanges

Gets Names collection that represents all the names in the specified workbook. The following code snippet illustrates how to get names:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Get names
INameRanges names = workbook.NameRanges;
public INameRanges NameRanges { get; }

Property Value

INameRanges

OpenPassword

Returns or sets password to encrypt document.

public string OpenPassword { get; set; }

Property Value

string

OptimizeImport

Indicates whether to optimize Import data. This option will take effect only on Import methods that are available with the worksheet WARNING: Setting this property to True can decrease memory significantly, but will increase the performance of data import .

public bool OptimizeImport { get; set; }

Property Value

bool

PivotCaches

Returns pivot caches collection. Read-only. The following code snippet illustrates how to get pivot caches:

//Create worksheet
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");
Worksheet worksheet = workbook.Worksheets[0];

//Gets pivot caches collection
IPivotCaches pivotCaches = workbook.PivotCaches;
public PivotCachesCollection PivotCaches { get; }

Property Value

PivotCachesCollection

ReadOnly

Indicates whether the workbook has been opened as Read-only.

public bool ReadOnly { get; }

Property Value

bool

SelectedTab

Gets or sets tab index of selected.

public int SelectedTab { get; set; }

Property Value

int

SheetTabBarWidth

Returns or sets the width of worksheet tab bar. 1/1000 of window width.

public int SheetTabBarWidth { get; set; }

Property Value

int

ShowTabs

Get or sets a value whether the Workbook tabs are displayed.

public bool ShowTabs { get; set; }

Property Value

bool

Styles

Returns a Styles collection that represents all the styles in the specified workbook. Read-only. The following code snippet illustrates how to get the Styles:

//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//Set styles
IStyles styles = workbook.Styles;
public StylesCollection Styles { get; }

Property Value

StylesCollection

UseStorageMode

User Compound storage mode

public bool UseStorageMode { get; set; }

Property Value

bool

Version

public ExcelVersion Version { get; set; }

Property Value

ExcelVersion

Worksheets

Returns a Sheets collection that represents all the worksheets in the specified workbook. Read-only Sheets object.

public WorksheetsCollection Worksheets { get; }

Property Value

WorksheetsCollection

WriteProtection

Returns options of the workbook write protection.

public WriteProtection WriteProtection { get; }

Property Value

WriteProtection

Methods

AcceptAllTrackedChanges()

Accept all tracked changes in the workbook.

public void AcceptAllTrackedChanges()

AddCustomFont(CustomFontData)

public CustomFontData AddCustomFont(CustomFontData data)

Parameters

data CustomFontData

Returns

CustomFontData

AddDigitalSignature(X509Certificate2, string, DateTime)

Add a DigitalSignature.

public IDigitalSignatures AddDigitalSignature(X509Certificate2 certificate, string comments, DateTime signTime)

Parameters

certificate X509Certificate2

Certificate object that was used to sign

comments string

Signature Comments

signTime DateTime

Sign Time

Returns

IDigitalSignatures

Collection of DigitalSignature

AddPivotTableStyle(PivotTableStyle)

public void AddPivotTableStyle(PivotTableStyle pts)

Parameters

pts PivotTableStyle

CaculateFormulaValue(string)

Computes the string formula

[Obsolete("the method is obsolete, please use CalculateFormulaValue.")]
public object CaculateFormulaValue(string text)

Parameters

text string

Returns

object

CalculateAllValue()

Caculate all formula for the workbook

public void CalculateAllValue()

CalculateFormulaValue(string)

Computes the string formula

public object CalculateFormulaValue(string text)

Parameters

text string

Returns

object

ChangePaletteColor(Color, int)

Changes the palette for the spreadsheet in the specified index. The following code snippet illustrates how to set palette color:

//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//Set palette color
workbook.ChangePaletteColor(System.Drawing.Color.Red , 10);

//Set color
worksheet["B2"].Style.Color = workbook.Colors[10];

//Save to file
workbook.SaveToFile("CellFormats.xlsx");
public void ChangePaletteColor(Color color, int index)

Parameters

color Color

Color structure

index int

Palette index,Value should be from 0 to 55

ClearFontCache()

Clear used fonts in cache.

public void ClearFontCache()

ColumnWidthToPixels(double)

onverts column width in characters into column width in pixels.

public double ColumnWidthToPixels(double columnWidth)

Parameters

columnWidth double

Column width in characters.

Returns

double

Column width in pixels.

ContainsFont(ExcelFont)

Indicates whether the workbook contains specified font.

public bool ContainsFont(ExcelFont font)

Parameters

font ExcelFont

Returns

bool

CopyTheme(Workbook)

Copy the theme from source workbook

public void CopyTheme(Workbook srcWorkbook)

Parameters

srcWorkbook Workbook

source workbook.

CopyThemeColor(Workbook)

Copy the theme color from source workbook

public void CopyThemeColor(Workbook srcWorkbook)

Parameters

srcWorkbook Workbook

source workbook.

CopyToClipboard()

Copies whole workbook to the clipboard.

[Obsolete("the method is not implemented")]
public void CopyToClipboard()

CopyToClipboard(Worksheet)

Copies the selected worksheet to clipboard.

[Obsolete("the method is not implemented")]
public void CopyToClipboard(Worksheet worksheet)

Parameters

worksheet Worksheet

CreateEmptySheet()

Create a new worksheet.

public Worksheet CreateEmptySheet()

Returns

Worksheet

CreateEmptySheet(string)

Create a new worksheet.

public Worksheet CreateEmptySheet(string name)

Parameters

name string

Sheet name.

Returns

Worksheet

CreateEmptySheets(int)

Create workbook with specified number of worksheets.

public void CreateEmptySheets(int sheetCount)

Parameters

sheetCount int

CreateEmptySheets(string[])

Create workbook with specified names of worksheets.

public void CreateEmptySheets(string[] sheetNames)

Parameters

sheetNames string[]

CreateFont()

Creates a font object and add it to the workbook. The following code illustrates how to create IFont object:

//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//Set text
IRichTextString richText = worksheet["B2"].RichText;

//Create font
IFont font = workbook.CreateFont();

//Set color
font.Color = Color.Red;

//Set text
richText.Text = "Sample";

//Set font
richText.SetFont(0, 5, font);

//Save to file
workbook.SaveToFile("CellFormats.xlsx");
public ExcelFont CreateFont()

Returns

ExcelFont

CreatePivotStyle()

public PivotStyle CreatePivotStyle()

Returns

PivotStyle

Dispose()

public void Dispose()

FindAllBool(bool)

Finds the cell with the input bool. This sample shows how to find all cells with specified bool value:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Find cells with specified bool value
CellRange[] result = workbook.FindAllBool(true);
public CellRange[] FindAllBool(bool boolValue)

Parameters

boolValue bool

Bool value to search for

Returns

CellRange[]

Found ranges

FindAllDateTime(DateTime)

Finds the cell with the input datetime. This sample shows how to find all cells with specified DateTime value:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Find cells with specified DateTime value
CellRange[] result = workbook.FindAllDateTime(DateTime.Now);
public CellRange[] FindAllDateTime(DateTime dateTimeValue)

Parameters

dateTimeValue DateTime

Datetime value to search for.

Returns

CellRange[]

Found ranges.

FindAllNumber(double, bool)

Finds the cell with the input double. This sample shows how to find all cells with specified doulbe value:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Find cells with specified double value
CellRange[] result = workbook.FindAllNumber(100.32 , false);
public CellRange[] FindAllNumber(double doubleValue, bool formulaValue)

Parameters

doubleValue double

Double value to search for.

formulaValue bool

Indicates whether includes formula value to search for.

Returns

CellRange[]

Found ranges.

FindAllString(string, bool, bool)

Finds the cell with the input string. This sample shows how to find all cells with specified string value:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Find cells with specified string value
string value = "value";
CellRange[] result = workbook.FindAllString(value , false , false);
public CellRange[] FindAllString(string stringValue, bool formula, bool formulaValue)

Parameters

stringValue string

String value to search for

formula bool

Indicates whether includes formula to search for.

formulaValue bool

Indicates whether includes formula value to search for.

Returns

CellRange[]

Found ranges.

FindAllTimeSpan(TimeSpan)

Finds the cell with the input time span. This sample shows how to find all cells with specified TimeSpan value:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Find cells with specified TimeSpan value
TimeSpan value = new TimeSpan(2, 30, 30);
CellRange[] result = workbook.FindAllTimeSpan(value);
public CellRange[] FindAllTimeSpan(TimeSpan timeSpanValue)

Parameters

timeSpanValue TimeSpan

Returns

CellRange[]

Found ranges.

FindBool(bool)

Finds the cell with the input bool. This sample shows how to find the first cell with specified bool value:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Find cell with specified bool value
IXLSRange result = workbook.FindBool(true);
public CellRange FindBool(bool boolValue)

Parameters

boolValue bool

Bool value to search for.

Returns

CellRange

Found range.

FindDateTime(DateTime)

Finds the cell with the input datetime. This sample shows how to find the first cell with specified DataTime value:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Find cell with specified DataTime value
DateTime dateTime = DateTime.Now;
IXLSRange result = workbook.FindDateTime(dateTime);
public CellRange FindDateTime(DateTime dateTimeValue)

Parameters

dateTimeValue DateTime

Datetime value to search for.

Returns

CellRange

Found range.

FindNumber(double, bool)

Finds the cell with the input number. This sample shows how to find the first cell with specified double value:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Find cell with specified double value
double value = 9.00;
IXLSRange result = workbook.FindNumber(value, false);
public CellRange FindNumber(double doubleValue, bool formulaValue)

Parameters

doubleValue double

Double value to search for.

formulaValue bool

Indicates whether includes formula value to search for.

Returns

CellRange

Found range.

FindString(string, bool, bool)

Finds the cell with the input string. This sample shows how to find the first cell with specified string value:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Find cell with specified string value
string value = "value";
IXLSRange result = workbook.FindString(value, false, false);
public CellRange FindString(string stringValue, bool formula, bool formulaValue)

Parameters

stringValue string

String value to search for.

formula bool

Indicates whether includes formula to search for.

formulaValue bool

Indicates whether includes formula value to search for.

Returns

CellRange

Found range.

FindTimeSpan(TimeSpan)

Finds the cell with the input time span. This sample shows how to find the first cell with specified TimeSpan value:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Find cell with specified TimeSpan value
TimeSpan timeSpan = new TimeSpan(2, 30, 30);
IXLSRange result = workbook.FindTimeSpan(timeSpan);
public CellRange FindTimeSpan(TimeSpan timeSpanValue)

Parameters

timeSpanValue TimeSpan

Time span value to search for.

Returns

CellRange

Found range.

GetChartSheetByName(string)

public ChartSheet GetChartSheetByName(string name)

Parameters

name string

Returns

ChartSheet

GetCustomFontParsedResult()

Get result that parse the custom path of font files

public Hashtable GetCustomFontParsedResult()

Returns

Hashtable

GetDigitalSignatures()

Get collection of DigitalSignature in this file.

public IDigitalSignatures GetDigitalSignatures()

Returns

IDigitalSignatures

Collection of DigitalSignature

GetMatchingColor(Color)

Find best matching Color in workbook palette. The following code illustrates how to get the indexed color from ExcelColors for the given color from Color structure:

//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//Get color
ExcelColors color = workbook.GetMatchingColor(System.Drawing.Color.Red);

//Set color
worksheet["B2"].Style.KnownColor = color;

//Save to file
workbook.SaveToFile("CellFormats.xlsx");
public ExcelColors GetMatchingColor(Color color)

Parameters

color Color

Color to search for.

Returns

ExcelColors

Workbook palette color.

GetMatchingColor(int, int, int)

Find best matching Color in workbook palette. The following code illustrates how to get the indexed color from ExcelColors for the given color from Color structure:

//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//Get color
ExcelColors color = workbook.GetMatchingColor(255, 0, 0);

//Set color
worksheet["B2"].Style.KnownColor = color;

//Save to file
workbook.SaveToFile("CellFormats.xlsx");
public ExcelColors GetMatchingColor(int r, int g, int b)

Parameters

r int

Red color.

g int

Green color.

b int

Blue color.

Returns

ExcelColors

Workbook palette color.

GetOleSize()

get the size of the visible range of cells when this workbook is displyed as an embedded obect in another document;

public IXLSRange GetOleSize()

Returns

IXLSRange

if there does not set the size ,return null

GetPaletteColor(ExcelColors)

Gets excel color from workbook palette. The following code illustrates how to get the RGB color value for the specified color from ExcelColors enumeration:

//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//Get color
System.Drawing.Color color = workbook.GetPaletteColor(ExcelColors.Red);

//Set color
worksheet["B2"].Style.Color = workbook.Colors[10];

//Save to file
workbook.SaveToFile("CellFormats.xlsx");
public Color GetPaletteColor(ExcelColors color)

Parameters

color ExcelColors

Index from palette array.

Returns

Color

RGB Color.

GetSafeSheetName(string)

public string GetSafeSheetName(string inputName)

Parameters

inputName string

Returns

string

GetSafeSheetName(string, char)

public string GetSafeSheetName(string inputName, char replaceChar)

Parameters

inputName string
replaceChar char

Returns

string

GetSplitPageInfo()

public List<Dictionary<int, PageColRow>> GetSplitPageInfo()

Returns

List<Dictionary<int, PageColRow>>

GetSplitPageTable(Workbook)

public DataTable GetSplitPageTable(Workbook wb)

Parameters

wb Workbook

Returns

DataTable

GetThemeColor(ThemeColorType)

Gets theme color.

public Color GetThemeColor(ThemeColorType type)

Parameters

type ThemeColorType

The theme color type.

Returns

Color

The theme color.

InitCalcEngine()

Initilize Calc engine

public void InitCalcEngine()

IsPasswordProtected(Stream)

public static bool IsPasswordProtected(Stream stream)

Parameters

stream Stream

Returns

bool

IsPasswordProtected(string)

check file is password protect

public static bool IsPasswordProtected(string fileName)

Parameters

fileName string

Returns

bool

LoadFromFile(string)

Loads a file and imports its data.

public void LoadFromFile(string fileName)

Parameters

fileName string

LoadFromFile(string, ExcelVersion)

Loads a file and imports its data.

public void LoadFromFile(string fileName, ExcelVersion version)

Parameters

fileName string

File name

version ExcelVersion

Excel version

LoadFromFile(string, bool)

Loads a file and imports its data.

public void LoadFromFile(string fileName, bool preserveMode)

Parameters

fileName string

File name

preserveMode bool

Preserve mode

LoadFromFile(string, string)

Loads text files stream with user defined separator.

public void LoadFromFile(string fileName, string separator)

Parameters

fileName string

File name

separator string

Delimiter of text file.

LoadFromFile(string, string, int, int)

Loads text files with user defined separator.

public void LoadFromFile(string fileName, string separator, int row, int column)

Parameters

fileName string

File name.

separator string

Delimiter of text file.

row int

Start row.

column int

Start column.

LoadFromFile(string, string, int, int, ExcelVersion)

Loads text files with user defined separator.

public void LoadFromFile(string fileName, string separator, int row, int column, ExcelVersion version)

Parameters

fileName string

File name.

separator string

Delimiter of text file.

row int

Start row.

column int

Start column.

version ExcelVersion

workbook version

LoadFromFile(string, string, int, int, ExcelVersion, Encoding)

Loads text files with user defined separator.

public void LoadFromFile(string fileName, string separator, int row, int column, ExcelVersion version, Encoding encoding)

Parameters

fileName string

File name.

separator string

Delimiter of text file.

row int

Start row.

column int

Start column.

version ExcelVersion

workbook version

encoding Encoding

Text Encoding

LoadFromHtml(Stream)

Loads a html file and imports its data.

public void LoadFromHtml(Stream stream)

Parameters

stream Stream

Stream contains data.

LoadFromHtml(string)

Loads a html file and imports its data.

public void LoadFromHtml(string fileName)

Parameters

fileName string

File name.

LoadFromMHtml(Stream)

Loads a Mhtml file and imports its data.

public void LoadFromMHtml(Stream stream)

Parameters

stream Stream

Stream contains data.

LoadFromMHtml(string)

Loads a Mhtml file and imports its data.

public void LoadFromMHtml(string fileName)

Parameters

fileName string

File name.

LoadFromStream(Stream)

Load workbook from the stream.

public void LoadFromStream(Stream stream)

Parameters

stream Stream

Stream contains data.

LoadFromStream(Stream, ExcelVersion)

Load workbook from the stream.

public void LoadFromStream(Stream stream, ExcelVersion version)

Parameters

stream Stream

Stream contains data

version ExcelVersion

Excel version

LoadFromStream(Stream, bool)

Load workbook from the stream.

public void LoadFromStream(Stream stream, bool loadStyles)

Parameters

stream Stream

Stream contains data.

loadStyles bool

Indicates whether loads styles.

LoadFromStream(Stream, string, int, int)

Loads text files stream with user defined separator.max row 60000.

public void LoadFromStream(Stream stream, string separator, int row, int column)

Parameters

stream Stream

File stream.

separator string

Delimiter of text file.

row int

Start row.

column int

Start column.

LoadFromStream(Stream, string, int, int, ExcelVersion)

Loads text files stream with user defined separator. Version2007 support 60000+ row

public void LoadFromStream(Stream stream, string separator, int row, int column, ExcelVersion version)

Parameters

stream Stream

File stream.

separator string

Delimiter of text file.

row int

Start row.

column int

Start column.

version ExcelVersion

Excel version.

LoadFromXml(Stream)

Loads a xml file and imports its data.

public void LoadFromXml(Stream stream)

Parameters

stream Stream

Stream contains data.

LoadFromXml(string)

Loads a xml file and imports its data.

public void LoadFromXml(string fileName)

Parameters

fileName string

File name.

LoadTemplateFromFile(string)

Load workbook from the excel template.

public void LoadTemplateFromFile(string fileName)

Parameters

fileName string

File name

LoadTemplateFromFile(string, bool)

Load workbook from the excel template.

public void LoadTemplateFromFile(string fileName, bool loadStyles)

Parameters

fileName string

File name

loadStyles bool

Indicates whehter load styles.

OnlineSaveToFile(string)

Save file use for Online

public bool OnlineSaveToFile(string fileName)

Parameters

fileName string

Returns

bool

OpenOnlineBin(string)

Save bin use for Online

public void OpenOnlineBin(string binFile)

Parameters

binFile string

PasteFromClipboard()

Copies workbook and all its worksheets from the clipboard.

public void PasteFromClipboard()

PixelsToColumnWidth(double)

Converts column width in pixels into column width in characters.

public double PixelsToColumnWidth(double pixels)

Parameters

pixels double

Column width in pixels.

Returns

double

Column width in characters.

Protect(string)

protect file also protect workbook window and structure.

public void Protect(string passwordToOpen)

Parameters

passwordToOpen string

password to open file.

Protect(string, bool, bool)

protect file,also Indicates whether protect workbook window and structure or not

public void Protect(string passwordToOpen, bool bIsProtectWindow, bool bIsProtectContent)

Parameters

passwordToOpen string

password to open file.

bIsProtectWindow bool

Indicates if protect workbook window.

bIsProtectContent bool

Indicates if protect workbook content.

ProtectWorkbook(bool, bool, string)

Sets protection for workbook.

public void ProtectWorkbook(bool bIsProtectWindow, bool bIsProtectContent, string password)

Parameters

bIsProtectWindow bool

Indicates if protect workbook window.

bIsProtectContent bool

Indicates if protect workbook content.

password string

password

RejectAllTrackedChanges()

Reject all tracked changes in the workbook.

public void RejectAllTrackedChanges()

RemoveAllDigitalSignatures()

Remove all DigitalSignature in this file.

public void RemoveAllDigitalSignatures()

Replace(string, DataColumn, bool)

Replaces cell's value from data column values. The following code snippet illustrates how to replace the string value with data column:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Replace the oldValue by data column
string oldValue = "Find";
System.Data.DataTable table = new System.Data.DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Rows.Add(1);
System.Data.DataColumn dataColumn = table.Columns[0];
workbook.Replace(oldValue, dataColumn, true);

//Save to file
workbook.SaveToFile("Replace.xlsx");
public void Replace(string oldValue, DataColumn newValues, bool includeColumnName)

Parameters

oldValue string

Value to replace.

newValues DataColumn

New data.

includeColumnName bool

Indicates whether includes column name.

Replace(string, DataTable, bool)

Replaces cell's value from data table values. The following code snippet illustrates how to replace the string value with data table:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Replace the oldValue by data table
string oldValue = "Find";
System.Data.DataTable table = new System.Data.DataTable();
table.Columns.Add("Dosage", typeof(int));
table.Rows.Add(1);
workbook.Replace(oldValue, table, true);

//Save to file
workbook.SaveToFile("Replace.xlsx");
public void Replace(string oldValue, DataTable newValues, bool includeColumnName)

Parameters

oldValue string

Value to replace.

newValues DataTable

New data.

includeColumnName bool

Indicates whether includes column name.

Replace(string, DateTime)

Replaces cell's value by specified value. The following code illustrates how to replace the string value with datetime:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Replace the oldValue by dateTime
string oldValue = "Find";
DateTime dateTime = DateTime.Now;
workbook.Replace(oldValue, dateTime);

//Save to file
workbook.SaveToFile("Replace.xlsx");
public void Replace(string oldValue, DateTime newValue)

Parameters

oldValue string

Value to replace.

newValue DateTime

New value

Replace(string, double)

Replaces cell's value by specified value. The following code snippet illustrates how to replace the string with double:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Replace the oldValue by double
string oldValue = "Ten";
workbook.Replace(oldValue, 10.0);

//Save to file
workbook.SaveToFile("Replace.xlsx");
public void Replace(string oldValue, double newValue)

Parameters

oldValue string

Value to replace.

newValue double

New value.

Replace(string, double[], bool)

Replaces cell's value from array. The following code snippet illustrates how to replace the string with array of double values:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Replace the oldValue by array of double values
string oldValue = "Find";
double[] newValues = { 1.0, 2.0 };
workbook.Replace(oldValue, newValues, true);

//Save to file
workbook.SaveToFile("Replace.xlsx");
public void Replace(string oldValue, double[] newValues, bool isVertical)

Parameters

oldValue string

Value to replace.

newValues double[]

New values.

isVertical bool

Indicates whether new values should be inserted vertically.

Replace(string, int[], bool)

Replaces cell's value from array. The following code snippet illustrates how to replace the string with array of int values:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Replace the oldValue by array of int values
string oldValue = "Find";
int[] newValues = { 1, 2 };
workbook.Replace(oldValue, newValues, true);

//Save to file
workbook.SaveToFile("Replace.xlsx");
public void Replace(string oldValue, int[] newValues, bool isVertical)

Parameters

oldValue string

Value to replace.

newValues int[]

New values.

isVertical bool

Indicates whether new values should be inserted vertically.

Replace(string, string)

Replaces cell's value by specified value. The following code snippet illustrates how to replace the string with another string:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Replace the oldValue by newValue
string oldValue = "Find";
string newValue = "NewValue";
workbook.Replace(oldValue, newValue);

//Save to file
workbook.SaveToFile("Replace.xlsx");
public void Replace(string oldValue, string newValue)

Parameters

oldValue string

Value to replace.

newValue string

New value

Replace(string, string[], bool)

Replaces cell's value from array. The following code snippet illustrates how to replace the string with array of string values:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Replace the oldValue by array of string values
string oldValue = "Find";
string[] newValues = { "X values", "Y values" };
workbook.Replace(oldValue, newValues , true);

//Save to file
workbook.SaveToFile("Replace.xlsx");
public void Replace(string oldValue, string[] newValues, bool isVertical)

Parameters

oldValue string

Value to replace.

newValues string[]

New values.

isVertical bool

Indicates whether new values should be inserted vertically.

ResetPalette()

Resets the color palette to the default colors. The following code snippets illustrates how to reset the palette:

//Create worksheet
Workbook workbook = new Workbook();
Worksheet worksheet = workbook.Worksheets[0];

//Get colors
System.Drawing.Color[] colors = workbook.Colors;

//Check color
Console.WriteLine(colors[2].Name);

//Set color
colors[2] = System.Drawing.Color.Yellow;

//Reset palette
workbook.ResetPalette();

//Check color
Console.WriteLine(workbook.Colors[2].Name);

//Save to file
workbook.SaveToFile("CellFormats.xlsx");
public void ResetPalette()

Save()

Saves changes to the specified workbook

public void Save()

SaveAsImage(int, float, float)

public Stream SaveAsImage(int sheetIndex, float dpiX, float dpiY)

Parameters

sheetIndex int
dpiX float
dpiY float

Returns

Stream

SaveAsImage(float, float)

public Stream[] SaveAsImage(float dpiX, float dpiY)

Parameters

dpiX float
dpiY float

Returns

Stream[]

SaveAsTemplate(string)

Save workbook as template to file.

public void SaveAsTemplate(string fileName)

Parameters

fileName string

File name.

SaveAsXml(Stream)

Save workbook as XML format to stream.

public void SaveAsXml(Stream stream)

Parameters

stream Stream

Stream object.

SaveAsXml(string)

Save workbook to an XML data file.

public void SaveAsXml(string fileName)

Parameters

fileName string

XML file name.

SaveChartAsImage(ChartSheet)

Save chart to image.

public Stream SaveChartAsImage(ChartSheet chartSheet)

Parameters

chartSheet ChartSheet

Returns

Stream

SaveChartAsImage(Worksheet)

Save chart to images.

public Stream[] SaveChartAsImage(Worksheet worksheet)

Parameters

worksheet Worksheet

worksheet instance

Returns

Stream[]

SaveChartAsImage(Worksheet, int)

Save chart to image.

public Stream SaveChartAsImage(Worksheet worksheet, int chartIndex)

Parameters

worksheet Worksheet

work sheet

chartIndex int

chart index

Returns

Stream

SaveToFile(string)

Saves changes to the workbook in a different file

public void SaveToFile(string fileName)

Parameters

fileName string

File name.

SaveToFile(string, ExcelVersion)

Saves changes to the workbook in a different file

public void SaveToFile(string fileName, ExcelVersion version)

Parameters

fileName string

File name

version ExcelVersion

Excel version

SaveToFile(string, FileFormat)

Saves changes to the workbook in a different file

public void SaveToFile(string fileName, FileFormat fileFormat)

Parameters

fileName string

File name

fileFormat FileFormat

File format

SaveToFile(string, FileFormat, bool)

Saves changes to the workbook in a different file

public void SaveToFile(string fileName, FileFormat fileFormat, bool retainHiddenDataToCSV)

Parameters

fileName string

File name

fileFormat FileFormat

File format

retainHiddenDataToCSV bool

Retain hidden data when save to csv.

SaveToFile(string, TextSaveOptions)

Saves changes to the workbook in a different file

public void SaveToFile(string fileName, TextSaveOptions textSaveOptions)

Parameters

fileName string

File name

textSaveOptions TextSaveOptions

Text save options.

SaveToFile(string, string)

Saves changes to the workbook in a different file. The following code illustrates how to save the active worksheet in a different file with separator:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Save to file
workbook.SaveToFile("Result.csv" , ",");
public void SaveToFile(string fileName, string separator)

Parameters

fileName string

File name.

separator string

Current separator.

SaveToFile(string, string, bool)

Saves changes to the workbook in a different file. The following code illustrates how to save the active worksheet in a different file with separator:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Save to file
workbook.SaveToFile("Result.csv" , ",", true);
public void SaveToFile(string fileName, string separator, bool addQuotationsForStringValue)

Parameters

fileName string

File name.

separator string

Current separator.

addQuotationsForStringValue bool

Add double Quotation marks for string value.

SaveToHtml(string)

Saves the workbook to html

public void SaveToHtml(string fileName)

Parameters

fileName string

File name.

SaveToHtml(string, bool)

Saves the workbook to html

public void SaveToHtml(string fileName, bool skipHideSheet)

Parameters

fileName string

File name.

skipHideSheet bool

Whether skip hidden sheet.

SaveToStream(Stream)

Save workbook the stream

public void SaveToStream(Stream Stream)

Parameters

Stream Stream

Stream object

SaveToStream(Stream, FileFormat)

Save workbook to stream.

public void SaveToStream(Stream stream, FileFormat fileFormat)

Parameters

stream Stream
fileFormat FileFormat

SaveToStream(Stream, string)

Save workbook the stream. The following code illustrates how to saves the active worksheet as stream with separator:

//Create workbook
Workbook workbook = new Workbook();
workbook.LoadFromFile("Sample.xlsx");

//Save to stream
Stream stream = new MemoryStream();
workbook.SaveToFile(stream , ",");
public void SaveToStream(Stream stream, string separator)

Parameters

stream Stream

Stream object.

separator string

Separator.

SetMaxDigitWidth(int)

public void SetMaxDigitWidth(int w)

Parameters

w int

SetOleSize(int, int, int, int)

set the size of the visible range of cells when this workbook is displyed as an embedded obect in another document;

public void SetOleSize(int firstRow, int firstColumn, int lastRow, int lastColumn)

Parameters

firstRow int

the visible range's first row index

firstColumn int

the visible range's first column index

lastRow int

the visible range's last row index

lastColumn int

the visible range's last column index

SetThemeColor(ThemeColorType, Color)

Sets the theme color

public void SetThemeColor(ThemeColorType type, Color color)

Parameters

type ThemeColorType

The theme color type.

color Color

the theme color

SetWriteProtectionPassword(string)

Sets write protection password.

public void SetWriteProtectionPassword(string password)

Parameters

password string

Password to set

SprBpcmUuRG9jLkRvY3Vt(object, object)

public void SprBpcmUuRG9jLkRvY3Vt(object val1, object val2)

Parameters

val1 object
val2 object

UnProtect()

unprotect file also upprotect workbook window and structure

public void UnProtect()

UnProtect(string)

unprotect file also upprotect workbook window and structure

public void UnProtect(string bookWindowAndStructurePassword)

Parameters

bookWindowAndStructurePassword string

password for protect workbook window and structure

UnProtectWorkbook(string)

unprotect workbook window and structure

public void UnProtectWorkbook(string password)

Parameters

password string

password