sydneyguy
asked on
getting the data out of an array into a string, using c# have data in array need to get it into a sting
have the below code pulling the data out of the spread sheet and getting it into an array,
but now need to get it into a single varable.
have tried
String abc;
abc = excelCell[1,1];
but throws up a Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelShee ts.get_Ite m(currentS heet);
Excel.Range excelCell = (Excel.Range)excelWorkshee t.get_Rang e("A1", "E100");
excelCell[1,2]= "dfddf";
// MessageBox.Show(excelCell[ 1][1].ToSt ring());
String abc;
abc = excelCell[1,1];
but now need to get it into a single varable.
have tried
String abc;
abc = excelCell[1,1];
but throws up a Cannot implicitly convert type 'object' to 'string'. An explicit conversion exists (are you missing a cast?)
Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelShee
Excel.Range excelCell = (Excel.Range)excelWorkshee
excelCell[1,2]= "dfddf";
// MessageBox.Show(excelCell[
String abc;
abc = excelCell[1,1];
ASKER
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
have read and looked through the code that you suggested but seems like i have to rebuild it with the new code. i already have it going i just need to get the data out of the System.__ComObject i can see it in the debug result it must be easy to get it from here.
would prefer to get this going than to we write the entire module
any ideas
would prefer to get this going than to we write the entire module
any ideas
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the above solution got a bit complecated but got the below code up and running now and can access the string at what ever location that i wish so thanks for you help
String filePath = @"C:\aeltest\@mill.csv";
Microsoft.Office.Interop.E xcel.Appli cation excelApp = new Microsoft.Office.Interop.E xcel.Appli cation();
Microsoft.Office.Interop.E xcel.Workb ook excelWorkbook = excelApp.Workbooks.Open(fi lePath, 0, true, 5, "", "", true, Microsoft.Office.Interop.E xcel.XlPla tform.xlWi ndows, "\t", false, false, 0, true, 1, 0);
Microsoft.Office.Interop.E xcel.Sheet s excelSheets = excelWorkbook.Worksheets;
Microsoft.Office.Interop.E xcel.Works heet excelSheet = (Microsoft.Office.Interop. Excel.Work sheet)exce lSheets.ge t_Item(1);
Microsoft.Office.Interop.E xcel.Range range = (Microsoft.Office.Interop. Excel.Rang e)excelShe et.Cells[1 , 1];
string cellValue = range.Value2.ToString();
String filePath = @"C:\aeltest\@mill.csv";
Microsoft.Office.Interop.E
Microsoft.Office.Interop.E
Microsoft.Office.Interop.E
Microsoft.Office.Interop.E
Microsoft.Office.Interop.E
string cellValue = range.Value2.ToString();
ASKER
thanks for the help did not end up using either of the answers as i worked out a solution that fixed my problem as you can see in the above text, thanks for pointing me in the right direction
Since you want to assign to a String variable, do the same thing:
abc = excelCell[1,1].ToString();