I have a [,] string array that is 40 rows by 40 column items. I am trying to write them into an excel sheet but the output keeps writing the same word on the first row of every column. What am I doing wrong?
public static void writeToFile(this string [,] result)
{
try
{
//open instance of excel
Microsoft.Office.Interop.Excel.Application app = null;
app = new Excel.Application();
app.Workbooks.Add();
Excel._Worksheet sheet = app.ActiveSheet;
sheet.Name = "Sheet 1";
int resultCount = result.Length;
for (int i = 0; i < 40; i++)
{
for (int j = 0; j < 40; j++ )
{
sheet.Cells[i].Value = result[i,j];
j++;
}
i++;
}
sheet.Cells[i, j].Value = result[i,j];It's not clear why you're usingi++andj++within your loops - you don't need that. Also - indexes passed toCells[]should begin at 1: there's noCells[0, 0], the first cell on the sheet isCells[1, 1]