解决DevExpress GridView导出XLS文件报错:Unable to cast object of type 'Windows.Win32.Messageld' to type 'System.IConvertible'

解决DevExpress GridView导出XLS文件报错:Unable to cast object of type 'Windows.Win32.Messageld' to type 'System.IConvertible'
错误信息

[异常类型】:InvalidCastException
[常信] :Unable to cast object of type 'Windows.Win32.Messageld' to type 'System.IConvertible'.
[异常方法】 :System.Object ChkCast_Helper(Void*, System.Object)
解决方案
重写 DevGridView.cs 文件 ExportData 方法:
C# 全选
public void ExportData(string format, string file)
{
//使用IPrint接口导出文件,需要自动调整列宽度
var xml = Path.Combine(Application.StartupPath, IdHelper.GetId() + ".xml");
try
{
_view.SaveLayoutToXml(xml);
_view.OptionsPrint.AutoWidth = false;//禁用自动宽度
_view.BestFitColumns();//自适应列宽
if (format.ToUpper() == "XLS" || format.ToUpper() == "XLSX")
new DevExportTool().ExportToExcel(file, _view.GridControl);
if (format == "DOCX")
new DevExportTool().ExportToDocx(file, _view.GridControl);
if (format == "PDF")
new DevExportTool().ExportToPDF(file, _view.GridControl);
}
finally
{
if (File.Exists(xml))
{
_view.RestoreLayoutFromXml(xml);
File.Delete(xml);
}
}
}
DevExportTool类 - DevExpress GridView 导出Excel 通用类
https://www.cscode.net/archive/newdoc/771171365036037.html

版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网





