FileInfo template = new FileInfo(Server.MapPath(@"Xls/Template.xlsx")); using (var package = new ExcelPackage(template)) { var workbook = package.Workbook; //*** Sheet 1 var worksheet = workbook.Worksheets.First(); // Rows1 worksheet.Cells["A3"].Value = "Data1-1"; worksheet.Cells["B3"].Value = "Data1-2"; worksheet.Cells["C3"].Value = "Data1-3"; worksheet.Cells["D3"].Value = "Data1-4"; worksheet.Cells["E3"].Value = "Data1-5"; // Rows2 worksheet.Cells["A4"].Value = "Data2-1"; worksheet.Cells["B4"].Value = "Data3-2"; worksheet.Cells["C4"].Value = "Data3-3"; worksheet.Cells["D4"].Value = "Data3-4"; worksheet.Cells["E4"].Value = "Data3-5"; package.SaveAs(new FileInfo(Server.MapPath(@"Xls/myExcel.xlsx"))); }
FileInfo template = new FileInfo(Server.MapPath(@"Xls/Template.xlsx")); using (var package = new ExcelPackage(template)) { var workbook = package.Workbook; //*** Sheet 1 var worksheet = workbook.Worksheets.First(); for (int i = 3; i <= 10; i++) { worksheet.Cells["A" + i].Value = "Data"; worksheet.Cells["B" + i].Value = "Data"; worksheet.Cells["C" + i].Value = "Data"; worksheet.Cells["D" + i].Value = "Data"; worksheet.Cells["E" + i].Value = "Data"; } package.SaveAs(new FileInfo(Server.MapPath(@"Xls/myExcel.xlsx"))); }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท