C# Create and Open Excel and Text-Based Workbook Files SpreadsheetGear API Sample
Excel-Compatible Samples for .NET
Description
Create and open Excel-compatible workbook files from disk or network drive using the SpreadsheetGear.Factory.GetWorkbook(...) method which will return an IWorkbook object. Specify no path argument (e.g., GetWorkbook()) to create a new workbook and specify a path (e.g., GetWorkbook(string pathToFile)) to open an existing workbook.
Additional overloaded versions are available (GetWorkbook(CultureInfo cultureInfo) and GetWorkbook(string pathToFile, CultureInfo cultureInfo)) if you need to specify what regional settings (i.e., System.Globalization.CultureInfo) should be used for various locale-sensitive workbook content (e.g., NumberFormats for cells) when creating opening the workbook. If no CultureInfo object is specified, the "en-US" CultureInfo will be used.
If you have already created an IWorkbookSet object, you can also open workbook files from disk or network drive within your IWorkbookSet object by using the IWorkbookSet.Workbooks.Open(string pathToFile) method.
IWorkbookSet.Workbooks.Open(string pathToFile, string password) method that accepts a password as the second argument. See also the Workbook Encryption (Password Protected) SpreadsheetGear API Sample for a demo of this API.SpreadsheetGear supports opening the following Excel-compatible file formats:
- Excel 2007-2025 Open XML (*.xlsx)
- Excel 2007-2025 Macro-Enabled Open XML (*.xlsm)
- Excel 97-2003 (*.xls)
- ASCII CSV / Comma-Delimited (typically saved with *.csv extension)
- Unicode Text Tab-Delimited (typically saved with *.txt extension)