PRB: Client-Side Spreadsheet Component Fails to Import Data from URL (286316)



The information in this article applies to:

  • Microsoft Office 2003 Web Components
  • Microsoft Office XP 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 <path/filename>
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.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Paste the following HTML code into any text editor and save it as C:\Test.htm.
    <html>
      <body>
        <table>
          <tr><td>Cell A1</td><td>Cell B1</td></tr>
        </table>
      </body>
    </html>
    					
  2. 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.
    <html>
      <body>
        <object id="SSheet" classid="CLSID:0002E551-0000-0000-C000-000000000046">
        </object>
      </body>
      <script language="VBScript">
       On Error Resume Next
       SSheet.HTMLURL = "c:\test.htm"
       If Err.Number <> 0 Then MsgBox Err.Description
      </script>
    </html>
    					
  3. 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.
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 <script> block above with the following:
   Dim oFSO, oFile, sHTML
   Set oFSO = CreateObject("Scripting.FileSystemObject")
   Set oFile = oFSO.OpenTextFile("c:\test.htm", 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

REFERENCES

For more information, see the following Microsoft Web sites:

Using Office Web Components
http://support.microsoft.com/ofd

Microsoft Office Developer Center
http://msdn.microsoft.com/office/


Modification Type:MinorLast Reviewed:8/23/2005
Keywords:kbOfficeWebSpread kbprb KB286316