I have a .Net core application, and i'm new to using the EPPlus Library with c#. I have a data-table filled with data which i'm currently inserting into an excel sheet using EPPlus. I was wondering if there is a way to format the sheet as a table after you added the data to the sheet and not before? (Like when you are using the Format a table function in excel)
sample of my Code which only fills the excel sheet:
var excelWorkSheet = excel.Workbook.Worksheets["WorkSheet1"];
using (SqlDataReader dr = cmd.ExecuteReader())
{
dt.Load(dr);
}
excelWorkSheet.Cells["A1"].LoadFromDataTable(dt, true);
excel.SaveAs(df);
please keep in mind the df variable above is of type file directory, and that the data in the data-table will be different for each user so the size will never be the same for two users.
EPPlus does not work with the XLS format. Only XLSX. You'll need to find a new library.
Format = "dd/MM/yyyy HH:mm"; if I set like this other columns which use numeric values are getting affected.
Yes this can be done with EPPlus. You can use Dimension
if you do not have fixed rows/columns.
using OfficeOpenXml.Table;
ExcelWorksheet ws = excel.Workbook.Worksheets[1];
//create a range for the table
ExcelRange range = ws.Cells[1, 1, ws.Dimension.End.Row, ws.Dimension.End.Column];
//add a table to the range
ExcelTable tab = ws.Tables.Add(range, "Table1");
//format the table
tab.TableStyle = TableStyles.Medium2;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With