手动导出为pdf/Excel/Word [英] Export to pdf/Excel/Word Manually

查看:79
本文介绍了手动导出为pdf/Excel/Word的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在Windows应用程序中显示rdlc报告,现在我需要隐藏报告查看器工具栏,并放置带有Excel/PDF/Word选项的按钮和下拉菜单,因此,无论何时我们选择并单击导出"按钮,报告都应导出,任何人都可以引导我...

Hi,

I am working on windows application in which showing an rdlc report, Now i need to hide the report viewer toolbar and place an button and dropdown with options of Excel/PDF/Word, so when ever we select and click export button, the report should be exported, Can anyone guide me...

推荐答案

1-禁用工具栏.
2-将按钮控件添加到窗体.对于按钮的文本"属性,键入导出到PDF文件".
3-双击按钮控件以为Click事件指定代码.

//变量
警告[]警告;
string [] streamIds;
字符串mimeType = string.Empty;
字符串编码= string.Empty;
字符串扩展名= string.Empty;

//设置报告查看器对象并获取字节数组
ReportViewer查看器=新的ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath ="YourReportHere.rdlc";

byte [] bytes = viewer.LocalReport.Render("PDF",null,out mimeType,out编码,out扩展名,out streamIds,out警告);

//现在,您已经拥有代表PDF报告的所有字节,请对其进行缓冲并将其发送给客户端.
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition","attachment; filename =" + fileName +." +扩展名);
Response.BinaryWrite(bytes); //创建文件
Response.Flush();
1- Disable the toolbar.
2- Add a button control to the form. For the Text property of the button, type Export to PDF File.
3- Double-click the button control to specify code for the Click event.

// Variables
Warning[] warnings;
string[] streamIds;
string mimeType = string.Empty;
string encoding = string.Empty;
string extension = string.Empty;

// Setup the report viewer object and get the array of bytes
ReportViewer viewer = new ReportViewer();
viewer.ProcessingMode = ProcessingMode.Local;
viewer.LocalReport.ReportPath = "YourReportHere.rdlc";

byte[] bytes = viewer.LocalReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamIds, out warnings);

// Now that you have all the bytes representing the PDF report, buffer it and send it to the client.
Response.Buffer = true;
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("content-disposition", "attachment; filename=" + fileName + "." + extension);
Response.BinaryWrite(bytes); // create the file
Response.Flush();


这篇关于手动导出为pdf/Excel/Word的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