Simple: paste twice from javascript into excel without overw

G

Guest

Guest
I have a web page and I want to select two areas on the page and paste them into Excel.

I can select one area and paste to excel, but when I select the other area and paste, the paste overwrites the first paste!
How can I do the second paste AFTER the first paste from javascript (ie append into excel sheet rather than overwrite)?

code below (with less than, greater than removed as I can't figure out how to put these on bulletin boards!)

SCRIPT LANGUAGE="JScript"
function bringToExcel(id, id2)
{
this.document.execCommand("UnSelect", false);
//first part of document to copy
if (document.selection)
{
var range = document.body.createTextRange();
range.moveToElementText(document.all[id]);
range.select();
}
else if (window.getSelection())
{
var range = document.createRange();
range.selectNodeContents(document.getElementById(id));
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}
this.document.execCommand("Copy", true);


// launch Excel
var oXL = new ActiveXObject("Excel.Application");
oXL.Visible = true;
var oWB = oXL.Workbooks.Add();
var oSheet = oWB.ActiveSheet;
oSheet.Paste();

//second part of document to copy
if (document.selection)
{
var range = document.body.createTextRange();
range.moveToElementText(document.all[id2]);
range.select();
}
else if (window.getSelection())
{
var range = document.createRange();
range.selectNodeContents(document.getElementById(id2));
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}
this.document.execCommand("Copy", true);

oSheet.Paste();
oXL.Visible = true;
oXL.UserControl = true;
this.document.execCommand("UnSelect", false);
}




/SCRIPT

**************************
then in html I have

input type=button value="Download to Excel" onclick="bringToExcel('test', 'test2');"


where test and test2 are the id's of two areas on the web page.
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,214,909
Messages
6,122,189
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top