Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Excel + C#

Excel + C#

Scheduled Pinned Locked Moved C#
csharpcomdata-structures
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    GrgBalden
    wrote on last edited by
    #1

    Hi all, I've been given source code for a program that created a form post from values within an excel document, however I keep getting the following errors: Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.Excel.Range.get_Value(object)' or 'Microsoft.Office.Interop.Excel.Range.set_Value(object, object)' I've had a root through the MSDN site, and cant seem to work out whats wrong:

    private void btnBatchExecute_Click(object sender, System.EventArgs e)
    {

            Excel.Application xlApp;
    		Excel.Workbook xlWorkbook;
    		Excel.Worksheet xlWorkSheet;
    		Excel.Range xlRange;
    
    		string method;
    		string postString;
    		string\[\] values;
    		string returnString;
    
    		XmlDocument xDoc = new XmlDocument();
    		
    		try
    		{
    			//Start Excel and get Application object.
    			xlApp = new Excel.ApplicationClass();
    			xlApp.Visible = true;
    
                string thisFileName = txtFileName.Text;
    
                xlWorkbook = xlApp.Workbooks.Open(thisFileName,
            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
            Type.Missing, Type.Missing, Type.Missing, Type.Missing,
            Type.Missing, Type.Missing);
    
                xlWorkSheet = (Excel.Worksheet)xlWorkbook.ActiveSheet;
    
    			
    			//int i = 5;
    			for(int i = 5;;i++)
    			{
    				xlRange = xlWorkSheet.get\_Range(xlWorkSheet.Cells\[i,2\],xlWorkSheet.Cells\[i,52\]);
    
    				values = ConvertToStringArray((System.Array)xlRange.Cells.Value);
    
    				if(values\[0\]=="") break;
    
    				postString = "ESERIES\_FORM\_ID=AUTHENTICATE\_3&CTRL\_TYPEINDICATOR=C&CTRL\_SEARCHCONSENT=Y&CTRL\_CHANNEL=I&CTRL\_CALLTYPE=I";
    				// Main App Name
    				postString+="&NAME\_TITLE="+values\[0\];
    				postString+="&NAME\_FORENAME="+values\[1\];
    				postString+="&NAME\_INITIALS="+values\[2\];
    				postString+="&NAME\_SURNAME="+values\[3\];
    				postString+="&NAME\_SUFFIX="+values\[4\];
    				postString+="&NAME\_DATEOFBIRTH\_DD="+("0"+values\[5\]).Substring(("0"+values\[5\]).Length-2);
    				postString+="&NAME\_DATEOFBIRTH\_MM="+("0"+values\[6\]).Substring(("0"+values\[6\]).Length-2);
    				postString+="&NAME\_DATEOFBIRTH\_CCYY="+values\[7\];
    

    // postString+="&NAME_DATEOFBIRTH="+values[7]+("0"+values[6]).Substring(("0"+values[6]).Length-2)+("0"+values[5]).Substring(("0"+values[5]).Length-2);

    				// Alias - need to check if title supplied fi
    
    G 1 Reply Last reply
    0
    • G GrgBalden

      Hi all, I've been given source code for a program that created a form post from values within an excel document, however I keep getting the following errors: Property, indexer, or event 'Value' is not supported by the language; try directly calling accessor methods 'Microsoft.Office.Interop.Excel.Range.get_Value(object)' or 'Microsoft.Office.Interop.Excel.Range.set_Value(object, object)' I've had a root through the MSDN site, and cant seem to work out whats wrong:

      private void btnBatchExecute_Click(object sender, System.EventArgs e)
      {

              Excel.Application xlApp;
      		Excel.Workbook xlWorkbook;
      		Excel.Worksheet xlWorkSheet;
      		Excel.Range xlRange;
      
      		string method;
      		string postString;
      		string\[\] values;
      		string returnString;
      
      		XmlDocument xDoc = new XmlDocument();
      		
      		try
      		{
      			//Start Excel and get Application object.
      			xlApp = new Excel.ApplicationClass();
      			xlApp.Visible = true;
      
                  string thisFileName = txtFileName.Text;
      
                  xlWorkbook = xlApp.Workbooks.Open(thisFileName,
              Type.Missing, Type.Missing, Type.Missing, Type.Missing,
              Type.Missing, Type.Missing, Type.Missing, Type.Missing,
              Type.Missing, Type.Missing, Type.Missing, Type.Missing,
              Type.Missing, Type.Missing);
      
                  xlWorkSheet = (Excel.Worksheet)xlWorkbook.ActiveSheet;
      
      			
      			//int i = 5;
      			for(int i = 5;;i++)
      			{
      				xlRange = xlWorkSheet.get\_Range(xlWorkSheet.Cells\[i,2\],xlWorkSheet.Cells\[i,52\]);
      
      				values = ConvertToStringArray((System.Array)xlRange.Cells.Value);
      
      				if(values\[0\]=="") break;
      
      				postString = "ESERIES\_FORM\_ID=AUTHENTICATE\_3&CTRL\_TYPEINDICATOR=C&CTRL\_SEARCHCONSENT=Y&CTRL\_CHANNEL=I&CTRL\_CALLTYPE=I";
      				// Main App Name
      				postString+="&NAME\_TITLE="+values\[0\];
      				postString+="&NAME\_FORENAME="+values\[1\];
      				postString+="&NAME\_INITIALS="+values\[2\];
      				postString+="&NAME\_SURNAME="+values\[3\];
      				postString+="&NAME\_SUFFIX="+values\[4\];
      				postString+="&NAME\_DATEOFBIRTH\_DD="+("0"+values\[5\]).Substring(("0"+values\[5\]).Length-2);
      				postString+="&NAME\_DATEOFBIRTH\_MM="+("0"+values\[6\]).Substring(("0"+values\[6\]).Length-2);
      				postString+="&NAME\_DATEOFBIRTH\_CCYY="+values\[7\];
      

      // postString+="&NAME_DATEOFBIRTH="+values[7]+("0"+values[6]).Substring(("0"+values[6]).Length-2)+("0"+values[5]).Substring(("0"+values[5]).Length-2);

      				// Alias - need to check if title supplied fi
      
      G Offline
      G Offline
      gg4237
      wrote on last edited by
      #2

      Hi, Easiest and fastest way to deal with Excel in C# is by using 3rd party component. It's much faster and easier way then Excel Interop. Try using GemBox Excel component for .NET- component is free for commercial use but with limit of 150 rows. Here you can see a list of reason why GemBox.Spreadsheet is much better tool to work with Excel then Excel Interop.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups