C# 从列表导入数据时<&燃气轮机;excel自动在excel文件中添加边框。如何从excel文件中删除边框?

C# 从列表导入数据时<&燃气轮机;excel自动在excel文件中添加边框。如何从excel文件中删除边框?,c#,excel,excel-import,C#,Excel,Excel Import,我使用了下面的代码。将数据从列表导入excel工作正常,但会将黑线边框添加到excel文件中。如何从excel文件中删除该边框 if (id != null) { int mid = Convert.ToInt32(clsPasswordHelper.Decryptdata(id)); var objMySavedMedicinePricesResults = db.MedicineRequestDownload(mid).ToList();

我使用了下面的代码。将数据从列表导入excel工作正常,但会将黑线边框添加到excel文件中。如何从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输出和客户端以excel格式打开html文件的方式。使用这种方式,您无法设置excel单元格和表格的样式。 使用库。使用此库,您可以创建有效的excel文件,并且可以修改导出excel的样式

示例代码:

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

您使用的生成html输出和客户端以excel格式打开html文件的方式。使用这种方式,您无法设置excel单元格和表格的样式。 使用库。使用此库,您可以创建有效的excel文件,并且可以修改导出excel的样式

示例代码:

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

代码在数据周围创建方形黑边框代码在数据周围创建方形黑边框