我正在寻找的是正确方向的一点。我正在自学 Visual Studios 2010。我有一个带有文本框的 WPF 应用程序。我想做的是将这些数据传输到 Word 文档中,然后打印出来。
问问题
775 次
1 回答
0
此链接中的以下代码应该会有所帮助,它将允许您使用文本“Hello World”创建一个 Word 文档并将其保存到“D:\MyWord.doc”
object missing = System.Reflection.Missing.Value;
object Visible=true;
object start1 = 0;
object end1 = 0;
ApplicationClass WordApp = new ApplicationClass();
Document adoc = WordApp.Documents.Add(ref missing, ref missing, ref missing, ref missing);
Range rng = adoc.Range(ref start1, ref missing);
try
{
rng.Font.Name = “Georgia”;
rng.InsertAfter(“Hello World!”);
object filename = @”D:\MyWord.doc”;
adoc.SaveAs(ref filename, ref missing, ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
WordApp.Visible = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
于 2012-06-08T17:14:39.053 回答