vb.netopenxmlexcelpackage

ExcelPackage excel file load collection


I have been using openxml from excelpackage to manipulate excel spreadsheet and I am stumbled on a function called LoadFromCollection.

Here is a sample code to understand.

 Dim ws As OfficeOpenXml.ExcelWorksheet
 ws = package.Workbook.Worksheets(tableName)
 Dim OutRange = ws.Cells("A1").LoadFromCollection(newList, True)

My question is what this method is doing and what is the correct way to use this function.

Is there any clear documentation?

Edit

Ok from documentation I understand a collection IEnumerable<T> is loaded from top left row of the range.But how does it map with the cells?

Suppose I have 4-5 custom properties in Type T.So how does the cells are filled?Is it like

  1. A1 - 1st Property

  2. B1 - 2nd Property

Need more precise explanation.


Solution

  • You can take a look at this link : LoadFromCollection method implementation.

    According to the source code it should start from Cell A1 and in the columns of 1st row it should write public properties names of type T. Next it would create corresponding rows to each element in IEnumerable<T> collection with actual values of properties in columns.