Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MS Office (Excel) Automation Across HTML Frames

Posted on 2004-11-01
3
Medium Priority
?
475 Views
Last Modified: 2012-06-21
Hi

I know how to automate Excel from an HTML
i.e.

      var oXL = new ActiveXObject("Excel.Application");
      oXL.Visible = true;

what it does, is open an excel workbook and show it outside of the HTML page (just a simple standalone Excel window)

1) what is the code to open that ActiveXObject inside an HTML frame?

Question Explanation:
what I want to do, is open that exact dynamically created  
Excel Object *inside another HTML frame* (let say left frame has a button with the above script , right frame should contain the Excel window)

2) What is the code to control an Existing XLS file that was loaded as a source of an HTML frame

Question Explanation:
I know that if I give the frame's src property the path to the excel object I can see it opened INSIDE the frame.

however, I dont know how to control it from the other frame
( I know to get as far as parent.frames.xlFrame. <- what to put after the frame to get the Excel object?)
0
Comment
Question by:eranation
3 Comments
 
LVL 3

Accepted Solution

by:
Fairco earned 2000 total points
ID: 12465487
Answer to question 1:

First off all, add an ID attribute to the FRAME tag within the FRAMESET, that contains the Excel. E.g.:

  <frame name="xlFrame" id="xlFrame">

(Since you mentioned xlFrame in your example, I'll use this name for that frame.)
Once an ID attribute is issued, you can use the following script line to load/change the contents from the other frame:

 parent.document.all.xlFrame.src = "myExcel.xls";

Here's an example for loading XLS:
The frameset file:
---------------------
<HTML>
<head>
   <title>test</title>
</head>
<frameset cols="20%,*" bordercolor=#154120>
<frame src="test2.html" name="menu" noresize scrollleft=0 scrolling=no>
<frame name="xlFrame" id="xlFrame">
</frameset>
</html>

The test2.html (left frame) file:
------------------------------------
<html>
<body>
<button onclick="loadXLS('test.xls')">Load TEST.XLS</button><br>
<button onclick="loadXLS('test2.xls')">Load TEST2.XLS</button><br>

<script language="JavaScript">

function loadXLS(filename)
{
 parent.document.all.xlFrame.src = filename;
}
</script>
</body>
</html>

Pay attention, that Excel being embedded into Internet Explorer renders both programs very unstable. For example, if you try to load the same file twice (clicking twice on either button), you will get an empty frame. This may be only an issue on my computer, but this is a warning of instability anyway. This isn't as annoying as in the following part.

Answer to question 2:
To get hold on the embedded Excel, you can use automation. To get the embedded Excel object, use this script:

  var xlsobj = new ActiveXObject("Excel.Application");
  xlsobj.Application.Workbooks(parent.document.all.xlFrame.src).Activate;
  xlsobj.Application.Range("A1:C3").Select;  // Some demostration: Select 3x3 cells

The problem is, that Internet Explorer does not wait for the commands to complete, therefore produces numerous errors during execution. This problem applies especially, if you combine the two answers into one script. (First it will work, but things go bad after loading the second Excel file.) You have to make the script wait for at least 500 ms after loading an Excel file, otherwise IE tries to access the non-existing Excel object and generates an error. Here's the combined script that I have made:

test2.html (file for the left frame - should be loaded by the frameset)
-------------------------------------------------------------------------------
<html>
<body>
<button onclick="loadXLS('test.xls')">Load TEST.XLS</button><br>
<button onclick="loadXLS('test2.xls')">Load TEST2.XLS</button><br>
<button onclick="selectCells()">Select 3x3 cells</button>

<script language="JavaScript">

function loadXLS(filename)
{
 parent.document.all.xlFrame.src = filename;
 window.setTimeout("activateWB()", 500);
}

function activateWB()
{
 xlsobj.Application.Workbooks(parent.document.all.xlFrame.src).Activate;
}

var xlsobj = new ActiveXObject("Excel.Application");
function selectCells()
{
 xlsobj.Application.Range("A1:C3").Select;
}

</script>
</body>
</html>

Hope I could help!
0
 
LVL 6

Expert Comment

by:abdullah716
ID: 12468259
0
 

Author Comment

by:eranation
ID: 12480798
Thanks, I'm checking it out...  :-)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmakerā€¦
This video teaches users how to migrate an existing Wordpress website to a new domain.
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question