Commonly used EPPlus functions to push data to spreadsheet
The basic syntax to apply a value to a
cell:
WorksheetName.Cells(row#, column#).Value = “data to be applied”
Here is a simple
example:
dim sTitleName as string = "Formula Code \ Version: " & _objectkey
sheet1.Cells(2, 1).Value = sTitleName
sheet1.Cells(3, 1).Value = ObjProperty("DESCRIPTION").
You can use variables for the row and column numbers, which can be helpful in case you need to later insert rows in the spreadsheet, or if the exact address is variable:
sheet1.Cells(headerrow, 1).Value = sTitleName
sheet1.Cells(headerrow + 1, 1).Value = ObjProperty("DESCRIPTION")
Example getting table data and applying it to variable
rows:
'Ingredient Table
dim ingrstartrow as integer = headerrow + 4
dim itemcol as integer = 1
dim fmlcol as integer = 2
dim desccol as integer = 3
dim qtycol as integer = 4
dim uomcol as integer = 5
dim instruccol as integer = 6
'Column Headers
Sheet1.Cells(ingrstartrow, itemcol).Value = "RM Code"
Sheet1.Cells(ingrstartrow, fmlcol).Value = "SubFmla Code"
Sheet1.Cells(ingrstartrow, desccol).Value = "Description"
Sheet1.Cells(ingrstartrow, qtycol).Value = "Quantity"
Sheet1.Cells(ingrstartrow, uomcol).Value = "UOM"
Sheet1.Cells(ingrstartrow, instruccol).Value = "Instructions"
'Data table
dim itemrow as integer = ingrstartrow + 1
for x as integer = 0 to oLines.length-1
Sheet1.Cells(itemrow, itemcol).Value = oItems(x)
Sheet1.Cells(itemrow, fmlcol).Value = oFmla(x)
Sheet1.Cells(itemrow, desccol).Value = oDes(x)
Sheet1.Cells(itemrow, qtycol).Value = math.Round(cdbl(oQty(x)), 4)
Sheet1.Cells(itemrow, uomcol).Value = oUOM(x)
Sheet1.Cells(itemrow, instruccol).Value = oInstruc(x)
itemrow = itemrow + 1
next
If your report requires list labels (enum lists, status, etc.), you may prefer to generate
and use XML data for the objects, which provides _LABEL
fields for
list-supported data, _FORMATTED
fields for parameter values, etc. Regardless
of how you retrieve and modify the data, setting it to cells is the same.