Using javascript to manipulate an Excel worksheet

CReSharper

New Member
Joined
Jun 23, 2005
Messages
2
I posted this in another forum and started thinking maybe that was the wrong place:

So here is the situation. I have a Javascript program that takes a table and exports it to excel when the user clicks a button. That works cool.

The problem is that I have an embedded menu in the table that now gets exported into excel as the first four rows.

Here is the script:

function exportToExcel()
{
try{
var sHTML = document.all.ExploreGrid.outerHTML;
var sHTML2 = document.body.all.Annotations1.outerHTML;
var oXL = new ActiveXObject("Excel.Application");
var oBook = oXL.Workbooks.Add;
oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML + sHTML2;
oBook.HTMLProject.RefreshDocument();
oXL.Visible = true;
oXL.UserControl = true;
}catch(er)
{
if(confirm('An error has occurred while trying to export to Excel. Possible causes are\n' +
' - Excel 2000 or higher is not installed on this PC\n' +
' - ActiveX controls are not enabled in your browser\n\n' +
'To view help on how to enable ActiveX controls, click OK.\n\n' +
'To continue without viewing help, click Cancel.')) +
window.open('InfoText.aspx?file=Help.htm#Supported Browsers');
}
}

The question I have is this, is there a way that once I have this into Excel that I can add some additional JS commands to delete the first four rows of the sheet? Maybe between the oBook.HTMLProject.HTMLProjectItems("Sheet1").Text = sHTML + sHTML2; command and the oBook.HTMLProject.RefreshDocument();?

Anyone ever done this? Someone with intimate knowledge of the Excel Object Model should be able to answer this, I hope.

CRS
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Does your menu have to be in the same table as the data you want to export to Excel? If not, just put it in its own table and your problem will be solved. :)
 
Upvote 0

Forum statistics

Threads
1,224,853
Messages
6,181,410
Members
453,038
Latest member
muhsen

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