翻譯|使用教程|編輯:胡濤|2022-04-20 16:01:31.283|閱讀 191 次
概述:本文將向您展示如何使用 Spire.Doc 通過比較兩個 Word 文檔來獲取差異。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
我們已經介紹了如何在 C# 和 VB.NET 中比較兩個 Word 文檔。從 Spire.Doc V8.12.14 開始,它支持在結構列表中獲取兩個 Word 文檔之間的差異。本文將向您展示如何使用 Spire.Doc 通過比較兩個 Word 文檔來獲取差異。
郵件合并通常用于批量打印報表,例如財務報表、工資單或成績單。合并后的文件可以通過電子郵件發送。
在本文中,我將展示一種通過 Spire.Doc 生成郵件合并報告的方法。
我們需要完成以下 3 個步驟來生成我們的報告。
每個步驟都包含幾個子步驟,在#2 和#3 中我們需要編寫一些代碼。
模板是可重用的文檔。它呈現了我們報告的模式。我們可以修改它來更改我們的報告,而無需修改任何代碼。
注意:在本節中,所有表均指 DataTable 實例,而不是數據庫中的物理表。
首先,我們可以在 MS Word 或其他程序中創建模板。這是我們需要創建的模板。數據將填寫在紅方。
其次,將 mail-merge-field 作為占位符插入紅塊中。郵件合并字段分為三種類型:
在此 Silverlight 應用程序中,我們僅使用 GeneralField。如下圖所示。將郵件合并字段作為占位符插入紅塊。
Spire.Doc 提供來自各種數據源的合并數據。該程序合并用戶填充的字符串數組中的數據。
using Spire.Doc; using System; using System.IO; namespace MailMerge { class Program { static void Main(string[] args) { String[] fieldNames = new String[] { "Contact Name", "Fax", "From", "Date", "Subject", "Content" }; DateTime faxDate = this.datePickerFaxDate.SelectedDate.HasValue ? this.datePickerFaxDate.SelectedDate.Value : DateTime.Now; String[] fieldValues = new String[] { this.textBoxTo.Text, this.textBoxFax.Text, this.textBoxFrom.Text, faxDate.ToShortDateString(), this.textBoxSubject.Text, this.textBoxContent.Text }; this.documentTemplate.MailMerge.Execute(fieldNames, fieldValues); bool? result = this.saveFileDialog.ShowDialog(); if (result.HasValue && result.Value) { using (Stream stream = this.saveFileDialog.OpenFile()) { //this.documentTemplate.SaveToStream(stream, FileFormat.Doc); this.documentTemplate.SaveToFile(stream, FileFormat.Doc); } } } } }
在本節中,我們需要編寫一些代碼來調用 Spire.Doc 來合并我們的數據和模板。 this.documentTemplate.MailMerge.Execute(fieldNames, fieldValues); bool? result = this.saveFileDialog.ShowDialog(); if (result.HasValue && result.Value) { using (Stream stream = this.saveFileDialog.OpenFile()) { //this.documentTemplate.SaveToStream(stream, FileFormat.Doc); this.documentTemplate.SaveToFile(stream, FileFormat.Doc); } }
歡迎下載|體驗更多E-iceblue產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn