An easier to use .NET XLSX API
Utility class for XLSX read operations
XLSXReader _reader = new XLSXReader();
Generic method to parse all data in an XLSX file from a given worksheet into a List of type T.
Each property within T which we wish to have automapped to the corresponding XLSX column must have an XLSXMapping
attribute, specifying the associated column name and type
public class MyModel
{
[XLSXMapping("Some Property Column", typeof(string))]
public string SomeProperty { get; set; }
public string SomeUnmappedProperty { get; set; }
}
...
List<MyModel> records = _reader.GetRecords<MyModel>("<path to my XLSX file>", "<sheet of interest>");
Retrieves all worksheet names in a given XLSX file
List<string> sheets = _reader.GetWorksheets("<path to my XLSX file>");
Utility class for XLSX write operations
Generic method to write a list of type T to a specified XLSX worksheet.
As with GetRecords
, each property within T must have an XLSXMapping
attribute if we wish for it to be written to a column within the spreadsheet.
public class MyModel
{
[XLSXMapping("Some Property Column", typeof(string))]
public string SomePropertyIWantWritten { get; set; }
public string SomePropertyIDontWantWritten { get; set; }
}
...
_writer.PutRecords<MyModel>("<path to my XLSX File>", "<sheet of interest>");
This method will write to an existing XLSX file, if one is found at the specified path, or create a new one, if one is not found at the specified path.
By default, this method will overwrite a file completely. If you wish to append to an existing file, specify append = true
_writer.PutRecords<MyModel>("<path to my XLSX File>", "<sheet of interest>", true);