Я пытаюсь создать новый лист Excel, но когда я пытаюсь получить доступ ко второму листу, он всегда выдает недопустимое исключение индекса.
Всегда показывает ошибку на xlWs3 = xlWb2.Worksheets.get_Item(2);
xlApp2 = new Excel.Application();
xlWb2 = xlApp2.Workbooks.Add();
xlWs2 = xlWb2.Worksheets.get_Item(1);
xlWs2.Name = "Format OR";
for (int j = 1; j < rowor; j++)
{
xlWb2.Sheets[1].Activate();
if (fulldataOR[j][23] != "RJCT")
{
createHeaderformatOR(xlWs2);
xlWs2.Cells[berhasilOr, 1] = fulldataOR[j][2];
xlWs2.Cells[berhasilOr, 2] = fulldataOR[j][3];
xlWs2.Cells[berhasilOr, 3] = fulldataOR[j][4];
xlWs2.Cells[berhasilOr, 4] = fulldataOR[j][5];
xlWs2.Cells[berhasilOr, 5] = fulldataOR[j][6];
xlWs2.Cells[berhasilOr, 6] = fulldataOR[j][7];
xlWs2.Cells[berhasilOr, 7] = fulldataOR[j][8];
xlWs2.Cells[berhasilOr, 8] = fulldataOR[j][9];
xlWs2.Cells[berhasilOr, 9] = fulldataOR[j][12];
xlWs2.Cells[berhasilOr, 10] = fulldataOR[j][13];
xlWs2.Cells[berhasilOr, 11] = fulldataOR[j][14];
xlWs2.Cells[berhasilOr, 12] = fulldataOR[j][15];
xlWs2.Cells[berhasilOr, 13] = fulldataOR[j][16];
xlWs2.Cells[berhasilOr, 14] = fulldataOR[j][17];
xlWs2.Cells[berhasilOr, 15] = fulldataOR[j][18];
xlWs2.Cells[berhasilOr, 16] = fulldataOR[j][19];
xlWs2.Cells[berhasilOr, 17] = fulldataOR[j][20];
xlWs2.Columns.AutoFit();
berhasilOr++;
}
}
xlWs3 = xlWb2.Worksheets.get_Item(2);
xlWs3.Name = "PBK - USD";
for (int j = 1; j < rowusd; j++)
{
xlWb2.Sheets[2].Activate();
if (fulldataUSD[j][9] == "USD")
{
if (fulldataUSD[j][11] != "RJCT")
{
//MessageBox.Show(fulldataUSD[j][1]);
createHeaderPBKUSD2(xlWs3);
xlWs3.Cells[berhasilusd, 1] = fulldataUSD[j][4];
xlWs3.Cells[berhasilusd, 2] = fulldataUSD[j][5];
xlWs3.Cells[berhasilusd, 3] = "";
xlWs3.Cells[berhasilusd, 4] = "";
xlWs3.Cells[berhasilusd, 5] = "";
xlWs3.Cells[berhasilusd, 6] = "";
xlWs3.Cells[berhasilusd, 7] = "";
xlWs3.Cells[berhasilusd, 8] = "";
xlWs3.Cells[berhasilusd, 9] = "";
xlWs3.Cells[berhasilusd, 10] = "";
xlWs3.Cells[berhasilusd, 11] = fulldataUSD[j][3];
xlWs3.Cells[berhasilusd, 12] = "";
xlWs3.Cells[berhasilusd, 13] = fulldataUSD[j][2];
xlWs3.Cells[berhasilusd, 14] = fulldataUSD[j][9];
xlWs3.Cells[berhasilusd, 15] = fulldataUSD[j][6];
xlWs3.Cells[berhasilusd, 16] = "";
xlWs3.Cells[berhasilusd, 17] = fulldataUSD[j][7];
xlWs3.Cells[berhasilusd, 18] = "";
xlWs3.Cells[berhasilusd, 19] = "";
berhasilusd++;
xlWs3.Columns.AutoFit();
}
}
}
Спасибо за помощь