Is it possible to copy a row (with data, merge, style) in Excel using Epplus?

The problem is that I need to insert data into Excel from the collection several times, using one template for the entire collection.

using (var pckg = new ExcelPackage(new FileInfo(association.TemplatePath))) { var workSheet = pckg.Workbook.Worksheets[1]; var dataTable = WorksheetToDataTable(workSheet); /*Some stuff*/ FindAndReplaceValue(workSheet, dictionary, row); } private DataTable WorksheetToDataTable(ExcelWorksheet oSheet) { int totalRows = oSheet.Dimension.End.Row; int totalCols = oSheet.Dimension.End.Column; DataTable dt = new DataTable(oSheet.Name); DataRow dr = null; for (int i = 1; i <= totalRows; i++) { if (i > 1) dr = dt.Rows.Add(); for (int j = 1; j <= totalCols; j++) { if (i == 1) dt.Columns.Add((oSheet.Cells[i, j].Value ?? "").ToString()); else dr[j - 1] = (oSheet.Cells[i, j].Value ?? "").ToString(); } } return dt; } 

The first image is my template. The second is the first element of the collection (with data, style, merging). Third - other items only have data

This is my templateFirst element of collection has data, style, mergingOther elements got nothing besides data

+8
c # excel epplus
source share
1 answer

I just make copies of the lines

  for (int i = 0; i < invoiceList.Count; i++) { workSheet.Cells[1, 1, totalRows, totalCols].Copy(workSheet.Cells[i * totalRows + 1, 1]); } 
+14
source share

All Articles