Microsoft KB Archive/286316

= PRB: Client-Side Spreadsheet Component Fails to Import Data from URL =

Article ID: 286316

Article Last Modified on 2/20/2007

-

APPLIES TO


 * Microsoft Office Web Components
 * Microsoft Office Web Components
 * Microsoft Visual Basic, Scripting Edition 5.5
 * Microsoft Visual Basic, Scripting Edition 5.0

-



This article was previously published under Q286316



SYMPTOMS
When you use the Office XP Spreadsheet component on a Web page in Microsoft Internet Explorer, you may receive the following error message:

Data cannot be imported from URL or file 

The data is not on the same host computer as your current document, or the data has been copied from another host computer.



CAUSE
For the purposes of ensuring security in Internet Explorer, you cannot use the CSVURL, HTMLURL, or XMLURL properties to load data into a Spreadsheet component that is hosted on a Web page if the source file is not on the same computer from which the Web page originates. You will see this error when you use CSVURL, HTMLURL, or XMLURL to load a source file in the following situations:


 * You use a FILE:// protocol to browse to a Web page on a computer (either local or remote) and attempt to load data from a source file that is not stored on that computer.
 * You use an HTTP:// protocol to browse to a Web page on a Web server and attempt to load data from a source file that is not stored on that Web server.
 * You use the CreateObject function for the Spreadsheet component (OWC10.Spreadsheet) in client-side script and attempt to load data using one of these properties. Because Internet Explorer cannot determine the safety of the client site when you use CreateObject, loading data using the aforementioned properties fails regardless of where the source file is stored.

Note that these restrictions apply only to client-side script from a Web page. You can use the CSVURL, HTMLURL, or XMLURL properties in server-side script, such as Active Server Pages (ASP) or in Visual Basic, without these restrictions on source file location.



RESOLUTION
When you require that data be loaded into the Spreadsheet component with client-side script, use the CSVData, HTMLData, and XMLData properties instead of CSVURL, HTMLURL, and XMLURL.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
  Paste the following HTML code into any text editor and save it as C:\Test.htm.   Paste the following code into any text editor and save it as LoadSheet.htm in the virtual root folder of your Web server. NOTE: The default virtual root folder is C:\Inetpub\Wwwroot.   On Error Resume Next SSheet.HTMLURL = &quot;c:\test.htm&quot; If Err.Number <> 0 Then MsgBox Err.Description  Start Internet Explorer and browse to http://YourWebServer/LoadSheet.htm, where YourWebServer is the name of your Web server. You receive the error previously described.</ol>

To correct the problem in the sample, you can use the FileSystemObject object to extract the contents of the source file as a string, and then set the HTMLData property to that string. For example, you can replace the code in the block above with the following: Dim oFSO, oFile, sHTML Set oFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;) Set oFile = oFSO.OpenTextFile(&quot;c:\test.htm&quot;, 1, True) sHTML = oFile.ReadAll SSheet.HTMLData = sHTML NOTE: To use FileSystemObject in client-side script, the Internet Explorer security setting for Initialize and script ActiveX controls not marked as safe must be set to either Prompt or Enable. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:

195826 PRB: CreateObject Fails from Client-Side Script

<div class="references_section">