如何在excel文件中排除Dhtmlxgrid的隐藏列
本文关键字:Dhtmlxgrid 隐藏 排除 excel 文件 | 更新日期: 2023-09-27 18:01:33
无论如何,在excel文件中排除DhtmlxGrid的隐藏列吗?
现在当我导出到excel时,它还包括隐藏在excel中的列。请建议。
MVC3
in View:
on a button click my code:
_grid.toExcel('@Url.Content("~/Shared/ExportGridToExcel?TableName")' +'Doc');
in Controller:
public ActionResult ExportGridToExcel(string TableName)
{
var generator = new ExcelWriter();
var xml = this.Request.Form["grid_xml"];
xml = this.Server.UrlDecode(xml);
var stream = generator.Generate(xml);
return File(stream.ToArray(), generator.ContentType, TableName + ".xls");
}
找到此方法并替换此
public ActionResult GenerateExcel()
{
var generator = new ExcelWriter();
var xml = this.Request.Form["grid_xml"];
xml = this.Server.UrlDecode(xml);
var xmlObj = XDocument.Parse(xml);
foreach (var x in xmlObj.Descendants("columns").ElementAt(0).Descendants("column"))
{
var w = x.Attribute("width").Value;
if (Convert.ToString(w).Equals("0")) { x.SetAttributeValue("hidden", "true"); }
}
xml = xmlObj.ToString();
var stream = generator.Generate(xml);
return File(stream.ToArray(), generator.ContentType, "grid.xlsx");
}
如果成功的话,别忘了把这个标记为答案
使用setColumnHidden api在导出调用之前隐藏列,然后显示列。隐藏列不包括在导出结果中。