用代码中的值替换合并字段

发布于 2024-11-17 20:19:21 字数 160 浏览 2 评论 0原文

我有这样的文本: Hello <>; <> 其中 <>和<>是文档中的合并字段,我有一个数组中的客户列表,我想将它们分配给这些字段。我该怎么做?

I have this Text: Hello <<FirstName>> <<LastName>> in which the <> and <> are merge fields in a document, and I have a list of customers in an array which I want to allocate them to these fields. How do I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌梦深 2024-11-24 20:19:21

我不知道你的数组是如何构造的,但是:

        Dim text As String = "Hello <<FirstName>> <<LastName>>"
        Dim foo() As String 
        For i As Integer = 0 To UBound(foo)
            Dim modifiedText As String = text
            modifiedText = Replace(modifiedText, "<<FirstName>>", foo(i,0), 1, -1, vbTextCompare)
            modifiedText = Replace(modifiedText, "<<LastName>>", foo(i,1), 1, -1, vbTextCompare)
            Console.WriteLine(modifiedText)

        Next

I don't know how you have your array structured, but:

        Dim text As String = "Hello <<FirstName>> <<LastName>>"
        Dim foo() As String 
        For i As Integer = 0 To UBound(foo)
            Dim modifiedText As String = text
            modifiedText = Replace(modifiedText, "<<FirstName>>", foo(i,0), 1, -1, vbTextCompare)
            modifiedText = Replace(modifiedText, "<<LastName>>", foo(i,1), 1, -1, vbTextCompare)
            Console.WriteLine(modifiedText)

        Next
闻呓 2024-11-24 20:19:21

看起来您想要 使用 VB.NET 合并 Word 文档中的字段值。如果我是正确的,您可以尝试 Aspose.Words for .NET。该组件为此类合并场景提供了全面的解决方案。

这里还有一个简单的代码片段:

' Open an existing document.

Dim doc As New Document(MyDir & "MailMerge.ExecuteArray.doc")



' Fill the fields in the document with user data.

doc.MailMerge.Execute(New String() {"FullName", "Company", "Address", "Address2", "City"}, New Object() {"James Bond", "MI5 Headquarters", "Milbank", "", "London"})



' Send the document in Word format to the client browser with an option to save to disk or open inside the current browser.

doc.Save(Response, "PersonalizedLetter Out.doc", ContentDisposition.Inline, Nothing)

披露:我在 Aspose 担任开发人员传播者。

It looks like you want to merge the field values in a Word document using VB.NET. If I'm correct, you may try Aspose.Words for .NET. This component provides a comprehensive solution for such merging scenarios.

Here is a simple code snippet as well:

' Open an existing document.

Dim doc As New Document(MyDir & "MailMerge.ExecuteArray.doc")



' Fill the fields in the document with user data.

doc.MailMerge.Execute(New String() {"FullName", "Company", "Address", "Address2", "City"}, New Object() {"James Bond", "MI5 Headquarters", "Milbank", "", "London"})



' Send the document in Word format to the client browser with an option to save to disk or open inside the current browser.

doc.Save(Response, "PersonalizedLetter Out.doc", ContentDisposition.Inline, Nothing)

Disclosure: I work as developer evangelist at Aspose.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文