Tag: mvc

在导出Excel之前添加标题

正在使用以下函数导出Excel文件。它工作正常。我从SQL数据库检索logging到数据表,并导出Excel工作表。 public ActionResult ExporttoExcel() { DataTable dt = new DataTable(); SqlConnection con = new SqlConnection("Connection string here"); con.Open(); SqlCommand cmd = new SqlCommand("select * from Exportxcel", con); dt.Load(cmd.ExecuteReader()); int total = 0; foreach (DataRow row in dt.Rows) { int salaryvalue = Convert.ToInt32(row["Salary"]); total = salaryvalue + total; } dt.Rows.Add(new object[] { "", "Total", total }); […]