我正在寻找的是正确方向的一点。我正在自学Visual Studio 2010.我有一个带文本框的WPF应用程序。我想做的是将数据传输到word文档然后打印出来。
答案 0 :(得分:0)
来自this link的以下代码应该有所帮助,它将允许您创建一个包含文本" Hello World"并将其保存到" 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);
}