[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.IWorkbook.Open

Open Method

Open(string)

Opens a workbook file.

This method opens the specified file by using the default open options. The file type is inferred from the file name extension.

The fileName value is used directly as a file system path. Pass only validated paths from trusted sources.

Declaration
void Open(string fileName)
Sub Open(fileName As String)
Parameters
Type Name Description
string fileName

The path and name of the workbook file to open. Must not be null.

Examples
workbook.Open(Path.Combine(Environment.CurrentDirectory, "QuarterlyReport.xlsx"));
string fullName = workbook.FullName;

Open(string, DeserializationOptions)

Opens the specified JSON file using the provided deserialization options.

Uses the provided DeserializationOptions to control how the JSON content is deserialized into the workbook.

Declaration
IList<JsonError> Open(string fileName, DeserializationOptions deserializationOptions)
Function Open(fileName As String, deserializationOptions As DeserializationOptions) As IList(Of JsonError)
Parameters
Type Name Description
string fileName

The JSON file to open.

DeserializationOptions deserializationOptions

The options that control JSON deserialization.

Returns
Type Description
IList<JsonError>

A list of JsonError objects generated while opening the JSON file.

Examples
DeserializationOptions options = new DeserializationOptions();
options.IgnoreStyle = true;
IList<JsonError> errors = workbook.Open("spread_js_exported.json", options);

Open(string, string, OpenOptions)

Opens the specified Excel file with an optional password and open options.

Use this overload to open a password-protected workbook from the specified file path. You can also provide OpenOptions to control how the workbook is loaded.

This method is obsolete. Use Open(string, OpenOptionsBase) instead.

Declaration
[Obsolete("Use Open(string, OpenOptionsBase) instead.")]
void Open(string fileName, string password = null, OpenOptions openOptions = null)
<Obsolete("Use Open(string, OpenOptionsBase) instead.")>
Sub Open(fileName As String, Optional password As String = Nothing, Optional openOptions As OpenOptions = Nothing)
Parameters
Type Name Description
string fileName

The path and name of the Excel file to open. Must not be null.

string password

The password for the file. Use the password required by the workbook; null if no password is needed.

OpenOptions openOptions

The open options for the file. Use null to apply no explicit open options.

Open(Stream)

Opens the specified Excel file stream.

Use this method to load workbook data from a Stream.

Declaration
void Open(Stream fileStream)
Sub Open(fileStream As Stream)
Parameters
Type Name Description
Stream fileStream

The stream that contains the Excel file data. Must not be null.

Examples
worksheet.Range["A1"].Value = "Name";
MemoryStream stream = new MemoryStream();
workbook.Save(stream, SaveFileFormat.Xlsx);
stream.Position = 0;
IWorkbook openedWorkbook = new Workbook();
openedWorkbook.Open(stream);

Open(Stream, string, OpenOptions)

Opens the specified excel file stream.

Declaration
[Obsolete("Use Open(Stream, OpenOptionsBase) instead.")]
void Open(Stream fileStream, string password = null, OpenOptions openOptions = null)
<Obsolete("Use Open(Stream, OpenOptionsBase) instead.")>
Sub Open(fileStream As Stream, Optional password As String = Nothing, Optional openOptions As OpenOptions = Nothing)
Parameters
Type Name Description
Stream fileStream

The file stream.

string password

The password of the file.

OpenOptions openOptions

Options for opening.

Open(string, OpenFileFormat)

Opens a file using the specified file format.

Use this overload when the file format should be provided explicitly instead of being inferred from the file name.

Declaration
void Open(string fileName, OpenFileFormat fileFormat)
Sub Open(fileName As String, fileFormat As OpenFileFormat)
Parameters
Type Name Description
string fileName

The path of the workbook file to open.

OpenFileFormat fileFormat

The format of the file.

Examples
IWorkbook openedWorkbook = new Workbook();
openedWorkbook.Open("Template.sjs", OpenFileFormat.Sjs);
IWorksheet firstSheet = openedWorkbook.Worksheets[0];

Open(Stream, OpenFileFormat)

Opens the specified format file stream.

Declaration
void Open(Stream fileStream, OpenFileFormat fileFormat)
Sub Open(fileStream As Stream, fileFormat As OpenFileFormat)
Parameters
Type Name Description
Stream fileStream

The specified file stream.

OpenFileFormat fileFormat

The format of the file stream.

Examples
worksheet.Range["A1"].Value = "Template";
using (MemoryStream stream = new MemoryStream())
{
    workbook.Save(stream, SaveFileFormat.Sjs);
    stream.Position = 0;
    IWorkbook openedWorkbook = new Workbook();
    openedWorkbook.Open(stream, OpenFileFormat.Sjs);
}

Open(string, OpenOptionsBase)

Opens a file with the specified open options.

Use this overload to control how the workbook is loaded for supported file formats.

Declaration
void Open(string fileName, OpenOptionsBase options)
Sub Open(fileName As String, options As OpenOptionsBase)
Parameters
Type Name Description
string fileName

The path of the workbook file to open.

OpenOptionsBase options

The open options for the file. Possible types:

Examples
XlsxOpenOptions options = new XlsxOpenOptions();
options.DoNotRecalculateAfterOpened = true;
string fileName = Path.Combine(Environment.CurrentDirectory, "OpenWorkbookWithOptions.xlsx");
IWorkbook openedWorkbook = new Workbook();
openedWorkbook.Open(fileName, options);

Open(Stream, OpenOptionsBase)

Opens the stream with specified options.

Declaration
void Open(Stream fileStream, OpenOptionsBase options)
Sub Open(fileStream As Stream, options As OpenOptionsBase)
Parameters
Type Name Description
Stream fileStream

The file stream.

OpenOptionsBase options

The options used when opening the file stream. Possible types:

Examples
worksheet.Range["A1"].Value = "Open with options";
using (MemoryStream stream = new MemoryStream())
{
    workbook.Save(stream);
    stream.Position = 0;
    XlsxOpenOptions options = new XlsxOpenOptions();
    options.DoNotRecalculateAfterOpened = true;
    IWorkbook openedWorkbook = new Workbook();
    openedWorkbook.Open(stream, options);
}