简体   繁体   中英

Creating xls in javascript using ActiveXObject

My code

    var fsobj = new ActiveXObject("Scripting.FileSystemObject");
    var excelApp = new ActiveXObject("Excel.Application");
    excelApp.DisplayAlerts = false;

    var wbobj = excelApp.Workbooks.Add;
    var wsobj = wbobj.Worksheets(1);

When I use the below code it works fine (ie, it executes excel and fills in two rows)

    wsobj.Cells(1,1).value="Hello";
    wsobj.Cells(2,1).value=compareData.response.length;
    wbobj.Application.visible=true;

But when I use this below code it says Expected ';' in 3rd line (with Hello), I am not able to find what is the problem here. Here is the jsfiddle link, not working though, if anyone can make it work

    for(i=0;i<compareData.response.length;i++)
    {
        wsobj.Cells(i,1).value="Hello";
    }
    wbobj.Application.visible=true;

Row numbers in Excel start from 1, not from 0. You should write

for(i=0; i<compareData.response.length; i++)
{
    wsobj.Cells(i + 1, 1).value="Hello";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM