C#NET2008 Use Microsoft WORD 2003

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Lennie Kuah

    #1

    C#NET2008 Use Microsoft WORD 2003

    Hi Good Guys,
    I need your help. Please help me.
    I am using C#NET2008 and Window Application to print Customer Order Transactio onto Microsoft WORD 2003 document.

    This is the expect result on WORD Document but it's not happening:

    CustomerID : S9921
    CustomerName : John Thompson
    Address : 63 Westcoast Road
    City : WestMall
    ----------------------------------------------------------
    List below are the error message and the coding that causes it:


    Error 1 Only assignment, call, increment, decrement, and new object expressions can be used as a statement

    Above error message caused by this coding trying to insert new line after printing it
    objWord.Selecti on.TypeParagrap h; < -- error

    -----------------------------------------------------------
    Error 2 'Word._Document .Range(ref object, ref object)' is a 'method', which is not valid in the given context

    Above error message caused by this coding when trying to print the LABEL and the Data on the same line
    objdoc.Range.Te xt = strTextLabel + this.txtCustID; < --- error

    ---------------------------------------------
    Here are the overall coding in C#NET3008

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Data.SqlClient;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using Microsoft.Office.Core;
    
    
    private void btnPrintWORD_Click(object sender, EventArgs e)
     {
       object objmissing = System.Reflection.Missing.Value;
       Word.Application objWord = new Word.Application();
       Word.Document objdoc;
    
       objWord.Visible = true;
       objdoc = objWord.Documents.Add(ref objmissing, ref objmissing, ref objmissing, ref objmissing);
       
       //variables         
       string strTextLabel;        
       int intcounter;
           
      //------Print CustomerID ------- 
        strTextLabel ="CustomerID";
        for ( intcounter = 1; intcounter <= 18; intcounter ++)
          {
            strTextLabel += " ";   //add spaces
            if (intcounter ==17)
               {
                  strText += ":  "  
     objdoc.Range.Text = strTextLabel +this.txtCustID; <- error
     objWord.Selection.TypeParagraph;   < - error
                break;
                }
       }
                    
       //----- Print CustomerName ------
       strTextLabel = "CustomerName";  //label title
       for (intcounter = 1; intcounter <=18; intcounter ++)
          {
           strTextLabel = " ";
          if (intcounter == 17)
           {
             strTextLabel += ":  " 
          objWord.Selection.Text = strText + strCompName;
          objWord.Selection.TypeParagraph;
          break;
           }
        }
    
        }
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    The first one you mentioned seems to be a method, not a property. Methods have parenthesis at the end.

    Range also seems to be a method. Try looking these fields up on the MSDN.

    Comment

    Working...