1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
   | <%@ import Namespace= "System.Data" %> 
<%@ import Namespace= "System.Data.SqlClient" %> 
<%@ import Namespace= "System.IO" %>
<%@ import Namespace= "System" %>
 
 
<script language="vb" runat="server">
 
 Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
 
	Response.Clear()
	Response.AddHeader("content-disposition", "attachment;filename=C:\FileName.xls")
	Response.Charset = ""
	Response.ContentType = "application/vnd.xls"
	Dim stringWrite As New System.IO.StringWriter()
	Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
	GridView1.RenderControl(htmlWrite)
	Response.Write(stringWrite.ToString())
	Response.[End]()
 
End Sub
 
Public Overrides Sub VerifyRenderingInServerForm(control As Control)
 
End Sub
 
</script>
 
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 
<title> Création d'un fichier xls </title>
</head>
 
<body>
<h1> Création d'un fichier excel </h1>
 
<div id="runat">
<form method="post">
 
 <asp:SqlDataSource id="SqlDataSource1"
          runat="server"
          DataSourceMode="DataReader"
          ConnectionString="user id=sa;password=toto;
           database=MSIDB;server=server;"
          SelectCommand="SELECT * FROM dbo.IT_CommunautySynch">
      </asp:SqlDataSource>
 
          <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="True" 
           DataSourceID="SqlDataSource1"> </asp:GridView>
        <br />
 
        <asp:Button id="btn2" onclick="Button2_Click" runat="server" text="CreationExcel"/>
 
</div>
</form>
 
 
</body>
</html> |