Excel + C#
-
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
-
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
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.