como devo proceder

08/09/2013

0

Estou querendo percorrer uma tabela feita em excel, quando a celula A2 (DOCUMENTO DE CLIENTE) for true ela percorrer as colunas e linhas (B2,C2,D2,E2,F2,G2,H2,I2,J2,K2) e senão percorrer as celulas (L3,M3,N3,O3,P3,Q3) ITENS DOC CLIENTE. Como devo fazer? Meu codigo está assim:

int qtdLines = plan1.Rows.Count;
string documento_cliente = "documento_cliente";

if (documento_cliente.Equals("documento_cliente"))
{
for (int index = 0; index <= qtdLines; index++)
{
object cell2 = "B2" + index;
object cell3 = "C2" + index;
object cell4 = "D2" + index;
object cell5 = "E2" + index;
object cell6 = "F2" + index;
object cell7 = "G2" + index;
object cell8 = "H2" + index;
object cell9 = "I2" + index;
object cell10 = "J2" + index;
object cell11 = "K2" + index;

Microsoft.Office.Interop.Excel.Range cell = plan1.get_Range(cell2, cell2);

if (((Microsoft.Office.Interop.Excel.Range)cell[2, 2]).Value == cell2 &&
((Microsoft.Office.Interop.Excel.Range)cell[2, 3]).Value == cell3)
{
break;
}
if (((Microsoft.Office.Interop.Excel.Range)cell[2, 4]).Value == cell4 &&
((Microsoft.Office.Interop.Excel.Range)cell[2, 5]).Value == cell5)
{
break;
}
if (((Microsoft.Office.Interop.Excel.Range)cell[2, 6]).Value == cell6 &&
((Microsoft.Office.Interop.Excel.Range)cell[2, 7]).Value == cell7)
{
break;
}
if (((Microsoft.Office.Interop.Excel.Range)cell[2, 8]).Value == cell8 &&
((Microsoft.Office.Interop.Excel.Range)cell[2, 9]).Value == cell9)
{
break;
}
if (((Microsoft.Office.Interop.Excel.Range)cell[2, 10]).Value == cell10 &&
((Microsoft.Office.Interop.Excel.Range)cell[2, 11]).Value == cell11)
{
break;
}

string itens_documento_cliente = "itens_documento_cliente";

if (itens_documento_cliente.Equals("itens_documento_cliente"))
{
for (int i = 0; i <= qtdLines; i++)
{
object cell1A = "L3";
object cell2B = "M3";
object cell3C = "N3";
object cell4D = "O3";
object cell5D = "P3";
object cell6E = "Q3";

Microsoft.Office.Interop.Excel.Range line1 = plan1.get_Range(cell1A, cell6E);

if (((Microsoft.Office.Interop.Excel.Range)line1[3, 12]).Value == cell1A &&
((Microsoft.Office.Interop.Excel.Range)line1[3, 13]).Value == cell2B)
{
break;
}
if (((Microsoft.Office.Interop.Excel.Range)line1[3, 14]).Value == cell3C &&
((Microsoft.Office.Interop.Excel.Range)line1[3, 15]).Value == cell4D)
{
break;
}
if (((Microsoft.Office.Interop.Excel.Range)line1[3, 16]).Value == cell5D &&
((Microsoft.Office.Interop.Excel.Range)line1[3, 17]).Value == cell6E)
{
break;
}

String data = (((Microsoft.Office.Interop.Excel.Range)cell[2, 2]).Value2.ToString());
String nomeObjeto = (((Microsoft.Office.Interop.Excel.Range)line1[3, 12]).Value == null)
? String.Empty : ((Microsoft.Office.Interop.Excel.Range)line1[3, 12]).Value.ToString();
String codigo = (((Microsoft.Office.Interop.Excel.Range)cell[2, 3]).Value == null)
? String.Empty : ((Microsoft.Office.Interop.Excel.Range)cell[2, 3]).Value.ToString();
Int32 vendedor = Convert.ToInt32((((Microsoft.Office.Interop.Excel.Range)cell[2, 5]).ToString()));
Int32 tipodocumento = Convert.ToInt32((((Microsoft.Office.Interop.Excel.Range)cell[2, 6]).Value.ToString()));
Int32 agentecobrador = Convert.ToInt32((((Microsoft.Office.Interop.Excel.Range)cell[2, 7]).Value.ToString()));
Int32 tipocobranca = Convert.ToInt32(((Microsoft.Office.Interop.Excel.Range)cell[2, 8]).Value.ToString());
Int32 frete = Convert.ToInt32(((Microsoft.Office.Interop.Excel.Range)cell[2, 10]).Value.ToString());
if (String.IsNullOrEmpty(nomeObjeto))
{
continue;
}
Decimal precoUnitario = Decimal.Zero;
Decimal quantidade = Convert.ToDecimal(((Microsoft.Office.Interop.Excel.Range)line1[3, 15]).Value.ToString());
if (quantidade == Decimal.Zero)
{
continue;
}
Int32 fluxo = Convert.ToInt32(((Microsoft.Office.Interop.Excel.Range)line1[3, 16]).Value2.ToString());
Int32 centroCusto = Convert.ToInt32(((Microsoft.Office.Interop.Excel.Range)line1[3, 17]).Value2.ToString());

regDocumentoCliente["site"] = instSessao.Site;
regDocumentoCliente["documento_cliente.data"] = (DateTime)this.regContexto["data"];
regDocumentoCliente["documento_cliente.empresa"] = (int)this.regContexto["empresa"];
regDocumentoCliente["documento_cliente.cliente"] = (int)this.regContexto["cliente"];
regDocumentoCliente["vendedor"] = (Int32)this.regContexto["id"];
regDocumentoCliente["tipo_documento"] = (Int32)this.regContexto["tipodocumento"];
regDocumentoCliente["agente_cobrador"] = (Int32)this.regContexto["agentecobrador"];
regDocumentoCliente["tp_cobranca"] = (int)this.regContexto["tipocobranca"];
regDocumentoCliente["prazo"] = (int)this.regContexto["prazo"];
regDocumentoCliente["frete"] = frete;
regDocumentoCliente["numero"] = (Decimal)regDocumentoCliente["numero"];
regDocumentoCliente["objeto"] = (Int32)rgcObjeto[0]["id"];
regDocumentoCliente["unidade_medida"] = (Int32)rgcObjeto[0]["unidade_estoque.unidade_medida"];
regDocumentoCliente["preco_unitario"] = precoUnitario;
regDocumentoCliente["quantidade"] = quantidade;
regDocumentoCliente["fluxo"] = fluxo;
regDocumentoCliente["centro_Custo"] = centroCusto;
Caixa Brasil

Caixa Brasil

Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar