水晶报表版本:Crystal Reports 10
本地连接的打印机型号:FARGO HDP5000
ASP.NET代码如下:
1 string fileName = FWConfig.GetAppSettingConfig("CardsPrint"); 2 DataSet ds = new DataSet(); 3 DataTable dt = new DataTable(); 4 DataColumn dc1 = new DataColumn("NAME"); 5 DataColumn dc2 = new DataColumn("ORG_NAME"); 6 DataColumn dc8 = new DataColumn("CARD_BOUND"); 7 DataColumn dc3 = new DataColumn("CARD_ENDTIME"); 8 DataColumn dc4 = new DataColumn("PRJT_ITM_NM"); 9 DataColumn dc6 = new DataColumn("PASSPORT_NO"); 10 DataColumn dc7 = new DataColumn("TYPE_NM"); 11 DataColumn dc5 = new DataColumn("STAFFIMAGES"); 12 dt.Columns.Add(dc1); dt.Columns.Add(dc2); 13 dt.Columns.Add(dc3); dt.Columns.Add(dc4); 14 dt.Columns.Add(dc5); dt.Columns.Add(dc6); 15 dt.Columns.Add(dc7); dt.Columns.Add(dc8); 16 DataRow dr = dt.NewRow(); 17 dr["NAME"]="张三"; 18 dr["ORG_NAME"]="广东核电"; 19 dr["CARD_BOUND"]="AA"; 20 dr["CARD_ENDTIME"]="2014-01-04"; 21 dr["PRJT_ITM_NM"]="二和"; 22 dr["PASSPORT_NO"]="430223198808225133"; 23 dr["TYPE_NM"] = "焊工";
dt.Rows.Add(dr); 24 CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument(); 25 rd.Load(Server.MapPath("Controls/RptOutCard.rpt")); 26 rd.PrintOptions.PrinterName = fileName; 27 rd.SetDataSource(dt); 28 rd.PrintToPrinter(1, false, 0, 0);
报错详细信息如下:
错误信息:索引超出了数组界限。
错误描述:
在 CrystalDecisions.CrystalReports.Engine.Migration.PrintOptionsConverter.EROMPaperSizeToDNETPaperSize(CrPaperSizeEnum ePaperSize)
在 CrystalDecisions.CrystalReports.Engine.PrintOptions.get_PaperSize()
在 CrystalDecisions.CrystalReports.Engine.PrintOptions.CopyTo(PrinterSettings printer, PageSettings page)
在 CrystalDecisions.CrystalReports.Engine.FormatEngine.PrintToPrinter(Int32 nCopies, Boolean collated, Int32 startPageN, Int32 endPageN)
在 CrystalDecisions.CrystalReports.Engine.ReportDocument.PrintToPrinter(Int32 nCopies, Boolean collated, Int32 startPageN, Int32 endPageN)
补充下:以前本地打印机为HP LaserJet P2055dn 可以打印 纸张为A4
这跟打印机没有关系。问题应该是出在你的dt和dr数据列的数量不一致。你的dt中有8列,但是你往其中添加的tr却只有7列,肯定会出错啦。
不是这个原因,按照你的说那么在“rd.SetDataSource(dt);”这段代码就会报错!