Table of Contents

Interface IWorkbook

Namespace
Spire.Xls.Core
Assembly
Spire.XLS.dll
public interface IWorkbook : IExcelApplication
Inherited Members

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.

IWorksheet ActiveSheet { get; }

Property Value

IWorksheet

ActiveSheetIndex

Gets / sets index of the active sheet.

int ActiveSheetIndex { get; set; }

Property Value

int

AddInFunctions

Returns collection of all workbook's add-in functions. Read-only.

IAddInFunctions AddInFunctions { get; }

Property Value

IAddInFunctions

Allow3DRangesInDataValidation

Indicates whether to allow usage of 3D ranges in DataValidation list property (MS Excel doesn't allow).

bool Allow3DRangesInDataValidation { get; set; }

Property Value

bool

ArgumentsSeparator

Formula arguments separator.

string ArgumentsSeparator { get; }

Property Value

string

Author

Returns or sets the author of the comment. Read-only String.

string Author { get; set; }

Property Value

string

BuiltInDocumentProperties

Returns 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;
IBuiltInDocumentProperties BuiltInDocumentProperties { get; }

Property Value

IBuiltInDocumentProperties

Charts

Collection of the chart objects.

ICharts Charts { get; }

Property Value

ICharts

CodeName

Name which is used by macros to access the workbook items.

string CodeName { get; set; }

Property Value

string

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;
ICustomDocumentProperties CustomDocumentProperties { get; }

Property Value

ICustomDocumentProperties

Date1904

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

bool Date1904 { get; set; }

Property Value

bool

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.

bool DetectDateTimeInValue { get; set; }

Property Value

bool

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).

bool DisableMacrosStart { get; set; }

Property Value

bool

DisplayWorkbookTabs

Indicates whether tabs are visible.

bool DisplayWorkbookTabs { get; set; }

Property Value

bool

DisplayedTab

Index of tab which will be displayed on document open.

int DisplayedTab { get; set; }

Property Value

int

HasMacros

True indicate that opened workbook contains VBA macros.

bool HasMacros { get; }

Property Value

bool

IsCellProtection

True if cell is protected.

bool IsCellProtection { get; }

Property Value

bool

IsDisplayPrecision

True if cell is protected.

bool IsDisplayPrecision { get; set; }

Property Value

bool

IsHScrollBarVisible

Gets or sets a value indicating whether to display 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");
bool IsHScrollBarVisible { get; set; }

Property Value

bool

IsRightToLeft

Indicates whether worksheet is displayed right to left.

bool IsRightToLeft { get; set; }

Property Value

bool

IsVScrollBarVisible

Gets or sets a value indicating whether to display 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");
bool IsVScrollBarVisible { get; set; }

Property Value

bool

IsWindowProtection

True if window is protected.

bool IsWindowProtection { get; }

Property Value

bool

MaxColumnCount

Returns maximum column count for each worksheet in this workbook. Read-only.

int MaxColumnCount { get; }

Property Value

int

MaxRowCount

Returns maximum row count for each worksheet in this workbook. Read-only.

int MaxRowCount { get; }

Property Value

int

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). 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;
INameRanges Names { get; }

Property Value

INameRanges

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 |

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");
Color[] Palette { get; }

Property Value

Color[]

PasswordToOpen

Gets / sets password to encrypt document.

string PasswordToOpen { get; set; }

Property Value

string

PivotCaches

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

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

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

Property Value

XlsPivotCachesCollection

ReadOnly

True if the workbook has been opened as Read-only. Read-only Boolean.

bool ReadOnly { get; }

Property Value

bool

ReadOnlyRecommended

True to display a message when the file is opened, recommending that the file be opened as read-only.

bool ReadOnlyRecommended { get; set; }

Property Value

bool

RowSeparator

Gets / sets row separator for array parsing.

string RowSeparator { get; }

Property Value

string

Saved

True if no changes have been made to the specified workbook since it was last saved. Read/write Boolean.

bool Saved { get; set; }

Property Value

bool

StandardFont

Returns or sets the name of the standard font. Read/write String. 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");
string StandardFont { get; set; }

Property Value

string

StandardFontSize

Returns or sets the standard font size, in points. Read/write. 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");
double StandardFontSize { get; set; }

Property Value

double

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;
IStyles Styles { get; }

Property Value

IStyles

TabSheets

Returns collection of tab sheets. Read-only.

ITabSheets TabSheets { get; }

Property Value

ITabSheets

ThrowOnUnknownNames

Indicates whether exception should be thrown when unknown name was found in a formula.

bool ThrowOnUnknownNames { get; set; }

Property Value

bool

Version

Gets / sets excel version.

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.

IWorksheets Worksheets { get; }

Property Value

IWorksheets

Methods

Activate()

Activates the first window associated with the workbook.

void Activate()

AddFont(IFont)

Adds font to the inner fonts collection and makes this font read-only.

IFont AddFont(IFont fontToAdd)

Parameters

fontToAdd IFont

Font to add.

Returns

