使用Gird++打印出現“Retrieving the COM class factory for component with CLSID”的解決辦法


我們的接口需要返回一個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:  下載

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM