Hi,
I was wondering if anybody can share a code snippet to read an excel file into a 2D array. I don't want to use the data connector since I have to do some manipulation of the data in the array.
Or is it doable using the data connector as well?
Thanks,
Excel into 2D array
- Support Team
- Site Admin
- Posts: 12145
- Joined: Fri Jul 07, 2006 4:30 pm
- Location: Houston, Texas, USA
- Contact:
Re: Excel into 2D array
Hello,
Unfortunately it is not possible to write values into the excel sheet using the data connector.
In order to write values into you excel file you can use the .NET framework directly.
There are several posts about this topic in the forum. Here are some of them:
http://www.ranorex.com/forum/writing-ex ... t1605.html
http://www.ranorex.com/forum/how-to-wri ... t3258.html
http://www.ranorex.com/forum/writing-th ... t1702.html
Regards,
Bernhard
Unfortunately it is not possible to write values into the excel sheet using the data connector.
In order to write values into you excel file you can use the .NET framework directly.
There are several posts about this topic in the forum. Here are some of them:
http://www.ranorex.com/forum/writing-ex ... t1605.html
http://www.ranorex.com/forum/how-to-wri ... t3258.html
http://www.ranorex.com/forum/writing-th ... t1702.html
Regards,
Bernhard
Re: Excel into 2D array
Hi,
I need to read from Excel into a 2D array. All the posts are to write to Excel.
Thanks,
I need to read from Excel into a 2D array. All the posts are to write to Excel.
Thanks,
Re: Excel into 2D array
Have a look at the methods I posted here: http://www.ranorex.com/forum/my-excel-f ... t3265.html
They might help you out or at least get you going in the right direction...
They might help you out or at least get you going in the right direction...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...
Re: Excel into 2D array
Hi Ciege,
Thanks for sharing the ExcelFramework.
When I use the ConvertToStringArray(myvalues), it complains that "The name 'ConvertToStringArray' does not exist in the current context (CS0103)".
I have the following references in my usercode:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;
Please advise.
Thanks for sharing the ExcelFramework.
When I use the ConvertToStringArray(myvalues), it complains that "The name 'ConvertToStringArray' does not exist in the current context (CS0103)".
I have the following references in my usercode:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Drawing;
using System.Threading;
using WinForms = System.Windows.Forms;
using Microsoft.Office.Interop.Excel;
using Ranorex;
using Ranorex.Core;
using Ranorex.Core.Testing;
Please advise.
Re: Excel into 2D array
I think that method was not included in the solution I posted for some reason...
Here is that method:
Here is that method:
Code: Select all
public static string[] ConvertToStringArray(System.Array values)
{
string[] newArray = new string[values.Length];
int index = 0;
for (int i = values.GetLowerBound(0);
i <= values.GetUpperBound(0); i++)
{
for (int j = values.GetLowerBound(1);
j <= values.GetUpperBound(1); j++)
{
if (values.GetValue(i, j) == null)
{
newArray[index] = "";
}
else
{
newArray[index] = (string)values.GetValue(i, j).ToString();
}
index++;
}
}
return newArray;
} //End ConvertToStringArray
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!
Ciege...
Ciege...