我创建了一个包含一些数据的报告。我不希望用户必须单击表单导出按钮并将数据导出到 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();
}
有什么建议么?