Using Javascript to manipulate an Excel spreadsheet

Status
Not open for further replies.

CReSharper

New Member
Joined
Jun 23, 2005
Messages
2
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. :cry:

CRS
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Status
Not open for further replies.

Forum statistics

Threads
1,224,862
Messages
6,181,463
Members
453,043
Latest member
Sronquest

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