我想在C#中作一个Word进货表单,并打印出来。但不知该调用什么函数,怎样进行数据传输和打印,还请高手赐教!帮助就给分,不够在加!

解决方案 »

  1.   

    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;
    }
      

  2.   

    to panda2fw2() :
    请问您的程序调用的是哪个命名空间呀,
      

  3.   

    要引用com里的microsoft office *.* Object Liberary *.*是office版本
      

  4.   

    http://msdn.microsoft.com/library/CHS/dv_wrcore/html/wroriCommonTasksInOfficeProgramming.asp
      

  5.   

    我自己写了一个封装微软的Word 和 Excel的组件。我可以给你。实现你的功能要求。给我发个短消息联系。或者我的信箱来信 [email protected]