目标
将 Word 文档数据(文本、要点、图像)附加到 RDLC 报告。
尝试
目前,我(不成功)通过 ReportParameter 将 Word 文档数据附加到报表末尾。
...
ReportViewer1.LocalReport.SetParameters(New ReportParameter("rpReportTemplate", GetWordData(WordDocumentPath)))
...
Public Function GetWordData(ByVal wordPath As String) As String
Dim MyWord As Microsoft.Office.Interop.Word.Application
Dim sConvertedString As String = ""
MyWord = CreateObject("Word.application")
MyWord.Visible = False
MyWord.Documents.Open(wordPath)
MyWord.Windows(1).Selection.WholeStory()
MyWord.Windows(1).Selection.Copy()
MyWord.Quit()
sConvertedString = Clipboard.GetData(DataFormats.Html)
Return sConvertedString
End Function
<小时/>
我似乎无法将图像放入报告中。我得到了一些奇怪的 HTML 文本,也得到了奇怪的文本字符:
Version:1.0 StartHTML:0000000207 EndHTML:0000068119 StartFragment:0000047434 EndFragment:0000068079 SourceURL:file://server1/folder1/file1.docx
â€
是否可以将 Word 模板导入 RDLC 报告?
最佳答案
试试这个
protected void Page_Load(object sender, EventArgs e)
{
LocalReport report = new LocalReport();
report.ReportPath = "Report1.rdlc";
ReportDataSource rds = new ReportDataSource();
rds.Name = "DataSet1";
//This refers to the dataset name in the RDLC file
rds.Value = EmployeeRepository.GetAllEmployees();
report.DataSources.Add(rds);
Byte[] mybytes = report.Render("WORD");
//Byte[] mybytes = report.Render("PDF"); for exporting to PDF
using (FileStream fs = File.Create(@"D:\wordfile.doc"))
{
fs.Write(mybytes, 0, mybytes.Length);
}
}
并将您的 rdlc 报告导出到 word 文件
关于vb.net - 将Word文档数据导入RDLC报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52779592/