利用Net组件打印
利用Net组件
; 优点这种打印方式对于格式变化大数据量小的应用来说非常合适
; 缺点
– 需要客户端安Net framework组件
– Xml的解析上如果文件较大速度上不是很理想
– 页面首次加载时会有明显的延时
使用XSL和XSLT转换Xml
; XSL扩展样式表语言可以通过它来把Xml转换为其他的文本格式
; XSL转换包括发现或者选择一个模式匹配通过使用XPath选择一个结果集然后对结果集中的每一项为这些匹配定义结果输出
; XSL是一个功能强大的工具可以把Xml转换成任何你想要的格式
【参考代码】
以下是引用片段
XslTransform xslt = new XslTransform();
xsltLoad(ServerMapPath( StudentsToHTMLxsl) );
XPathDocument XDoc = new XPathDocument(ServerMapPath( StudentsXml ));
XmlWriter writer = new XmlTextWriter( serverMapPath(Studentshtml) SystemTextEncodingUTF );
xsltTransform( XDoc null writer );
writerClose();
ResponseRedirect(Studentshtml);
利用ActiveX控件打印
利用第三方控件
; 自己开发控件这种方式很多商用软件采用这种方式写成控件后已经无所谓是在web中使用还是应用程序中使用了
; 优点打印方式非常灵活基本上程序能做到的web也能做得到
; 缺点客户端需要安装组件部署不是很方便
使用水晶报表
; 用户仅需要Web 浏览器就可以查看报表
; 报表查看器控件可以是应用程序中众多控件之一
; 与报表轻松交互
; 用户可将报表导出为Microsoft word 和Excel 格式以及PDFHTML 和Crystal Reports for visual Studio Net格式
; 可以使用报表控件直接打印
【实例代码】
以下是引用片段
//水晶报表的填充省略连接代码
myReport ReportDoc = new myReport();
ReportDocSetDataSource(ds);
CrvReportSource = ReportDoc;
//输出为指定类型文件
CrystalDecisionsSharedDiskFileDestinationOptions DiskOpts = new CrystalDecisionsSharedDiskFileDestinationOptions();
ReportDocExportOptionsExportDestinationType = CrystalDecisionsSharedExportDestinationTypeDiskFile;
string strFileName = serverMapPath(Output);
switch (ddlFormatSelectedItemText)
{
case Rich Text (RTF):
ReportDocExportOptionsExportFormatType = CrystalDecisionsSharedExportFormatTypeRichText;
DiskOptsDiskFileName =strFileName + rtf;
break;
case Portable Document (PDF):
ReportDocExportOptionsExportFormatType = CrystalDecisionsSharedExportFormatTypePortableDocFormat;
DiskOptsDiskFileName = strFileName + pdf;
break;
case MS word (DOC):
ReportDocExportOptionsExportFormatType = CrystalDecisionsSharedExportFormatTypeWordForWindows;
DiskOptsDiskFileName = strFileName + doc;
break;
case MS excel (XLS):
ReportDocExportOptionsExportFormatType = CrystalDecisionsSharedExportFormatTypeExcel;//
DiskOptsDiskFileName = strFileName + xls;
break;
default:
break;
}
ReportDocExportOptionsDestinationOptions = DiskOpts;
ReportDocExport();
//打印
// 指定打印机名称
string strPrinterName;
strPrinterName = @Canon BubbleJet BJCSP;
// 设置打印页边距
PageMargins margins;
margins = ReportDocPrintOptionsPageMargins;
marginsbottomMargin = ;
marginsleftMargin = ;
marginsrightMargin = ;
marginstopMargin = ;
ReportDocPrintOptionsApplyPageMargins(margins);
//应用打印机名称
ReportDocPrintOptionsPrinterName = strPrinterName;
// 打印 // 打印报表将startPageN 和endPageN
// 参数设置为 表示打印所有页
ReportDocPrintToPrinter( false);
[] [] [] []