.NET Framework Developer Center > .NET Development Forums > JScript for the .NET Framework > creating excel file with comments using javascript
Ask a questionAsk a question
 

Answercreating excel file with comments using javascript

  • Thursday, January 10, 2008 5:08 AMvinodhvp Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

     

    Hi,

    I want to create an excel file using on the client side using javascript.

    I created the file using

     

    this.document.execCommand("SelectAll", false);

    this.document.execCommand("Copy", true);

    this.document.execCommand("UnSelect", false);

    var oXL = new ActiveXObject("Excel.Application");

    document.body.style.cursor = 'default';

    oXL.Visible = true;

    var oWB = oXL.Workbooks.Add();

    var oSheet = oWB.ActiveSheet;

    oSheet.Paste();

    oXL.Visible = true;

    oXL.UserControl = true;

     

     

     

    I am working with html and javascript.

    I created a table in html and copied the content of the table to the excel  file .

    But I want to add comments in some cells.

    I don't know hoe to add the comments in the eacel file using javascript.

    please help.

     

    Thanks

    Vinod

Answers

  • Friday, January 11, 2008 5:59 AMJi Cheng Wang - MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi vinod,

     

    If you would like to add comments to in some cells of an Excel file using javascript, you can try this code line - "oSheet. Cells(1, 1).AddComment("Test comment.");". The whole javascript sample codes as follows:

    Code Block

    this.document.execCommand("SelectAll", false);

    this.document.execCommand("Copy", true);

    this.document.execCommand("UnSelect", false);

    var oXL = new ActiveXObject("Excel.Application");

    document.body.style.cursor = 'default';

    oXL.Visible = true;

    var oWB = oXL.Workbooks.Add();

    var oSheet = oWB.ActiveSheet;

    oSheet. Cells(1, 1).AddComment("Test comment.");".

    oSheet.Paste();

    oXL.Visible = true;

    oXL.UserControl = true;

     

    Try to check out this document for more information about "Tips and Tricks for Scripting Microsoft Office Applications" - https://thesource.ofallevil.com/technet/scriptcenter/resources/officetips/may05/tips0531.mspx

     

    Hope this helps,

    Regards,

All Replies

  • Friday, January 11, 2008 5:59 AMJi Cheng Wang - MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi vinod,

     

    If you would like to add comments to in some cells of an Excel file using javascript, you can try this code line - "oSheet. Cells(1, 1).AddComment("Test comment.");". The whole javascript sample codes as follows:

    Code Block

    this.document.execCommand("SelectAll", false);

    this.document.execCommand("Copy", true);

    this.document.execCommand("UnSelect", false);

    var oXL = new ActiveXObject("Excel.Application");

    document.body.style.cursor = 'default';

    oXL.Visible = true;

    var oWB = oXL.Workbooks.Add();

    var oSheet = oWB.ActiveSheet;

    oSheet. Cells(1, 1).AddComment("Test comment.");".

    oSheet.Paste();

    oXL.Visible = true;

    oXL.UserControl = true;

     

    Try to check out this document for more information about "Tips and Tricks for Scripting Microsoft Office Applications" - https://thesource.ofallevil.com/technet/scriptcenter/resources/officetips/may05/tips0531.mspx

     

    Hope this helps,

    Regards,

  • Thursday, October 15, 2009 2:02 PMgsrs_shane Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi I am getting an error near

    " Automation server can't create object" near


    var oXL = new ActiveXObject("Excel.Application");


    i have done the changes as given by you in IE but still I have the same issue can you please help me out.
    thnx in advance