Foros del Web » Programando para Internet » Javascript »

Error exportando datos de una tabla a excel

Estas en el tema de Error exportando datos de una tabla a excel en el foro de Javascript en Foros del Web. hola a todos, primero ante todo Dios los bendiga :P. mi problema es el siguiente. Estoy tratando de crear una funcion de javascrip para poder ...
  #1 (permalink)  
Antiguo 16/04/2010, 22:28
 
Fecha de Ingreso: marzo-2006
Mensajes: 31
Antigüedad: 18 años, 1 mes
Puntos: 0
Mensaje Error exportando datos de una tabla a excel

hola a todos, primero ante todo Dios los bendiga :P.

mi problema es el siguiente.
Estoy tratando de crear una funcion de javascrip para poder exportar datos a excel a partir de una tabla html pero cada vez que llego a la linea

Código:
var ExlApp = new ActiveXObject("Excel.Application");
me muestra el siguiente error

Error en tiempo de ejecución de Microsoft JScript: El servidor de Automatización no puede crear el objeto.

A continuacion dejo la funcion que tengo.

Código:
function ExportarExcel() {
    // Start a new instance of Microsoft Excel
    var ExlApp = new ActiveXObject("Excel.Application");
    
    // Silent-mode:
    ExlApp.Visible = false;
    ExlApp.DisplayAlerts = false;

    var WorkBook = ExlApp.Workbooks.Add();
    var Sheet = WorkBook.ActiveSheet;

    Sheet.Range("A1").Value = "1.01.2006";
    Sheet.Range("A2").Value = "2.01.2006";
    Sheet.Range("A3").Value = "3.01.2006";
    Sheet.Range("A4").Value = "4.01.2006";
    Sheet.Range("A5").Value = "5.01.2006";
    Sheet.Range("A6").Value = "6.01.2006";
    Sheet.Range("A7").Value = "7.01.2006";
    Sheet.Range("A8").Value = "8.01.2006";
    Sheet.Range("A9").Value = "9.01.2006";
    Sheet.Range("A10").Value = "10.01.2006";

    Sheet.Range("B1").Value = 1;
    Sheet.Range("B2").Value = 2;
    Sheet.Range("B3").Value = 3;
    Sheet.Range("B4").Value = 4;
    Sheet.Range("B5").Value = 5;
    Sheet.Range("B6").Value = 6;
    Sheet.Range("B7").Value = 7;
    Sheet.Range("B8").Value = 8;
    Sheet.Range("B9").Value = 9;
    Sheet.Range("B10").Value = 10;

    Sheet.Range("C1").Value = 11;
    Sheet.Range("C2").Value = 9.9;
    Sheet.Range("C3").Value = 8.8;
    Sheet.Range("C4").Value = 7.7;
    Sheet.Range("C5").Value = 6.6;
    Sheet.Range("C6").Value = 5.5;
    Sheet.Range("C7").Value = 4.4;
    Sheet.Range("C8").Value = 3.3;
    Sheet.Range("C9").Value = 2.2;
    Sheet.Range("C10").Value = 1.1;

    var rang = Sheet.Range("A1:C10");

    // First chart:
    var ch = Sheet.ChartObjects.Add(rang.Left + rang.Width, rang.Top, 350, 220);
    ch.Chart.ChartType = -4120;
    ch.Chart.SetSourceData(rang, 2);

    Sheet.Range("A11").Select();

    ch.CopyPicture();

    // Start a new instance of Microsoft Word:
    var WordApp = new ActiveXObject("Word.Application");

    // Silent mode:
    WordApp.Visible = false;

    // Create a new Word document
    WordApp.Documents.Add();

    WordApp.Selection.ParagraphFormat.Alignment = 1;
    WordApp.Selection.Paste();

    WordApp.Selection.TypeParagraph();

    // Second chart:
    var ch1 = Sheet.ChartObjects.Add(ch.Left + ch.Width, ch.Top, 400, 250);
    ch1.Chart.ChartType = 95;
    ch1.Chart.SetSourceData(rang, 2);

    ch1.CopyPicture();

    WordApp.Selection.Paste();
    WordApp.Selection.TypeParagraph();

    // Third chart:
    var ch2 = Sheet.ChartObjects.Add(rang.Left + rang.Width, ch.Top + ch.Height, 400, 250);
    ch2.Chart.ChartType = -4100;
    ch2.Chart.SetSourceData(rang, 2);

    ch2.CopyPicture();

    WordApp.Selection.Paste();

    // Save Word document & exit:
    var Path = WScript.ScriptFullName;
    Path = Path.substring(0, Path.lastIndexOf("\\"));

    WordApp.ActiveDocument.SaveAs(Path + "/charts.doc");
    WordApp.Quit();

    // Save Excel document & exit:
    WorkBook.SaveAs(Path + "/charts.xls");

    ExlApp.Quit();
}
Agradezco la ayuda que me puedan dar Mil gracias.

Etiquetas: excel, tablas
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:18.