我已创建了它的一些数据的报告。 我不希望用户必须点击表格导出按钮和数据导出到Word文档。 该文件保存精美的问题是,当我走在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();
}
有什么建议么?