In my export ActionResult I was able to load the model into my ExcelPackage.
Where I am having trouble is assigning a border around each cell once LoadFromCollection
is applied. While the AutoFitColumns
correctly applies, the border style I applied only works on Cells["D1"]
, but not on the table.
BorderAround
successfully places a border around the entire table, but I would rather apply to the border to the cells inside the table. Is there a way I can do that?
// Fill worksheet with data to export
var modelCells = worksheet.Cells["D1"];
var border = modelCells.Style.Border.Top.Style = modelCells.Style.Border.Left.Style = modelCells.Style.Border.Right.Style = modelCells.Style.Border.Bottom.Style = ExcelBorderStyle.Medium;
modelCells
.LoadFromCollection(Collection: exportQuery, PrintHeaders: true)
.AutoFitColumns();
If I know the amount of columns the model has, I can count the number of rows with a function and do this:
Or, with more context. I verified that EPPlus will accept a string variable in Cells[], which allows me to select the entire table and apply my border styling and
AutoFitColumns{}
correctly. All I have to do manually is enter the starting column and ending column in themodelRange
variable.