【问题标题】:Import Word Document Data to RDLC Report将 Word 文档数据导入 RDLC 报告
【发布时间】:2019-03-17 16:32:07
【问题描述】:

目标

将 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 文本,也得到了奇怪的文本字符:

版本:1.0 开始HTML:0000000207 结束HTML:0000068119 开始片段:0000047434 结束片段:0000068079 SourceURL:file://server1/folder1/file1.docx

??????????

是否可以将 Word 模板导入 RDLC 报告?

【问题讨论】:

  • 您需要了解Clipboard.GetData(DataFormats.Html) 检索到的内容,请参阅:HTML Clipboard Format
  • @TnTinMn 我希望保留所述 Word 文档的完整格式并将内容粘贴到 rdlc 中。这就是为什么我认为 HTML 会是最好的

标签: vb.net import ms-word rdlc reportviewer


【解决方案1】:

试试这个

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 文件

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 1970-01-01
    • 2023-02-14
    • 2011-07-14
    • 1970-01-01
    相关资源
    最近更新 更多