当我将数据从 List<> 导入到 excel 时,它会自动在 excel file.How 中添加边框以从 excel 文件中删除该边框?

When I import the data from List<> to excel it autometically add the border in a excel file.How to remove that Border from excel file?

我使用了下面的代码。将数据从 List<> 导入到 excel 工作正常,但它将 黑线边框 添加到 excel file.how 我可以从中删除该边框吗excel 文件?

if (id != null)
{
          int mid = Convert.ToInt32(clsPasswordHelper.Decryptdata(id));
          var objMySavedMedicinePricesResults = db.MedicineRequestDownload(mid).ToList();  

          GridView gv = new GridView();
          gv.DataSource = objMySavedMedicinePricesResults;
          gv.DataBind();
          Response.ClearContent();
          Response.Buffer = true;
          Response.AddHeader("content-disposition", "attachment; filename=" + DateTime.Now.ToShortDateString() + "_MedicinePrice.xls");
          Response.ContentType = "application/ms-excel";
          Response.Charset = "";
          StringWriter sw = new StringWriter();
          HtmlTextWriter htw = new HtmlTextWriter(sw);
          gv.RenderControl(htw);
          Response.Output.Write(sw.ToString());
          Response.Flush();
          Response.End();
          return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}

您使用的方式生成 html 输出和客户端打开 html 文件作为 excel.On 这样您就不能设置 excel 单元格和 table. 使用 ClosedXML library.with 这个库你可以创建一个有效的 excel 文件并且你可以修改导出的样式 excel.

示例代码:

var workbook = new XLWorkbook();
var worksheet = workbook.Worksheets.Add("Sample Sheet");
worksheet.Cell("A1").Value = "Hello World!";
workbook.SaveAs("HelloWorld.xlsx");