我们的接口需要返回一个gird++生成PDF文件的二进制数据,在本地测试都很好,发布到服务器上一直出现“Retrieving the COM class factory for component with CLSID”问题。
最后终于找到问题的解决方法:把程序池里的Enable 32-Bit Applications 设置为True
(ps: 服务器上要安装Grid++的客户端)
另外 附上代码
public struct MatchFieldPairType { public IGRField grField; public int MatchColumnIndex; } public class PrintHelper { // 将 DataTable 的数据转储到 Grid++Report 的数据集中 public static void FillRecordToReport(IGridppReport Report, DataTable dt) { MatchFieldPairType[] MatchFieldPairs = new MatchFieldPairType[Math.Min(Report.DetailGrid.Recordset.Fields.Count, dt.Columns.Count)]; //根据字段名称与列名称进行匹配,建立DataReader字段与Grid++Report记录集的字段之间的对应关系 int MatchFieldCount = 0; for (int i = 0; i < dt.Columns.Count; ++i) { foreach (IGRField fld in Report.DetailGrid.Recordset.Fields) { if (String.Compare(fld.Name, dt.Columns[i].ColumnName, true) == 0) { MatchFieldPairs[MatchFieldCount].grField = fld; MatchFieldPairs[MatchFieldCount].MatchColumnIndex = i; ++MatchFieldCount; break; } } } // 将 DataTable 中的每一条记录转储到 Grid++Report 的数据集中去 Report.PrepareRecordset(); foreach (DataRow dr in dt.Rows) { //Report.PrepareRecordset(); Report.DetailGrid.Recordset.Append(); for (int i = 0; i < MatchFieldCount; ++i) { if (!dr.IsNull(MatchFieldPairs[i].MatchColumnIndex)) MatchFieldPairs[i].grField.Value = dr[MatchFieldPairs[i].MatchColumnIndex]; } Report.DetailGrid.Recordset.Post(); } } }
var report = new GridppReport();
report.LoadFromFile(Server.MapPath("~/eExpressReportbulk.grf"));
PrintHelper.FillRecordToReport(report, printDt); string fileName = ConfigurationSettings.AppSettings["pdfPath"] + shipmentNumber + ".pdf"; //直接调用ExportDirect方法执行导出任务 report.ExportDirect(GRExportType.gretPDF, fileName, false, false); FileStream stream = new FileStream(fileName, FileMode.OpenOrCreate); byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, Convert.ToInt32(stream.Length)); stream.Close();
附上Grid++破解dll: 下载