怎样在C#中调用Word文档,并传输数据后打印,请高手赐教! 我想在C#中作一个Word进货表单,并打印出来。但不知该调用什么函数,怎样进行数据传输和打印,还请高手赐教!帮助就给分,不够在加! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public void CreateWordDocument(string FileName) { if(FileName == "") return; wordApp = new Word.ApplicationClass(); wordApp.Visible = true; wordApp.Caption = ""; wordApp.Options.CheckSpellingAsYouType = false; wordApp.Options.CheckGrammarAsYouType = false; Object filename = FileName; Object ConfirmConversions = false; Object ReadOnly = true; Object AddToRecentFiles = false; Object PasswordDocument = System.Type.Missing; Object PasswordTemplate = System.Type.Missing; Object Revert = System.Type.Missing; Object WritePasswordDocument = System.Type.Missing; Object WritePasswordTemplate = System.Type.Missing; Object Format = System.Type.Missing; Object Encoding = System.Type.Missing; Object Visible = System.Type.Missing; Object OpenAndRepair = System.Type.Missing; Object DocumentDirection = System.Type.Missing; Object NoEncodingDialog = System.Type.Missing; wordDoc = wordApp.Documents.Open(ref filename, ref ConfirmConversions, ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate, ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate, ref Format, ref Encoding, ref Visible);// wordDoc = wordApp.Documents.Open(ref filename, ref ConfirmConversions,// ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate,// ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate, ref Format,// ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection, ref NoEncodingDialog); formFields = wordDoc.FormFields; }//参数根据word的版本不同,自己修改!!!//在word里面添加表格,命名,再用下面方法填充各个表格的值就可以。//可以在网上查一查,很多文章的。 /// <summary> /// 填充Word文件的字段值 /// </summary> /// <param name="fieldName">字段名</param> /// <param name="newValue">要显示的字段名的具体值</param> public void FillFieldValueToWord(string fieldName, string newValue) { Object itemName = fieldName; Word.FormField field = formFields.Item(ref itemName); if (field == null) return; string strResult = field.Result.ToString(); string fieldValue = newValue; // 对于不够长度的在后面加空格 if (strResult.Length > newValue.Length) fieldValue = fieldValue.PadRight(strResult.Length,' '); field.Result = fieldValue; } to panda2fw2() :请问您的程序调用的是哪个命名空间呀, 要引用com里的microsoft office *.* Object Liberary *.*是office版本 http://msdn.microsoft.com/library/CHS/dv_wrcore/html/wroriCommonTasksInOfficeProgramming.asp 我自己写了一个封装微软的Word 和 Excel的组件。我可以给你。实现你的功能要求。给我发个短消息联系。或者我的信箱来信 [email protected] 如何能点击一下按钮,弹出来一个文件夹? datagridview如何给指定列写click事件 关于asp.net MENU菜单 一个C#菜鸟的迷茫,求大侠给指个路 怎么用C#实现多客户端的CS模式的SOCKET程序?谢谢了! WinFrom中发送邮件问题 关于SQL语句在C#中应用的问题? @@问一个相当复杂的问题,手软的千万别进!@@ 买了书,没源码,火,谁能提供,我寒假要看! .NET Remoting能被非.NET环境调用吗? 是不是ComboBox的小bug,大家发现没有 运行问题
{
if(FileName == "") return;
wordApp = new Word.ApplicationClass();
wordApp.Visible = true;
wordApp.Caption = "";
wordApp.Options.CheckSpellingAsYouType = false;
wordApp.Options.CheckGrammarAsYouType = false; Object filename = FileName;
Object ConfirmConversions = false;
Object ReadOnly = true;
Object AddToRecentFiles = false;
Object PasswordDocument = System.Type.Missing;
Object PasswordTemplate = System.Type.Missing;
Object Revert = System.Type.Missing;
Object WritePasswordDocument = System.Type.Missing;
Object WritePasswordTemplate = System.Type.Missing;
Object Format = System.Type.Missing;
Object Encoding = System.Type.Missing;
Object Visible = System.Type.Missing;
Object OpenAndRepair = System.Type.Missing;
Object DocumentDirection = System.Type.Missing;
Object NoEncodingDialog = System.Type.Missing; wordDoc = wordApp.Documents.Open(ref filename, ref ConfirmConversions,
ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate,
ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate, ref Format,
ref Encoding, ref Visible);
// wordDoc = wordApp.Documents.Open(ref filename, ref ConfirmConversions,
// ref ReadOnly, ref AddToRecentFiles, ref PasswordDocument, ref PasswordTemplate,
// ref Revert, ref WritePasswordDocument, ref WritePasswordTemplate, ref Format,
// ref Encoding, ref Visible, ref OpenAndRepair, ref DocumentDirection, ref NoEncodingDialog); formFields = wordDoc.FormFields;
}
//参数根据word的版本不同,自己修改!!!//在word里面添加表格,命名,再用下面方法填充各个表格的值就可以。
//可以在网上查一查,很多文章的。
/// <summary>
/// 填充Word文件的字段值
/// </summary>
/// <param name="fieldName">字段名</param>
/// <param name="newValue">要显示的字段名的具体值</param>
public void FillFieldValueToWord(string fieldName, string newValue)
{
Object itemName = fieldName;
Word.FormField field = formFields.Item(ref itemName);
if (field == null) return; string strResult = field.Result.ToString();
string fieldValue = newValue; // 对于不够长度的在后面加空格
if (strResult.Length > newValue.Length)
fieldValue = fieldValue.PadRight(strResult.Length,' '); field.Result = fieldValue;
}
请问您的程序调用的是哪个命名空间呀,