468,134 Members | 1,262 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,134 developers. It's quick & easy.

can we send data from html to excel sheet using java script

hi,
can we send data from html to excel sheet using java script
sandeep
Jul 6 '07 #1
4 8410
r035198x
13,262 8TB
hi,
can we send data from html to excel sheet using java script
sandeep
Moved to Javascript forum.
P.S Welcome to TSDN.
Jul 6 '07 #2
acoder
16,027 Expert Mod 8TB
hi,
can we send data from html to excel sheet using java script
sandeep
Not with standard javascript as far as I'm aware.

You could use AJAX to simulate client-side interactions or it could even be as simple as right-click and "Send to Excel" or something to that effect (without the need for any scripting).
Jul 6 '07 #3
Yes we can do whatever you are saying:

I am listing an example function where I am copying the html data in a div to the excel sheet. It is following copy-paste technique. But you can select and carry the data in a javascript variable and then save it cell-wise. Google out the rest yourself. You have got the clue.

Expand|Select|Wrap|Line Numbers
  1.  function fnSelect(objId)
  2. {
  3.    fnDeSelect();
  4.    if (document.selection) 
  5.    {
  6.       var range = document.body.createTextRange();
  7.       range.moveToElementText(document.getElementById(objId));
  8.       range.select();
  9.       range.execCommand("Copy");
  10.    }
  11.    else if (window.getSelection) 
  12.    {
  13.       var range = document.createRange();
  14.       range.selectNode(document.getElementById(objId));
  15.       window.getSelection().addRange(range);
  16.       range.execCommand("Copy");
  17.    }
  18. var eWApp = new ActiveXObject("Excel.Application")
  19. eWApp.Visible = true
  20. eWApp.Workbooks.Add()
  21. xlSheet = eWApp.ActiveSheet;
  22. xlSheet.Paste();
  23. fnDeSelect();
  24. }
  25.  
  26. function fnDeSelect() 
  27. {
  28.    if (document.selection)
  29.              document.selection.empty();
  30.    else if (window.getSelection)
  31.               window.getSelection().removeAllRanges();
  32. }
Jul 11 '07 #4
acoder
16,027 Expert Mod 8TB
Yes we can do whatever you are saying:

I am listing an example function where I am copying the html data in a div to the excel sheet. It is following copy-paste technique. But you can select and carry the data in a javascript variable and then save it cell-wise. Google out the rest yourself. You have got the clue.

Expand|Select|Wrap|Line Numbers
  1.  function fnSelect(objId)
  2. {
  3.    fnDeSelect();
  4.    if (document.selection) 
  5.    {
  6.       var range = document.body.createTextRange();
  7.       range.moveToElementText(document.getElementById(objId));
  8.       range.select();
  9.       range.execCommand("Copy");
  10.    }
  11.    else if (window.getSelection) 
  12.    {
  13.       var range = document.createRange();
  14.       range.selectNode(document.getElementById(objId));
  15.       window.getSelection().addRange(range);
  16.       range.execCommand("Copy");
  17.    }
  18. var eWApp = new ActiveXObject("Excel.Application")
  19. eWApp.Visible = true
  20. eWApp.Workbooks.Add()
  21. xlSheet = eWApp.ActiveSheet;
  22. xlSheet.Paste();
  23. fnDeSelect();
  24. }
  25.  
  26. function fnDeSelect() 
  27. {
  28.    if (document.selection)
  29.              document.selection.empty();
  30.    else if (window.getSelection)
  31.               window.getSelection().removeAllRanges();
  32. }
Welcome to TSDN!

Thanks for sharing your code.

Just to mention though, this is JScript, not Javascript. It uses ActiveX. It would work in IE, but not in any other browser.
Jul 12 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Jean-Marie Delapierre | last post: by
1 post views Thread by Steven Stewart | last post: by
7 posts views Thread by Vanessa | last post: by
1 post views Thread by gcdp | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.