我正在尝试构建一个WPF应用程序,以预览和修改.docx文档。它通过用用户输入替换关键字来对其进行修改。
关键字是$ keyword1 $ * 14和$ keyword2 $ * 10等。
虽然我的应用程序正在显示.docx文档的内容,包括关键字,但我希望它们(关键字)被预览窗格内确切位置上的呈现文本框覆盖。这些文本框将像输入一样来替换覆盖/覆盖的关键字。我希望它足够清楚。
我的问题如下:是否可以动态呈现将自己置于关键字上方的文本框?如果是,我应该在哪里看?
下面的代码适用于.Net WinForms,并使用Office Interop预览RichTextBox中的Word文档。我目前正在尝试使其在WPF中工作。由于Microsoft表示Office Interop不稳定且不受支持,所以我正在考虑尝试OpenXML获得相同的结果。
感谢您阅读这篇文章,并对这个愚蠢的问题表示歉意。我正处于我的编码职业生涯的开始。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace wordtoform
{
public partial class Form1 : Form
{
private readonly object fnd;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
object filename = @"D:\test.docx";
Microsoft.Office.Interop.Word.Application AC = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
object readOnly = true;
object isVisible = true;
object missing = System.Reflection.Missing.Value;
try
{
doc = AC.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
doc.Content.Select();
doc.Content.Copy();
richTextBox1.Paste();
}
catch (Exception ex)
{
MessageBox.Show("ERROR: " + ex.Message);
}
finally
{
doc.Close(ref missing, ref missing, ref missing);
}
}
}
}