我如何直接导出到Word文档中的报表查看器 [英] How do I export directly to a word document in report viewer

查看:124
本文介绍了我如何直接导出到Word文档中的报表查看器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已创建了它的一些数据的报表。我不希望用户必须点击表格导出按钮和数据导出到Word文档。该文件保存精美的问题是,当我走在Word中打开该文档的只是一堆垃圾,而不是应该保存的报告。

I have created a report with some data in it. I do not want the user to have to click on the forms export button and export the data to a word document. The file saves fine the problem is when I go to open the document in word its just a bunch of garbage instead of the report that was supposed to save.

我保存按钮看起来是这样的:

my save button looks like this:

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();
}

有什么建议?

推荐答案

有关Word只出口到旧的Word格式的LocalReport.Render(第6版,我相信)。不支持基于XML(DOCX扩展)较新的,开放的格式。所以通过具有的docx扩展,Word正在期待新的格式,而不是旧的,所以它解释一切,垃圾。顺便说一句,更改Word文档的docx扩展成.zip文件,解压缩的内容,并有导致夹周围一捅。这是很有意思的是,现在可见的。

The LocalReport.Render for Word only exports to the older Word format (version 6, I believe). The newer, open formats based on XML (docx extension) are not supported. So by having a docx extension, Word is expecting the newer format, not the old one, so it interprets everything as rubbish. As an aside, change the docx extension on a Word document into .zip, extract the contents and have a poke around the resulting folders. It is quite interesting what is now visible.

这篇关于我如何直接导出到Word文档中的报表查看器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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