I'm trying to write a 2d array to worksheet and I'm getting the following error:
Specified array was not of the expected type.
This is my code:
string[][] allEvars = new string[evars.Count][];
for (var i = 0; i < evars.Count; i++) {
var evarsList = new List<string>();
evarsList.Add(evars[i].id.Value);
evarsList.Add(evars[i].name.Value);
if (evars[i].enabled != null)
evarsList.Add(evars[i].enabled.Value.ToString());
else
evarsList.Add("");
if (evars[i].description != null)
evarsList.Add(evars[i].description.Value);
else
evarsList.Add("");
string[] evarsArray = evarsList.ToArray();
//var range = (Excel.Range)wsEvars.Range[wsEvars.Cells[i + 5, 2], wsEvars.Cells[i + 5, evarsArray.Length]];
//range.Value = evarsArray;
allEvars[i] = evarsList.ToArray();
}
var range = (Excel.Range)wsEvars.Range[wsEvars.Cells[5, 2], wsEvars.Cells[allEvars.Length, 3]];
range.Value2 = allEvars; // This is the line with the exception
The 2 commented lines from my code add the array to the worksheet one by one and I'm trying to add them all at once to save some time.