If I know the amount of columns the model has, I can count the number of rows with a function and do this:
var modelRows = exportQuery.Count()+1;
string modelRange = "D1:F" + modelRows.ToString();
var modelTable = worksheet.Cells[modelRange];
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 the modelRange
variable.
var modelCells = worksheet.Cells["D1"];
var modelRows = exportQuery.Count()+1;
string modelRange = "D1:F" + modelRows.ToString();
var modelTable = worksheet.Cells[modelRange];
// Assign borders
modelTable.Style.Border.Top.Style = ExcelBorderStyle.Thin;
modelTable.Style.Border.Left.Style = ExcelBorderStyle.Thin;
modelTable.Style.Border.Right.Style = ExcelBorderStyle.Thin;
modelTable.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
// Fill worksheet with data to export
modelCells.LoadFromCollection(Collection: exportQuery, PrintHeaders: true);
modelTable.AutoFitColumns();