İyinet'e Hoşgeldiniz!

Türkiye'nin En Eski Webmaster Forum'una Hemen Kayıt Olun!

Kayıt Ol!

Excele aktarma (databaseden)

SametE

0
İyinet Üyesi
Katılım
7 Mart 2008
Mesajlar
307
Reaction score
0
Konum
Balıkesir
Databaseden excele 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:\Inetpub\wwwroot\tekintranet\dokuman\excel")
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
%>
 

Türkiye’nin ilk webmaster forum sitesi iyinet.com'da forum üyeleri tarafından yapılan tüm paylaşımlardan; Türk Ceza Kanunu’nun 20. Maddesinin, 5651 Sayılı Kanununun 4. maddesinin 2. fıkrasına göre, paylaşım yapan üyeler sorumludur.

Backlink ve Tanıtım Yazısı için iletişime geçmek için Skype Adresimiz: .cid.1580508955483fe5

Üst