IFont

Added font.

Clone()

Creates copy of the current instance.

IWorkbook Clone()

Returns

IWorkbook

Copy of the current instance.

Close()

Closes the object without saving.

void Close()

Close(bool)

Closes the object.

void Close(bool saveChanges)

Parameters

saveChanges bool

If True, all changes will be saved.

Close(bool, string)

Closes the object.

void Close(bool SaveChanges, string Filename)

Parameters

SaveChanges bool

If True, all changes will be saved.

Filename string

Name of the file.

Close(string)

Closes the object and saves changes into specified file.

void Close(string Filename)

Parameters

Filename string

File name in which workbook will be saved if SaveChanges is true.

CopyToClipboard()

Copies workbook to the clipboard.

void CopyToClipboard()

CreateFont()

Method to create a font object and register it in 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");
IFont CreateFont()

Returns

IFont

Newly created font.

CreateFont(IFont)

Method that creates font object based on another font object and registers it in the workbook.

IFont CreateFont(IFont baseFont)

Parameters

baseFont IFont

Base font for the new one.

Returns

IFont

Newly created font.

CreateFont(string, float, int)

Method creates a font object based on native font and register it in the workbook.

IFont CreateFont(string familyName, float size, int fontStyle)

Parameters

familyName string
size float
fontStyle int

Returns

IFont

Newly created font.

CreateTemplateMarkersProcessor()

Creates object that can be used for template markers processing.

IMarkersDesigner CreateTemplateMarkersProcessor()

Returns

IMarkersDesigner

Object that can be used for template markers processing.

FindAll(bool)

This method seraches for the all cells with specified bool value. 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);
CellRange[] FindAll(bool findValue)

Parameters

findValue bool

Value to search.

Returns

CellRange[]

All found cells, or Null if value was not found

FindAll(DateTime)

This method seraches for the all cells with specified DateTime value. 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);
CellRange[] FindAll(DateTime findValue)

Parameters

findValue DateTime

Value to search.

Returns

CellRange[]

All found cells, or Null if value was not found.

FindAll(double, FindType)

This method seraches for the all cells with specified double value. 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);
CellRange[] FindAll(double findValue, FindType flags)

Parameters

findValue double

Value to search.

flags FindType

Type of value to search.

Returns

CellRange[]

All found cells, or Null if value was not found.

FindAll(string, FindType)

This method seraches for the all cells with specified string value. 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);
CellRange[] FindAll(string findValue, FindType flags)

Parameters

findValue string

Value to search.

flags FindType

Type of value to search.

Returns

CellRange[]

All found cells, or Null if value was not found.

FindAll(TimeSpan)

This method seraches for the all cells with specified TimeSpan value. 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);
CellRange[] FindAll(TimeSpan findValue)

Parameters

findValue TimeSpan

Value to search.

Returns

CellRange[]

All found cells, or Null if value was not found.

FindOne(bool)

This method seraches for the first cell with specified bool value. 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);
IXLSRange FindOne(bool findValue)

Parameters

findValue bool

Value to search.

Returns

IXLSRange

First found cell, or Null if value was not found.

FindOne(DateTime)

This method seraches for the first cell with specified DateTime value. This sample shows how to find the first cell with specified DateTime value:

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

//Find cell with specified DateTime value
DateTime dateTime = DateTime.Now;
IXLSRange result = workbook.FindDateTime(dateTime);
IXLSRange FindOne(DateTime findValue)

Parameters

findValue DateTime

Value to search.

Returns

IXLSRange

First found cell, or Null if value was not found.

FindOne(double, FindType)

This method seraches for the first cell with specified double value. 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);
IXLSRange FindOne(double findValue, FindType flags)

Parameters

findValue double

Value to search.

flags FindType

Type of value to search.

Returns

IXLSRange

First found cell, or Null if value was not found.

FindOne(string, FindType)

This method seraches for the first cell with specified string value. 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);
IXLSRange FindOne(string findValue, FindType flags)

Parameters

findValue string

Value to search.

flags FindType

Type of value to search.

Returns

IXLSRange

First found cell, or Null if value was not found.

FindOne(TimeSpan)

This method seraches for the first cell with specified TimeSpan value. 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);
IXLSRange FindOne(TimeSpan findValue)

Parameters

findValue TimeSpan

Value to search.

Returns

IXLSRange

First found cell, or Null if value was not found.

GetNearestColor(Color)

Gets the nearest color to the specified Color structure from 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");
ExcelColors GetNearestColor(Color color)

Parameters

color Color

System color.

Returns

ExcelColors

Color index from workbook palette.

GetNearestColor(int, int, int)

Gets the nearest color to the specified by red, green, and blue values color from 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");
ExcelColors GetNearestColor(int r, int g, int b)

Parameters

r int

Red component of the color.

g int

Green component of the color.

b int

Blue component of the color.

Returns

ExcelColors

Color index from workbook palette.

GetPaletteColor(ExcelColors)

Method return Color object from workbook palette by its index. 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");
Color GetPaletteColor(ExcelColors color)

