vb.net - 将Word文档数据导入RDLC报告

标签 vb.net import ms-word rdlc reportviewer

目标

将 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/

相关文章:

vba - 如何打开(并保存)Word文档中的所有嵌入式文档?

python - 在 Python 中解析 Word 文档

vb.net - Propertygrid 中的复选框列表

VB.NET 创建一个带有可选输入的类

arrays - 在VB.NET中将char数组转换为字符串数组

android - 当我尝试在 Android Studio 中导入项目时没有任何反应

import - 在 Golang 中导入模块时如何捕获错误?

javascript - 为什么发布后没有定义任何集合?

excel - 我想从word中提取段落并将其导入到excel电子表格中的单元格中,保留项目符号和字母

vb.net - 如何在vb.net中将字符a变成b