c# - 如何在报表查看器中直接导出到 word 文档

标签 c# reportviewer

我创建了一个包含一些数据的报告。我不希望用户必须单击表单导出按钮并将数据导出到 word 文档。该文件保存良好问题是当我打开文档时它只是一堆垃圾而不是应该保存的报告。

我的保存按钮是这样的:

SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.InitialDirectory = @“C:\”;
saveFileDialog.RestoreDirectory = true;
savefileDialog.Title = “Browse Text Files”;
saveFileDialog.DefaultExt = “docx”;

saveFileDialog.Filter = “Word Doc (*.docx)|*.docx|PDF (*.pdf)| *.pdf”;
saveFileDialog.checkFileExists = false;
saveFileDialog.CheckPathExists = true;

Warning[] warnings;
string[] streams;
string mimeType;
string encoding;
string extension;

byte[] bytes = reportViewer1.LocalReport.Render(“Word”, null, out mimeType, out encoding, out extension, out streams, out warnings);

if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
var filename = saveFileDialog.FileName;
System.IO.FileStream file = new FileStream(filename, FileMode.Create);
file.Write(bytes, 0, bytes.length);
file.close();
}

有什么建议吗?

最佳答案

我知道这是旧的并且已经回答了(某种程度上),但我偶然发现了这个问题,您需要在 Render 调用中使用“WORDOPENXML”而不是“Word”。这样它将导出到 docx。

使用 ListRenderingExtensions 查看可用的扩展。

关于c# - 如何在报表查看器中直接导出到 word 文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12184042/

相关文章:

c# - 从WCF应用程序传递回WPF应用程序的ReportServer的byte []反序列化上没有BinaryHeader错误

c# - 无法在每个其他请求中创建 SSL/TLS 安全通道

c# - 了解 Ninject 的好处

c# - 如何设置migradoc图表x轴刻度线

textbox - Report (.rdlc)/ReportViewer - 当文本框的文本太长时如何将其分成多个部分?

asp.net - ASP.net Web 应用程序中 SSRS 报告自定义参数的可用/默认值

asp.net - 如何在reportviewer控件上从asp.net调用打印?

c# - Visual Studio 2010 的 ReportViewer 组件是否对应于 SQL Server Reporting Services 2008 或 2008 R2?

c# - bool 到图像转换器不起作用。图像不变

c# - 跨平台应用程序中的 BinaryFormatter