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.
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.