[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.Workbook.Open

Open Method

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.")]
public void Open(string fileName, string password = null, OpenOptions openOptions = null)
<Obsolete("Use Open(string, OpenOptionsBase) instead.")>
Public 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.

Implements

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
public void Open(string fileName)
Public 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.

Implements
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
public IList<JsonError> Open(string fileName, DeserializationOptions deserializationOptions)
Public 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.

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

Open(Stream, string, OpenOptions)

Opens the specified excel file stream.

Declaration
[Obsolete("Use Open(Stream, OpenOptionsBase) instead.")]
public void Open(Stream fileStream, string password = null, OpenOptions openOptions = null)
<Obsolete("Use Open(Stream, OpenOptionsBase) instead.")>
Public 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.

Implements

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
public void Open(string fileName, OpenFileFormat fileFormat)
Public Sub Open(fileName As String, fileFormat As OpenFileFormat)
Parameters
Type Name Description
string fileName

The file to open.

OpenFileFormat fileFormat

The format of the file.

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

Open(Stream, OpenFileFormat)

Opens the stream with specified file format.

Declaration
public void Open(Stream fileStream, OpenFileFormat fileFormat)
Public 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.

Implements
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(Stream)

Opens the specified Excel file stream.

Use this method to load workbook data from a Stream.

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

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

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

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
public void Open(string fileName, OpenOptionsBase options)
Public Sub Open(fileName As String, options As OpenOptionsBase)
Parameters
Type Name Description
string fileName

The file to open.

OpenOptionsBase options

The open options for the file. Must be compatible with the file format.

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

Open(Stream, OpenOptionsBase)

Opens the stream with specified options.

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

The file stream.

OpenOptionsBase options

The format of opening the file stream. Possible types:

Implements
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);
}