主要是其中的LoadData(nDataType)函数。用于加载文件选择对话框中路径中的table.htm
文件中的数据。 当你点击 “ Load HTML data from a URL using the HTMLURL method. “
时开始执行。
Spreadsheet1.DataType = "HTMLURL"
Spreadsheet1.HTMLURL = (sDBPath)
他在保存为单独的htm文件中时好用,但将相同的代码。也就是LoadData(nDataType)函数和Activex控件加到aspx页中就不好用了。
<! --- ENTER DESCRIPTION HERE --- !>
This sample demonstrates several methods for loading data into the Spreadsheet and saving the data in the Spreadsheet. Click <B>Comments</B> for more details on the methods illustrated in this sample.
</TD>
</TR>
</TABLE>
<BR>
<HR COLOR=DARKBLUE NOSHADE>
<BR>
<TABLE WIDTH="100%">
<TR>
<TD WIDTH="40%" COLSPAN=2 Class=Desc><B>Try the Following Methods for Loading Data: </B></TD>
<TD WIDTH="10%"></TD>
<TD WIDTH="50%" ROWSPAN=9><OBJECT classid=clsid:0002E510-0000-0000-C000-000000000046
id=Spreadsheet1 style="width=100%"></OBJECT></TD>
</TR>
<TR>
<TD> </TD>
<TD Class=Selection onclick="LoadData(0)" onmouseover="MakeHilite()" onmouseout="MakeNormal()">Load HTML data from a URL using the <B>HTMLURL</B> method.</TD>
</TR>
<TR>
<TD></TD>
<TD Class=Selection onclick="LoadData(1)" onmouseover="MakeHilite()" onmouseout="MakeNormal()">Load HTML data from a string using the <B>HTMLData</B> method.</TD>
</TR>
<TR>
<TD></TD>
<TD Class=Selection onclick="LoadData(2)" onmouseover="MakeHilite()" onmouseout="MakeNormal()">Load CSV data from a URL using the <B>CSVURL</B> method.</TD>
</TR>
<TR>
<TD></TD>
<TD Class=Selection onclick="LoadData(3)" onmouseover="MakeHilite()" onmouseout="MakeNormal()">Load CSV data from a string using the <B>CSVData</B> method.</TD>
</TR>
<TR>
<TD></TD>
<TD Class=Selection onclick="LoadData(4)" onmouseover="MakeHilite()" onmouseout="MakeNormal()">Load Text from a tab-delimited text file using the <B>LoadText</B> method.</TD>
</TR>
<TR>
<TD COLSPAN=2 Class=Desc><B>Try the Following Methods for Saving Data: </B></TD>
</TR>
<TR>
<TD></TD>
<TD Class=Selection onclick="SaveData(0)" onmouseover="MakeHilite()" onmouseout="MakeNormal()">Save the Spreadsheet in an XML format using the <B>HTMLData</B> method and the FileSystemObject.</TD>
</TR>
<TR>
<TD></TD>
<TD Class=Selection onclick="SaveData(1)" onmouseover="MakeHilite()" onmouseout="MakeNormal()">Export the Spreadsheet to Excel using the <B>Export</B> method.
</TD>
</TR>
<TR>
<TD></TD>
<TD Class=Desc> <I>Note: The <B>Export</B> method requires that Microsoft Excel 2000 be installed at the client.</I></TD>
</TABLE>
<BR>
<BR>
<FONT COLOR=DARKBLUE SIZE=1><DIV ALIGN=RIGHT>Sample Provided by Microsoft Developer Support</DIV></FONT>
</BODY>
<script language=vbscript>
Dim strData
Dim c
Sub Window_onLoad()
set c = Spreadsheet1.Constants
Spreadsheet1.Cells.Clear
Spreadsheet1.TitleBar.Caption = "Loading & Saving Data"
End Sub
' This code runs any time the datasource type drop list is changed.
' It reloads the sheet with the selected type of Data
'If user hit Cancel, the sDBPath variable will be an empty string
if len(sDBPath) = 0 then
msgbox "你必须选择文件" & _
"及正确的文件类型.", vbcritical
exit sub
end if 'len(sDBPath) = 0
' Switch on the new data type
select case nDataType
case 0
' Load Data from html file specified in URL
Spreadsheet1.DataType = "HTMLURL"
Spreadsheet1.HTMLURL = (sDBPath)
case 1
' Load Data using HTMLData
Spreadsheet1.DataType = "HTMLData"
Spreadsheet1.HTMLData = "<TABLE>" & _
"<TR>" & _
" <TD><B>Bold</B></TD><TD><I>Italic</I></TD>" & _
"</TR>" & _
"<TR>" & _
" <TD><U>Underline</U></TD><TD>Normal</TD>" & _
"</TR>" & _
"</TABLE>"
case 2
' Load Data using a CSV file on the server
Spreadsheet1.DataType = "CSVURL"
Spreadsheet1.CSVURL = "..\data\csvdata.csv"
case 3
' Load Data using csv data by supplying hardcoded values
Spreadsheet1.DataType = "CSVData"
Spreadsheet1.CSVData = "CSVData1" & ",CSVData2" & vbCrLf _
& "CSVData3" & ",CSVData4" & vbCrLf _
& "CSVData5" & ",CSVData6"
case 4
' Load Text from Tab delimited text file
Spreadsheet1.DataType = "CSVURL"
Spreadsheet1.LoadText "..\data\textFile.txt", vbTab
end select
' AutoFit the column widths for the new data
Spreadsheet1.Refresh
Spreadsheet1.ActiveSheet.UsedRange.AutoFitColumns
Spreadsheet1.Range("A1").Select
End Sub
Function SaveData(nDataType)
Select Case nDataType
Case 0:
' Save data using HTMLData to an xls file
Dim ofs 'FileSystemObject
Dim oTs 'TextStream
Set ofs = CreateObject("Scripting.FileSystemObject")
Set oTs = ofs.CreateTextFile("C:\HTMLData.xls")
oTs.WriteLine Spreadsheet1.HTMLData
oTs.Close
Set oTs = Nothing
Set fs = Nothing
MsgBox "Saved sheet as C:\HTMLData.xls"
Case 1:
'Save the data using the Export method and display
'the results in Excel
On Error Resume Next
SpreadSheet1.ActiveSheet.Export "C:\HTMLData.xls", c.ssExportActionOpenInExcel
If Err<>0 Then
MsgBox "Unable to Export to Excel."
End If
On Error GoTo 0
End Select
End Function
Function btnComments_onclick()
window.showmodaldialog "LoadSave_Comments.htm",,"dialogWidth:50em;help:no;status:no"
End Function
Function MakeNormal()
Set src = window.event.fromElement
if src.classname = "Hilite" then src.classname = "Selection"
End function
Function MakeHilite()
Set src = window.event.toElement
if src.classname = "Selection" then src.classname = "Hilite"
End Function