This repository was archived by the owner on Mar 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Reading and Writing Data
Jan Källman edited this page Nov 7, 2017
·
3 revisions
You can read and write data from your spreadsheet in a few different ways. The most obvious is to use the Cells property of the ExcelWorksheet class, shown in the samples above. There are also a few other ways to access the data...
From the Cells property (ExcelRange) you can access these methods to load data from various sources:
-
LoadFromText- Read a csv test file. -
LoadFromDataReader- Loads data from a DataReader -
LoadFromDataTable- Loads data from a DatatTable -
LoadFromCollection- Loads data from an IEnumerable using reflection. -
LoadFromArrays- Loads data from arrays
You can optionally specify a parameter to create an ExcelTable when you use these methods. For more detailed examples, have a look at Sample 9 and Sample 13
-
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
Most of these methods are demonstrated in the sample project.