Parameters

color ExcelColors

Index from palette array.

Returns

Color

RGB Color.

Protect(bool, bool)

Sets protection for workbook.

void Protect(bool bIsProtectWindow, bool bIsProtectContent)

Parameters

bIsProtectWindow bool

Indicates if protect workbook window.

bIsProtectContent bool

Indicates if protect workbook content.

Replace(string, DataColumn, bool)

Replaces specified string by 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");
void Replace(string oldValue, DataColumn newValues, bool isFieldNamesShown)

Parameters

oldValue string

String value to replace.

newValues DataColumn

Data table with new data.

isFieldNamesShown bool

Indicates whether field name must be shown.

Replace(string, DataTable, bool)

Replaces specified string by 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");
void Replace(string oldValue, DataTable newValues, bool isFieldNamesShown)

Parameters

oldValue string

String value to replace.

newValues DataTable

Data table with new data.

isFieldNamesShown bool

Indicates whether field name must be shown.

Replace(string, DateTime)

Replaces specified string 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");
void Replace(string oldValue, DateTime newValue)

Parameters

oldValue string

String value to replace.

newValue DateTime

New value for the range with specified string.

Replace(string, double)

Replaces specified string 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");
void Replace(string oldValue, double newValue)

Parameters

oldValue string

String value to replace.

newValue double

New value for the range with specified string.

Replace(string, double[], bool)

Replaces specified string by data 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");
void Replace(string oldValue, double[] newValues, bool isVertical)

Parameters

oldValue string

String value to replace.

newValues double[]

Array of new values.

isVertical bool

Indicates whether array should be inserted vertically.

Replace(string, int[], bool)

Replaces specified string by data 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");
void Replace(string oldValue, int[] newValues, bool isVertical)

Parameters

oldValue string

String value to replace.

newValues int[]

Array of new values.

isVertical bool

Indicates whether array should be inserted vertically.

Replace(string, string)

Replaces specified string 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");
void Replace(string oldValue, string newValue)

Parameters

oldValue string

String value to replace.

newValue string

New value for the range with specified string.

Replace(string, string[], bool)

Replaces specified string by data 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");
void Replace(string oldValue, string[] newValues, bool isVertical)

Parameters

oldValue string

String value to replace.

newValues string[]

Array of new values.

isVertical bool

Indicates whether array should be inserted vertically.

ResetPalette()

Recover palette to default values. 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");
void ResetPalette()

Save()

Saves changes to the specified workbook. This sample shows how to save changes to the specified workbook:

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

//Save to file
workbook.Save();
void Save()

SaveAs(Stream)

Saves changes to the specified stream.

void SaveAs(Stream stream)

Parameters

stream Stream

Stream that will receive workbook data.

SaveAs(Stream, ExcelSaveType)

Saves changes to the specified stream.

void SaveAs(Stream stream, ExcelSaveType saveType)

Parameters

stream Stream

Stream that will receive workbook data.

saveType ExcelSaveType

Type of the Excel file.

SaveAs(Stream, string)

Save active WorkSheet using separator. 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 , ",");
void SaveAs(Stream stream, string separator)

Parameters

stream Stream

Stream to save.

separator string

Current separator.

SaveAs(string)

Short variant of SaveAs method.

void SaveAs(string Filename)

Parameters

Filename string

SaveAs(string, ExcelSaveType)

Short variant of SaveAs method.

void SaveAs(string Filename, ExcelSaveType saveType)

Parameters

Filename string

Name of the file.

saveType ExcelSaveType

Excel save type.

SaveAs(string, string)

Save active WorkSheet using separator. 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" , ",");
void SaveAs(string fileName, string separator)

Parameters

fileName string

Path to save.

separator string

Current separator.

SetColorOrGetNearest(Color)

If there is at least one free color, define a new color; if not, search for the closest one.

ExcelColors SetColorOrGetNearest(Color color)

Parameters

color Color

Returns

ExcelColors

Color index from workbook palette.

SetColorOrGetNearest(int, int, int)

If there is at least one free color, define a new color; if not, search for the closest one.

ExcelColors SetColorOrGetNearest(int r, int g, int b)

Parameters

r int

Red component of the color.

g int

Green component of the color.

b int

Blue component of the color.

Returns

ExcelColors

Color index from workbook palette.

SetPaletteColor(int, Color)

Set user color for specified element in Color table. 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");
void SetPaletteColor(int index, Color color)

Parameters

index int

Index of Color in array.

color Color

New color which must be set.

SetSeparators(char, char)

Sets separators for formula parsing.

void SetSeparators(char argumentsSeparator, char arrayRowsSeparator)

Parameters

argumentsSeparator char

Arguments separator to set.

arrayRowsSeparator char

Array rows separator to set.

SetWriteProtectionPassword(string)

This method sets write protection password.

void SetWriteProtectionPassword(string password)

Parameters

password string

Password to set.

Unprotect()

Unprotects workbook.

void Unprotect()