-
Notifications
You must be signed in to change notification settings - Fork 305
Reading and Writing Data
You can read and write data from and to your spreadsheet in a few different ways. The most obvious is to use the Cells property of the ExcelWorksheet class, shown on the Getting Started page. There are also a few other ways to import/export/read data from/into spreadsheets with EPPlus.
From the Cells property (ExcelRange) you can access these methods to load data from various sources:
-
LoadFromTextandLoadFromTextAsync- Read a csv text file and load the data into a range on a worksheet. -
LoadFromDataReaderandLoadFromDataReaderAsync- Loads data into a range from a DataReader -
LoadFromDataTable- Loads data into a range from a DataTable. Can be used for importing data from a range of sources, like XML and databases. -
LoadFromCollection- Loads data into a range from an IEnumerable using reflection. -
LoadFromDictionaries- Loads data into a range from an IEnumerable of ExpandoObject/dynamic objects (via their IDictionary<string, object> interface. -
LoadFromArrays- Loads data into a range from an IEnumerable of object[] where each object array becomes a row in the worksheet.
You can optionally specify a parameter to create an ExcelTable when you use these methods. For more detailed examples, have a look at sample 4 & 5 the sample project Sample-.NET Framework or Sample-.NET Framework.
From the Cells property (ExcelRange) you can access these methods to write:
-
ToTextandToTextAsync- Writes a range to a csv text. -
SaveToTextandSaveToTextAsync- Writes a range to a csv file. -
GetValue<T>- Gets a value, with the option to specify a datatype -
Value- Gets or sets the value of the range.
You can also use the GetValue and SetValue methods directly on the worksheet object. (This will give a little bit better performance than reading/writing via the range):
-
GetValue<T>- Gets a value of a single cell, with the option to specify a datatype -
SetValue- Sets a value of a single cell
Since the Cells property implements the IEnumerable interface, you can use Linq to query data from a worksheet.
var query1= (from cell in sheet.Cells["d:d"] where cell.Value is double && (double)cell.Value >= 9990 && (double)cell.Value <= 10000 select cell);Most of these methods are demonstrated in the sample project.
EPPlus Software AB - https://epplussoftware.com
- What is new in EPPlus 5+
- Breaking Changes in EPPlus 5
- Breaking Changes in EPPlus 6
- Breaking Changes in EPPlus 7
- Breaking Changes in EPPlus 8
- Addressing a worksheet
- Dimension/Used range
- Copying ranges/sheets
- Insert/Delete
- Filling ranges
- Sorting ranges
- Taking and skipping columns/rows
- Data validation
- Comments
- Freeze and Split Panes
- Header and Footer
- Hyperlinks
- Autofit columns
- Grouping and Ungrouping Rows and Columns
- Formatting and styling
- The ExcelRange.Text property
- Conditional formatting
- Using Themes
- Working with custom named table- or slicer- styles
-
Formula Calculation
- Security considerations
- Circular references
- Referencing tables in formulas
- Supported Functions
- Dynamic array formulas
- Legacy array formulas
- Lambda functions
- Regression analysis functions
- Custom functions for calculations
- Function prefixes
- Precision as Displayed
- Cancelling a calculation
- Trim reference operator
- Working with filters
- Working with slicers
- Working with External Workbooks