[]
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.
[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)
| 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. |
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.
public void Open(string fileName)
Public Sub Open(fileName As String)
| Type | Name | Description |
|---|---|---|
| string | fileName | The path and name of the workbook file to open. Must not be |
workbook.Open(Path.Combine(Environment.CurrentDirectory, "QuarterlyReport.xlsx"));
string fullName = workbook.FullName;
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.
public IList<JsonError> Open(string fileName, DeserializationOptions deserializationOptions)
Public Function Open(fileName As String, deserializationOptions As DeserializationOptions) As IList(Of JsonError)
| Type | Name | Description |
|---|---|---|
| string | fileName | The JSON file to open. |
| DeserializationOptions | deserializationOptions | The options that control JSON deserialization. |
| Type | Description |
|---|---|
| IList<JsonError> | A list of JsonError objects generated while opening the JSON file. |
DeserializationOptions options = new DeserializationOptions();
options.IgnoreStyle = true;
IList<JsonError> errors = workbook.Open("spread_js_exported.json", options);
Opens the specified excel file stream.
[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)
| Type | Name | Description |
|---|---|---|
| Stream | fileStream | The file stream. |
| string | password | The password of the file. |
| OpenOptions | openOptions | Options for opening. |
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.
public void Open(string fileName, OpenFileFormat fileFormat)
Public Sub Open(fileName As String, fileFormat As OpenFileFormat)
| Type | Name | Description |
|---|---|---|
| string | fileName | The file to open. |
| OpenFileFormat | fileFormat | The format of the file. |
IWorkbook openedWorkbook = new Workbook();
openedWorkbook.Open("Template.sjs", OpenFileFormat.Sjs);
IWorksheet firstSheet = openedWorkbook.Worksheets[0];
Opens the stream with specified file format.
public void Open(Stream fileStream, OpenFileFormat fileFormat)
Public Sub Open(fileStream As Stream, fileFormat As OpenFileFormat)
| Type | Name | Description |
|---|---|---|
| Stream | fileStream | The specified file stream. |
| OpenFileFormat | fileFormat | The format of the file stream. |
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);
}
Opens the specified Excel file stream.
Use this method to load workbook data from a Stream.
public void Open(Stream fileStream)
Public Sub Open(fileStream As Stream)
| Type | Name | Description |
|---|---|---|
| Stream | fileStream | The stream that contains the Excel file data. Must not be null. |
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);
Opens a file with the specified open options.
Use this overload to control how the workbook is loaded for supported file formats.
public void Open(string fileName, OpenOptionsBase options)
Public Sub Open(fileName As String, options As OpenOptionsBase)
| Type | Name | Description |
|---|---|---|
| string | fileName | The file to open. |
| OpenOptionsBase | options | The open options for the file. Must be compatible with the file format. |
XlsxOpenOptions options = new XlsxOpenOptions();
options.DoNotRecalculateAfterOpened = true;
string fileName = Path.Combine(Environment.CurrentDirectory, "OpenWorkbookWithOptions.xlsx");
workbook.Open(fileName, options);
Opens the stream with specified options.
public void Open(Stream fileStream, OpenOptionsBase options)
Public Sub Open(fileStream As Stream, options As OpenOptionsBase)
| Type | Name | Description |
|---|---|---|
| Stream | fileStream | The file stream. |
| OpenOptionsBase | options | The format of opening the file stream. Possible types: |
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);
}