Ver Mensaje Individual
  #1  
Antiguo 26-09-2012
Avatar de lmpadron
lmpadron lmpadron is offline
Miembro
 
Registrado: feb 2009
Ubicación: Habana, Cuba
Posts: 204
Reputación: 16
lmpadron Va por buen camino
Al exportar excel no me acepta variables (CreateOleObject)

saludos

Con el siguiente código creo perfectamente una hoja de excel , el problema viene a la hora de insertar valores almacenados en variables, cuando paso una cadena de caracteres de forma directa como al crear los nombres de los campos excel los acepta, cuando paso una cadena almacenada en una variable me devuelve un error indicando que no es el tipo de variable correcta. Si paso números no tengo problemas, es solo con el String. Al pasar un char asignandole una letra como por ejemplo 'a' me inserta una numeración matemática en este caso fue '95'. He tratado de ponerle comillas simples, comillas dobles y nada. No se que mas hacer !!! Aquí les dejo el código por si alguien se lo a topado antes y tiene alguna idea. Gracias de antemano por su ayuda

Código:
  Variant Excel,Libro,Hoja,Celda;
  Excel = CreateOleObject("Excel.Application");
  Excel.OlePropertySet("Visible", true);
  Libro=Excel.OlePropertyGet("Workbooks");
  Libro.OleProcedure("Add");
  Hoja=Libro.OlePropertyGet("Item",1);
  Libro=Hoja.OlePropertyGet("Worksheets");
  Libro.OlePropertyGet("Item",1).OlePropertySet("Name","Pago");
  //Libro.OlePropertyGet("Item",2).OlePropertySet("Name","The red book-keeping ");

  /*este que paso directo pasa bien*/
  Hoja=Libro.OlePropertyGet("Item",1);
  Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,1).OlePropertySet("Value","ueb");
  Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,2).OlePropertySet("Value","expediente");
  Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,3).OlePropertySet("Value","fecha_pago");
  Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,4).OlePropertySet("Value","periodo_inicio");
  Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,5).OlePropertySet("Value","periodo_final");
  Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,6).OlePropertySet("Value","salario_basico");
  Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,7).OlePropertySet("Value","salario_destajo");
  Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,8).OlePropertySet("Value","salario_prima");
  Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,9).OlePropertySet("Value","salario_interrupto");
  Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,10).OlePropertySet("Value","salario_regimen_turno");
  Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,11).OlePropertySet("Value","salario_total");
  Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,12).OlePropertySet("Value","orden");
  Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,13).OlePropertySet("Value","convenio");

  /*Aqui creo una variable para usar de ejemplo y siempre que sea diferente de int o char me da error sin embargo me deja pasar las demás de forma directa sin problemas*/
  String a;
  a = "c";

  int j = 1;
  while (j < 15)
  {
    j++;

    Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",j,1).OlePropertySet("Value",a);
    Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",j,2).OlePropertySet("Value","a");
    Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",j,3).OlePropertySet("Value","b");
    Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",j,4).OlePropertySet("Value","c");
    Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",j,5).OlePropertySet("Value","d");
    Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",j,6).OlePropertySet("Value","e");
    Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",j,7).OlePropertySet("Value","f");
    Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",j,8).OlePropertySet("Value","g");
    Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",j,9).OlePropertySet("Value","h");
    Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",j,10).OlePropertySet("Value","i");
    Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",j,11).OlePropertySet("Value","j");
    Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",j,12).OlePropertySet("Value","k");
    Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",j,13).OlePropertySet("Value","1");
  }

  for (int i=1;i<14;i++)
  {
    Celda=Hoja.OlePropertyGet("Cells").OlePropertyGet("Item",1,i);
    Celda.OlePropertyGet("Font").OlePropertySet("Bold",true);
  }

  Excel.OlePropertySet("DisplayAlerts",false); //suppress the warning dialog on closing the server
  Excel.OlePropertyGet("Workbooks").OlePropertyGet("Item",1).OleProcedure("SaveAs","c:\\VentaBuque");
  Excel=Unassigned;
__________________
Nunca esta de más volver a ver la "Guia de Estilo" o "La Otra Guia de Estilo". Recuerda siempre usar los "Tags" para una mejor legibilidad de tu código.


Cuando miras fijamente al abismo, este te devuelve la mirada


oo______ooo_____ooo_ooooooo_____ooo____oooooo____ooooooo______oooo____ooo____oo_
oo______oooo___oooo_oo____oo__oo___oo__oo____oo__oo____oo___oo____oo__oooo___oo_
oo______oo_oo_oo_oo_oo____oo_oo_____oo_oo_____oo_oo____oo__oo______oo_oo_oo__oo_
oo______oo__ooo__oo_oooooo___ooooooooo_oo_____oo_ooooooo___oo______oo_oo__oo_oo_
oo______oo_______oo_oo_______oo_____oo_oo____oo__oo____oo___oo____oo__oo___oooo_
ooooooo_oo_______oo_oo_______oo_____oo_oooooo____oo_____oo____oooo____oo____ooo_
________________________________________________________________________________
Responder Con Cita