下面即是用 Asp 创建 (生成) pdf 文件的代码
<%
Opção explícita
Sub -checkXldRiver ()
Em erro de erro em seguida
Dim vconnString
Dim Oconn, Oerr
'Tente se conectar ao arquivo nul:
vConnString = driver = {Microsoft Excel Driver (*.xls)}; dbq = nul:
Set oconn = createObject (adodb.connection)
OCONN.OPEN VCONNSTRING
Para cada oerr em oconn.errors
'Quando o driver do Excel relata a falha criando arquivo,
'Então deve ser instalado e funcionando ;-))
Se oerr.nativeError = -5036 então
Sub
Final se
Próximo
Provedor de respostas.write ou driver não disponível. (Re) Instale o MDAC.
Response.Write Hex (err.number) & & err.description &
Para cada oerr em oconn.errors
Response.Write Hex (Oerr.Number) & & oerr.nativeError & & oerr.Description &
Próximo
Resposta.END
Final sub
Função getConnection (vConnString)
Em erro de erro em seguida
Definir getConnection = server.createObject (adodb.connection)
GetConnection.open vconnstring
Se err.number <> 0 então
Definir getConnection = nada
Final se
Função final
Função OptionTag (VCHOICE, VTRUE)
Dim vSlected
Se vtrue então
VSELECED = SELECTADO
Final se
OptionTag = <Opção & VSselected &> & _
Server.htmlencode (VChoice) & </pption> & vbcrlf
Função final
Função isCHECKED (VTRUE)
Se vtrue então
IsCHECKED = verificado
Final se
Função final
Função Bookoptions (vxlfile)
Dim vServerFolder
Dim Ofs, Ofolder, Ofile
Dim vSlected
vServerFolder = server.mappath (.)
Conjunto OFS = server.createObject (script.filesystemoBject)
Conjunto Ofolder = OfS.getFolder (vServerFolder)
Para cada um de ile em Ofolder.files
Se ofile.type = planilha do Microsoft Excel então
VSELECTED = (OFILE.NAME = VXLFILE)
Bookoptions = bookoptions & _
OptionTag (ofile.name, VSselected)
Final se
Próximo
Conjunto de solder = nada
Conjunto de anos = nada
Função final
Função denominada Rangeoptions (OCONN, VXLRANGE, VTableType)
Oschemars escuros
Dim vSlected
Chamado Rangeoptions = OptionTag (vazio, vazio)
Se typename (oconn) = conexão então
Set oschemars = oconn.openschema (adschematables)
Faça enquanto não oschemars.eof
Se oschemars (tabela_type) = vtableType então
VSELECTED = (Oschemars (tabela_name) = vxlRange)
Chamado Rangeoptions = nomeado Rangeoptions & _
OptionTag (Oschemars (Table_name), VSelected)
Final se
oschemars.movenext
Laço
Final se
Função final
Função Datatable (OCONN, VXLRANGE, VXLHASHEADINGS)
Em erro de erro em seguida
'De Oledbvbc.inc
Const db_e_errorsincommand = & h80040e14
Dim Ors, de campo
Dim vthtag, vthendtag
Se vxlhasheadings, então
vthtag = <th>
vthendTag = </th>
Outro
vthtag = <td>
vthendTag = </td>
Final se
Datatable = <borda da tabela = 1>
Se typename (oconn) = conexão então
Set ors = oconn.execute ([& vxlRange &])
Se oconn.errors.count> 0 então
Para cada Oconnerr em Oconn.errors
Se oconnerr.number = db_e_errorsincommand então
Datatable = datatable & _
<tr> <td> sem esse intervalo: </td> <th> & vxlRange & </th> </tr>
Outro
Datatable = datatable & _
<tr> <td> & oconnerr.description & </td> </tr>
Final se
Próximo
Outro
Datatable = datatable & <tr>
Para cada campo em Ors.fields
Datatable = datatable & vthtag & ofield.name & vthendTag
Próximo
Datatable = datatable & </tr>
Faça enquanto não Ors.eof
Datatable = datatable & <tr>
Para cada campo em Ors.fields
Datatable = datatable & <td> & ofield.value & </td>
Próximo
Datatable = datatable & </tr>
Ors.Movenext
Laço
Final se
Set Ors = nada
Outro
Datatable = datatable & <tr> <t> file bloqueado por outro aplicativo ou de outra forma não está acessível. Não pode continuar. </td> </tr>
Final se
Datatable = datatable & </ table>
Função final
' --principal--
%>
<html>
<head>
<título> Leia o Excel </ititle>
<Idioma do script = javascript>
<!-
função xlbook_onchange (theform) {
com (theForm) {
Xlsheet.SelectedIndex = 0;
Xlsheet.disabled = true;
XlNamedRange.SelectedIndex = 0;
XlnamedRange.disabled = true;
XltypedRange.value = a: iv;
}
}
função xlsheet_onchange (theform) {
com (theForm) {
XlNamedRange.SelectedIndex = 0;
XltypedRange.value = xlsheet.options [xlsheet.SelectedIndex] .Text;
}
}
função xlnamedRange_onnchange (theform) {
com (theForm) {
Xlsheet.SelectedIndex = 0;
XltypedRange.value = xlnamedRange.options [xlNamedRange.SelectedIndex] .Text;
}
}
função xltypedRange_onnchange (theform) {
com (theForm) {
Xlsheet.SelectedIndex = 0;
XlNamedRange.SelectedIndex = 0;
}
}
//->
</Script>
</head>
<Body>
<%
Dim vxlfile, vxlfilepath
Dim vxlRange, vxlhasheadings
Dim vdisabled
Dim vconnString
Dim Oconn, Oconnerr
Const adschematables = 20 'de Adovbs.inc
Checkxldriver 'verifique se está funcionando
vxlfile = solicitação (xlbook)
Se vxlfile <> vazio então
vxlRange = solicitação (XLTYPEDRANGE)
Se vxlRange = vazio então
vxlRange = a: iv
Outro
vxlRange = substituir (vxlRange ,!, $)
Final se
vxlhasheadings = solicitação (xlhasheadings)
'estabeleça conexão
vxlfilepath = server.mappath (vxlfile)
vConnString = driver = {Microsoft Excel Driver (*.xls)}; readonly = 1; dbq = & _ vxlfilepath
Set oconn = getConnection (vconnString)
Outro
vdisabled = desativado
Final se
%>
<nome do formulário = método myform = pós -ação = <%= request.Servervariables (script_name)%>>
<borda da tabela = 1 largura = 100%>
<tr>
<th> Pasta de trabalho: </th>
<Td>
<select name = xlbook idioma = javascript onchange = return xlbook_onchange (myform)>
< %= Bookoptions (vxlfile) %>
</leclect> </td>
<td align = center> planilha: </td>
<Td> <select <%= vdisabled %> name = xlsheet idioma = javascript onchange = return xlsheet_onchange (myform)>
< %= Nomeado Rangeoptions (OCONN, VXLRANGE, Tabela de Sistema) %>
</leclect> </td>
</tr>
<tr>
<th> intervalo: </th>
<td> <tipo de entrada = nome do texto = XLTYPedRange idioma = javascript onchange = return xltypedRange_onnchange (myform)
valor = < %= vxlRange %>> </td>
<td align = Center> Nomeado intervalo: </td>
<td> <select <%= vdisabled %> name = xlNamedRange idioma = javascript onchange = retornar xlnamedRange_onnchange (myform)>
< %= Nomeado Rangeoptions (OCONN, VXLRANGE, TABLE) %>
</leclect> </td>
</tr>
<tr>
<th>
<p> </th>
<td colspan = 3>
<Tipo de entrada = Nome da caixa de seleção = Xlhasheadings
< %= IsCHecked (vxlhasheadings) %>
valor = true> Mostrar primeira linha como títulos de coluna </td>
</tr>
<tr>
<th>
<p> </th>
<td colspan = 3>
<a href = < %= vxlfile %>> < %= vxlfile %> </a>
</td>
</tr>
</tabela>
<Tipo de entrada = Valor de envio = Nome de envio = cmdsubMit>
<Tipo de entrada = Valor de redefinição = Nome de redefinição = cmdreset>
</morm> <hr>
<%
Se vxlRange <> vazio então
Response.Write Datatable (OCONN, VXLRANGE, VXLHASHEADINGS)
Final se
%>
</body>
</html>