下面即是用asp創建(生成)pdf文件的代碼
<%
選項解釋
sub checkxldriver()
下一個錯誤簡歷
DIM VCONNSTRING
Dim Oconn,Oerr
'嘗試連接到文件nul:
vconnstring =驅動程序= {Microsoft Excel驅動程序(*.xls)}; dbq = nul:
設置oconn = createObject(adodb.connection)
OCONN.OPEN VCONNSTRING
對於Oconn.errors中的每個OERR
'當Excel驅動程序報告失敗創建文件時,
然後必須安裝並工作;-))
如果oerr.nativeerror = -5036,則
出口子
如果結束
下一個
響應。不可用的提供商或驅動程序。 (重新)安裝MDAC。
響應。寫六角(err.number)&&err.Description&
對於Oconn.errors中的每個OERR
wrespons.write hex(oerr.number)
下一個
響應
結束子
函數getConnection(vconnstring)
下一個錯誤簡歷
設置getConnection = server.createobject(adodb.connection)
getConnection.open vconnstring
如果err.number <> 0,則
設置getConnection =沒有
如果結束
結束功能
函數選項圖(VCHOICE,VTRUE)
昏暗的vselect
如果vtrue
vselected =選擇
如果結束
optionTag = <option&vselected&>&_
server.htmlencode(vChoice)&</option>&vbcrlf
結束功能
簽名功能(VTRUE)
如果vtrue
檢查=檢查
如果結束
結束功能
功能簿(VXLFILE)
DIM VSERVERFOLDER
昏暗的,Ofolder,Ofile
昏暗的vselect
vserverfolder = server.mappath(。)
ofs = server.createobject(scripting.filesystemobject)
of oforder = ofs.getFolder(vserverfolder)
對於ofolder.files中的每個ofile
如果ofile.type = Microsoft Excel工作表,則
vselected =(ofile.name = vxlfile)
bookoptions = bookoptions&_
optionTag(ofile.name,vselected)
如果結束
下一個
of ofolder = nothing
一組=沒有
結束功能
名為RangeOptions(OCONN,VXLRANGE,VTABLETYPE)的函數
昏暗的Oschemars
昏暗的vselect
名稱rangeOptions = optionTag(空,空)
如果鍵入(oconn)=連接,則
設置OSCHEMARS = OCONN.OPENSCHEMA(ADSCHEMATOBLES)
在不oschemar.eof時做
如果Oschemars(table_type)= vtableType,則
vselected =(oschemars(table_name)= vxlrange)
名稱rangeoptions = natyrangeOptions&_
OptionTag(Oschemars(table_name),vselected)
如果結束
Oschemars.movenext
環形
如果結束
結束功能
函數數據表(OCONN,VXLRANGE,VXLHASHEADING)
下一個錯誤簡歷
'來自oledbvbc.inc
const db_e_erororsincommand =&h80040e14
昏暗的,奧特爾
dim vthtag,vthendtag
如果vxlhasheadings
vthtag = <th>
vthendtag = </th>
別的
vthtag = <td>
vthendtag = </td>
如果結束
datatable = <table border = 1>
如果鍵入(oconn)=連接,則
set ors = oconn.execute([&vxlrange&])
如果OCONN.ERRORS.COUNT> 0,則
對於Oconn.Errors中的每個Oconnerr
如果oconnerr.number = db_e_erororsincommand,則
datatable = dataTable&_
<tr> <td>沒有這樣的範圍:</td> <th>&vxlrange&</th> </tr>
別的
datatable = dataTable&_
<tr> <td>&oconnerr.description&</td> </tr>
如果結束
下一個
別的
datatable = dataTable&<tr>
對於Or.fields中的每個Offiel
datatable = dataTable&vthtag&ofield.name&vthendtag
下一個
datatable = dataTable&</tr>
在不ers.eof時做
datatable = dataTable&<tr>
對於Or.fields中的每個Offiel
dataTable = datatable&<td>&ofield.value&</td>
下一個
datatable = dataTable&</tr>
ors.movenext
環形
如果結束
設置ors =沒有
別的
dataTable = dataTable&<tr> <td>文件由另一個應用程序鎖定或以其他方式無法訪問。無法繼續。</td> </tr>
如果結束
datatable = dataTable&</table>
結束功能
' - 主要的 -
%>
<html>
<頭>
<title>閱讀excel </title>
<腳本語言= JavaScript>
<! -
函數xlbook_onchange(theform){
使用(theform){
xlsheet.selectedIndex = 0;
xlsheet.disabled = true;
XlnamedRange.SelectedIndex = 0;
xlnamedrange.disabled = true;
xltypedrange.value = a:iv;
}
}
函數xlsheet_onchange(theform){
使用(theform){
XlnamedRange.SelectedIndex = 0;
xltypedrange.value = xlsheet.options [xlsheet.selectedIndex] .text;
}
}
函數xlnamedrange_onchange(theform){
使用(theform){
xlsheet.selectedIndex = 0;
xltypedrange.value = xlnamedrange.options [xlnamedrange.selectedIndex] .text;
}
}
函數xltypedrange_onchange(theform){
使用(theform){
xlsheet.selectedIndex = 0;
XlnamedRange.SelectedIndex = 0;
}
}
// - >
</script>
</head>
<身體>
<%
昏暗的vxlfile,vxlfilepath
昏暗的vxlrange,vxlhasheadings
dim vdisabled
DIM VCONNSTRING
Dim Oconn,Oconnerr
const adschematobles = 20'來自adovbs.inc
checkxldriver'確保它正在工作
vxlfile =請求(xlbook)
如果vxlfile <>空,則
vxlrange =請求(xltypedrange)
如果vxlrange =空,則
vxlrange = a:iv
別的
vxlrange =替換(vxlrange,!,$)
如果結束
vxlhasheadings =請求(xlhasheadings)
建立連接
vxlfilepath = server.mappath(vxlfile)
vconnstring = driver = {Microsoft Excel驅動程序(*.xls)}; readonly = 1; dbq =&_ vxlfilepath
設置oconn = getConnection(vconnstring)
別的
vdisabled =禁用
如果結束
%>
<form name = myform方法= post action = <%= request.servervariables(script_name)%>>
<table border = 1寬度= 100%>
<tr>
<th>工作簿:</th>
<td>
<select name = xlbook語言= javascript onChange = return xlbook_onchange(myform)>
<%= bookoptions(vxlfile)%>
</select> </td>
<td align =中心>工作表:</td>
<td> <select <%= vdisabled%> name = xlsheet語言= javascript onChange = return xlsheet_onchange(myform)>
<%=名稱rangeOptions(OCONN,VXLRANGE,SYSTEM TABLE)%>
</select> </td>
</tr>
<tr>
<th>範圍:</th>
<td> <input type = text name = xltypedrange語言= javascript onChange = return xltypedrange_onchange(myform)
值= <%= vxlrange%>> </td>
<td align =中心>命名範圍:</td>
<td> <select <%= vdisabled%> name = xlnamedrange語言= javascript onChange = return xlnamedrange_onchange(myform)>
<%=名稱rangeoptions(oconn,vxlrange,table)%>
</select> </td>
</tr>
<tr>
<th>
<p> </th>
<td colspan = 3>
<輸入類型=複選框名稱= xlhasheadings
<%= iSchecked(vxlhasheadings)%>
值= true>將第一行顯示為列標題</td>
</tr>
<tr>
<th>
<p> </th>
<td colspan = 3>
<a href = <%= vxlfile%>> <%= vxlfile%> </a>
</td>
</tr>
</table>
<輸入類型=提交值=提交名稱= cmdsubmit>
<輸入類型= reset value = reset name = cmdreset>
</form> <hr>
<%
如果vxlrange <>空,則
wrest.write datatable(oconn,vxlrange,vxlhasheadings)
如果結束
%>
</body>
</html>