Está dando este seguinte erro: O índice estava fora do intervalo. Ele deve ser não-negativo e menor que o tamanho da coleção. Nome do parâmetro: index
03/09/2013
0
this.btnImportarArquivo.Enabled = false;
String strFiltro = String.Empty;
excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
excel.Visible = false;
object objDoc = txtArquivo.Text;
object objFls = false;
object objTre = true;
object objMss = System.Reflection.Missing.Value;
object objPtw = Microsoft.Office.Interop.Excel.XlPlatform.xlWindows;
object objPwr = "";
docEx = excel.Workbooks._Open(txtArquivo.Text, false, false, objMss, objPwr, objMss, objMss, objMss, objMss, objMss, objMss, objMss, objMss);
Microsoft.Office.Interop.Excel.Worksheet plan1 = (Microsoft.Office.Interop.Excel.Worksheet)excel.ActiveSheet;
RegistroCollection rgcItensDocCliente = new RegistroCollection(instSessao.Site, Catalogo.obterDadosXml(instSessao.Site, "itens_doc_cliente", true));
int qtdLines = plan1.Rows.Count;
for (int index=12; index<=qtdLines; index++)
{
object cell1 = "A" + index;
object cell2 = "B" + index;
object cell3 = "C" + index;
object cell4 = "D" + index;
object cell5 = "E" + index;
object cell6 = "F" + index;
object cell7 = "G" + index;
object cell8 = "H" + index;
object cell9 = "I" + index;
object cell10 = "J" + index;
object cell11 = "K" + index;
object cell12 = "L" + index;
Microsoft.Office.Interop.Excel.Range line1 = plan1.get_Range(cell1,cell12);
if (((Microsoft.Office.Interop.Excel.Range)line1[2, 2]).Value2 == null &&
((Microsoft.Office.Interop.Excel.Range)line1[2, 3]).Value2 == null)
break;
string codigoAlternativo = ((Microsoft.Office.Interop.Excel.Range)line1[2, 2]).Value2.ToString();
String nomeObjeto = (((Microsoft.Office.Interop.Excel.Range)line1[1, 3]).Value2 == null)
? String.Empty : ((Microsoft.Office.Interop.Excel.Range)line1[1, 3]).Value2.ToString();
String strFiltro = String.Empty;
excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
excel.Visible = false;
object objDoc = txtArquivo.Text;
object objFls = false;
object objTre = true;
object objMss = System.Reflection.Missing.Value;
object objPtw = Microsoft.Office.Interop.Excel.XlPlatform.xlWindows;
object objPwr = "";
docEx = excel.Workbooks._Open(txtArquivo.Text, false, false, objMss, objPwr, objMss, objMss, objMss, objMss, objMss, objMss, objMss, objMss);
Microsoft.Office.Interop.Excel.Worksheet plan1 = (Microsoft.Office.Interop.Excel.Worksheet)excel.ActiveSheet;
RegistroCollection rgcItensDocCliente = new RegistroCollection(instSessao.Site, Catalogo.obterDadosXml(instSessao.Site, "itens_doc_cliente", true));
int qtdLines = plan1.Rows.Count;
for (int index=12; index<=qtdLines; index++)
{
object cell1 = "A" + index;
object cell2 = "B" + index;
object cell3 = "C" + index;
object cell4 = "D" + index;
object cell5 = "E" + index;
object cell6 = "F" + index;
object cell7 = "G" + index;
object cell8 = "H" + index;
object cell9 = "I" + index;
object cell10 = "J" + index;
object cell11 = "K" + index;
object cell12 = "L" + index;
Microsoft.Office.Interop.Excel.Range line1 = plan1.get_Range(cell1,cell12);
if (((Microsoft.Office.Interop.Excel.Range)line1[2, 2]).Value2 == null &&
((Microsoft.Office.Interop.Excel.Range)line1[2, 3]).Value2 == null)
break;
string codigoAlternativo = ((Microsoft.Office.Interop.Excel.Range)line1[2, 2]).Value2.ToString();
String nomeObjeto = (((Microsoft.Office.Interop.Excel.Range)line1[1, 3]).Value2 == null)
? String.Empty : ((Microsoft.Office.Interop.Excel.Range)line1[1, 3]).Value2.ToString();
Caixa Brasil
Curtir tópico
+ 0
Responder
Posts
03/09/2013
Joel Rodrigues
Provavelmente é dentro desse loop que você está tentando acessar um índice (de uma célula, por exemplo) que não existe. Tente depurar e ver exatamente onde está ocorrendo e qual vai ser o valor da variável index no momento em que a exceção for gerada.
Responder
Clique aqui para fazer login e interagir na Comunidade :)