Database'den excel'e bilgi aktarma Açıklama :
Database'den excel'e bilgi aktarma
Kod:
<%@ Language=VBScript %>
<%
'sql: kısmına çift tırnak içinde direk sql stringi yaz
'cnnl: database bağlantısı
Function exporttoexcel(FileName,sql,cnnl)
dim iCols
dim i
set rs=server.CreateObject("ADODB.Recordset")
set rs=cnnl.Execute (sql)
iCols = rs.Fields.Count****
session("FileName")=cstr(FileName)**
set fso = createobject("scripting.filesystemobject")
Set folder = fso.GetFolder("c:Inetpubwwwroottekintranetdokumanexcel")
Set act = folder.CreateTextFile(""&FileName& "" &".xls", true)
act.WriteLine "<html xmlns:x=""urn:schemas-microsoft-com:office:excel"">"
act.WriteLine "<head>"
act.WriteLine "<!--[if gte mso 9]><xml>"
act.WriteLine "<x:ExcelWorkbook>"
act.WriteLine "<x:ExcelWorksheets>"
act.WriteLine "<x:ExcelWorksheet>"
act.WriteLine "<x:Name>"& "Sheet1" &"</x:Name>"
act.WriteLine "<x:WorksheetOptions>"
act.WriteLine "<x:Print>"
act.WriteLine "<x:ValidPrinterInfo/>"
act.WriteLine "</x:Print>"
act.WriteLine "</x:WorksheetOptions>"
act.WriteLine "</x:ExcelWorksheet>"
act.WriteLine "</x:ExcelWorksheets>"
act.WriteLine "</x:ExcelWorkbook>"
act.WriteLine "</xml>"
act.WriteLine "<![endif]--> "
act.WriteLine "</head>"
act.WriteLine "<body>"
act.WriteLine "<table>"
act.WriteLine "<tr>"
****For i = 0 To iCols - 1
********act.WriteLine "<th>"
********act.WriteLine "<font face=Arial>"&cstr(rs.Fields.Item(i).Name&"</font>")**
********act.WriteLine "</th>"
****next
****act.WriteLine "</tr>"
****rs.MoveFirst**
****i=0
****do until rs.EOF**
****act.WriteLine "<tr>"
********For i = 0 To iCols - 1
********act.WriteLine "<td>"
********if rs.Fields.Item(i)<>"" then
********act.WriteLine "<font face=Arial>"&cstr(rs.Fields.Item(i))&"</font>"
********end if**
********act.WriteLine "</td>"
********next
****act.WriteLine "</tr>"
****rs.MoveNext**
****loop****
act.WriteLine "</table>"
act.WriteLine "</body>"
act.WriteLine "</html>"
' close the document**
act.close
rs.Close**
end function
%> ****