代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Asp.Net
】
GridView 导出到 Word/Excel/PDF/CSV
作者:
曾祥展
/ 发布于
2011/3/15
/
1561
<div> <span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> System.Drawing; </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> System.IO; </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> System.Text; </span><span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> Button3_Click(</span><span style="color: rgb(0,0,255)">object</span><span style="color: rgb(0,0,0)"> sender, EventArgs e) { Response.Clear(); Response.Buffer </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">false</span><span style="color: rgb(0,0,0)">; Response.Charset </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">GB2312</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; Response.AppendHeader(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">Content-Disposition</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">attachment;filename=pkmv_de.xls</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); Response.ContentEncoding </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> System.Text.Encoding.GetEncoding(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">GB2312</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); Response.ContentType </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">application/ms-excel</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; Response.Write(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)"><meta http-equiv=Content-Type content=\"text/html; charset=GB2312\"></span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.EnableViewState </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">false</span><span style="color: rgb(0,0,0)">; System.IO.StringWriter oStringWriter </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> System.IO.StringWriter(); HtmlTextWriter oHtmlTextWriter </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> HtmlTextWriter(oStringWriter); GridView2.RenderControl(oHtmlTextWriter); Response.Write(oStringWriter.ToString()); Response.End(); } </span><span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">override</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> VerifyRenderingInServerForm(Control control) { } 或者 </span><span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> 定义导出 Excel Word 的函数</span><span style="color: rgb(128,128,128)"> </span><span style="color: rgb(0,0,255)">private</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> Export(</span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> FileType, </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> FileName) { Response.Charset </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">GB2312</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; Response.ContentEncoding </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> System.Text.Encoding.UTF8; Response.AppendHeader(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">Content-Disposition</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">attachment;filename=</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString()); Response.ContentType </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> FileType; </span><span style="color: rgb(0,0,255)">this</span><span style="color: rgb(0,0,0)">.EnableViewState </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">false</span><span style="color: rgb(0,0,0)">; StringWriter tw </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> StringWriter(); HtmlTextWriter hw </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> HtmlTextWriter(tw); GridView1.RenderControl(hw); Response.Write(tw.ToString()); Response.End(); } </span><span style="color: rgb(128,128,128)">///</span><span style="color: rgb(0,128,0)"> 此方法必重写,否则会出错</span><span style="color: rgb(128,128,128)"> </span><span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">override</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> VerifyRenderingInServerForm(Control control) { } </span><span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> Button1_Click(</span><span style="color: rgb(0,0,255)">object</span><span style="color: rgb(0,0,0)"> sender, EventArgs e) </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)"> Excel</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)">{ Export(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">application/ms-excel</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">Employee information.xls</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); } </span><span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> Button2_Click(</span><span style="color: rgb(0,0,255)">object</span><span style="color: rgb(0,0,0)"> sender, EventArgs e) </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">Word</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)">{ </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">Export("application/ms-excel", "Employee.doc");</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)">Export(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">application/ms-word</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">员工信息.doc</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">);</span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">都可以</span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)">} 打开word </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> System.IO; </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> System.Text; </span><span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> open() { </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> fileName </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">temp.doc</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)"> (fileName </span><span style="color: rgb(0,0,0)">!=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">null</span><span style="color: rgb(0,0,0)">) { </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> filePath </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">@"</span><span style="color: rgb(128,0,0)">images/</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; FileStream MyFileStream </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> FileStream(filePath </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> fileName, FileMode.Open); </span><span style="color: rgb(0,0,255)">long</span><span style="color: rgb(0,0,0)"> FileSize </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> MyFileStream.Length; </span><span style="color: rgb(0,0,255)">byte</span><span style="color: rgb(0,0,0)">[] Buffer </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">byte</span><span style="color: rgb(0,0,0)">[(</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">)FileSize]; MyFileStream.Read(Buffer, </span><span style="color: rgb(128,0,128)">0</span><span style="color: rgb(0,0,0)">, (</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)">)FileSize); MyFileStream.Close(); Response.AppendHeader(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">Content-Disposition</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">attachment;filename=</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> HttpUtility.UrlEncode(fileName, Encoding.UTF8).ToString()); Response.ContentType </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">application/ms-word</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; Response.BinaryWrite(Buffer); Response.End(); } </span><span style="color: rgb(0,0,255)">else</span><span style="color: rgb(0,0,0)"> { Response.Write(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">文件不存在!</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); } } </span><span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> btnExportWord_Click(</span><span style="color: rgb(0,0,255)">object</span><span style="color: rgb(0,0,0)"> sender, EventArgs e) { Response.Clear(); Response.Buffer </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">true</span><span style="color: rgb(0,0,0)">; Response.AddHeader(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">content-disposition</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">attachment;filename=GridViewExport.doc</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); Response.Charset </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">""</span><span style="color: rgb(0,0,0)">; Response.ContentType </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">application/vnd.ms-word </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; StringWriter sw</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> StringWriter(); HtmlTextWriter hw </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> HtmlTextWriter(sw); GridView1.AllowPaging </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">false</span><span style="color: rgb(0,0,0)">; GridView1.DataBind(); GridView1.RenderControl(hw); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); } </span><span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> btnExportExcel_Click(</span><span style="color: rgb(0,0,255)">object</span><span style="color: rgb(0,0,0)"> sender, EventArgs e) { Response.Clear(); Response.Buffer </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">true</span><span style="color: rgb(0,0,0)">; Response.AddHeader(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">content-disposition</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">attachment;filename=GridViewExport.xls</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); Response.Charset </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">""</span><span style="color: rgb(0,0,0)">; Response.ContentType </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">application/vnd.ms-excel</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; StringWriter sw </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> StringWriter(); HtmlTextWriter hw </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> HtmlTextWriter(sw); GridView1.AllowPaging </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">false</span><span style="color: rgb(0,0,0)">; GridView1.DataBind(); </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">Change the Header Row back to white color </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> GridView1.HeaderRow.Style.Add(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">background-color</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">#FFFFFF</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">Apply style to Individual Cells </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> GridView1.HeaderRow.Cells[</span><span style="color: rgb(128,0,128)">0</span><span style="color: rgb(0,0,0)">].Style.Add(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">background-color</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">green</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); GridView1.HeaderRow.Cells[</span><span style="color: rgb(128,0,128)">1</span><span style="color: rgb(0,0,0)">].Style.Add(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">background-color</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">green</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); GridView1.HeaderRow.Cells[</span><span style="color: rgb(128,0,128)">2</span><span style="color: rgb(0,0,0)">].Style.Add(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">background-color</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">green</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); GridView1.HeaderRow.Cells[</span><span style="color: rgb(128,0,128)">3</span><span style="color: rgb(0,0,0)">].Style.Add(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">background-color</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">green</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); </span><span style="color: rgb(0,0,255)">for</span><span style="color: rgb(0,0,0)"> (</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)"> i </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">0</span><span style="color: rgb(0,0,0)">; i </span><span style="color: rgb(0,0,0)"><</span><span style="color: rgb(0,0,0)"> GridView1.Rows.Count;i</span><span style="color: rgb(0,0,0)">++</span><span style="color: rgb(0,0,0)"> ) { GridViewRow row </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> GridView1.Rows[i]; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">Change Color back to white </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> row.BackColor </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> System.Drawing.Color.White; </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">Apply text style to each Row </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> row.Attributes.Add(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">class</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">textmode</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">Apply style to Individual Cells of Alternating Row </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">if</span><span style="color: rgb(0,0,0)"> (i </span><span style="color: rgb(0,0,0)">%</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">2</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">!=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">0</span><span style="color: rgb(0,0,0)">) { row.Cells[</span><span style="color: rgb(128,0,128)">0</span><span style="color: rgb(0,0,0)">].Style.Add(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">background-color</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">#C2D69B</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); row.Cells[</span><span style="color: rgb(128,0,128)">1</span><span style="color: rgb(0,0,0)">].Style.Add(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">background-color</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">#C2D69B</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); row.Cells[</span><span style="color: rgb(128,0,128)">2</span><span style="color: rgb(0,0,0)">].Style.Add(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">background-color</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">#C2D69B</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); row.Cells[</span><span style="color: rgb(128,0,128)">3</span><span style="color: rgb(0,0,0)">].Style.Add(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">background-color</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">#C2D69B</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); } } GridView1.RenderControl(hw); </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">style to format numbers to string </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> style </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">@"</span><span style="color: rgb(128,0,0)"><style> .textmode { } </style></span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; Response.Write(style); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); } </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> iTextSharp.text; </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> iTextSharp.text.pdf; </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> iTextSharp.text.html; </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> iTextSharp.text.html.simpleparser; </span><span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> btnExportPDF_Click(</span><span style="color: rgb(0,0,255)">object</span><span style="color: rgb(0,0,0)"> sender, EventArgs e) { Response.ContentType </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">application/pdf</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; Response.AddHeader(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">content-disposition</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">attachment;filename=GridViewExport.pdf</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); Response.Cache.SetCacheability(HttpCacheability.NoCache); StringWriter sw </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> StringWriter(); HtmlTextWriter hw </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> HtmlTextWriter(sw); GridView1.AllowPaging </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">false</span><span style="color: rgb(0,0,0)">; GridView1.DataBind(); GridView1.RenderControl(hw); StringReader sr </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> StringReader(sw.ToString()); Document pdfDoc </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> Document(PageSize.A4, 10f,10f,10f,0f); HTMLWorker htmlparser </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> HTMLWorker(pdfDoc); PdfWriter.GetInstance(pdfDoc, Response.OutputStream); pdfDoc.Open(); htmlparser.Parse(sr); pdfDoc.Close(); Response.Write(pdfDoc); Response.End(); } </span><span style="color: rgb(0,0,255)">protected</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> btnExportCSV_Click(</span><span style="color: rgb(0,0,255)">object</span><span style="color: rgb(0,0,0)"> sender, EventArgs e) { Response.Clear(); Response.Buffer </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">true</span><span style="color: rgb(0,0,0)">; Response.AddHeader(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">content-disposition</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">, </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">attachment;filename=GridViewExport.csv</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); Response.Charset </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">""</span><span style="color: rgb(0,0,0)">; Response.ContentType </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">application/text</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; GridView1.AllowPaging </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">false</span><span style="color: rgb(0,0,0)">; GridView1.DataBind(); StringBuilder sb </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> StringBuilder(); </span><span style="color: rgb(0,0,255)">for</span><span style="color: rgb(0,0,0)"> (</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)"> k </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">0</span><span style="color: rgb(0,0,0)">; k </span><span style="color: rgb(0,0,0)"><</span><span style="color: rgb(0,0,0)"> GridView1.Columns.Count; k</span><span style="color: rgb(0,0,0)">++</span><span style="color: rgb(0,0,0)">) { </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">add separator </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> sb.Append(GridView1.Columns[k].HeaderText </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">'</span><span style="color: rgb(128,0,0)">,</span><span style="color: rgb(128,0,0)">'</span><span style="color: rgb(0,0,0)">); } </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">append new line </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> sb.Append(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">\r\n</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); </span><span style="color: rgb(0,0,255)">for</span><span style="color: rgb(0,0,0)"> (</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)"> i </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">0</span><span style="color: rgb(0,0,0)">; i </span><span style="color: rgb(0,0,0)"><</span><span style="color: rgb(0,0,0)"> GridView1.Rows.Count; i</span><span style="color: rgb(0,0,0)">++</span><span style="color: rgb(0,0,0)">) { </span><span style="color: rgb(0,0,255)">for</span><span style="color: rgb(0,0,0)"> (</span><span style="color: rgb(0,0,255)">int</span><span style="color: rgb(0,0,0)"> k </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,128)">0</span><span style="color: rgb(0,0,0)">; k </span><span style="color: rgb(0,0,0)"><</span><span style="color: rgb(0,0,0)"> GridView1.Columns.Count; k</span><span style="color: rgb(0,0,0)">++</span><span style="color: rgb(0,0,0)">) { </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">add separator </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> sb.Append(GridView1.Rows[i].Cells[k].Text </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">'</span><span style="color: rgb(128,0,0)">,</span><span style="color: rgb(128,0,0)">'</span><span style="color: rgb(0,0,0)">); } </span><span style="color: rgb(0,128,0)">//</span><span style="color: rgb(0,128,0)">append new line </span><span style="color: rgb(0,128,0)"> </span><span style="color: rgb(0,0,0)"> sb.Append(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">\r\n</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); } Response.Output.Write(sb.ToString()); Response.Flush(); Response.End(); } </span><span style="color: rgb(0,0,255)">public</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">override</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">void</span><span style="color: rgb(0,0,0)"> VerifyRenderingInServerForm(Control control) { </span><span style="color: rgb(0,128,0)">/*</span><span style="color: rgb(0,128,0)"> Verifies that the control is rendered </span><span style="color: rgb(0,128,0)">*/</span><span style="color: rgb(0,0,0)"> } Excel 与 Access 互导入 with ASP.NET </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> Access </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> Server.MapPath(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">App_Data/contacts.mdb</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> Excel </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> Server.MapPath(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">App_Data/Book1.xls</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> connect </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">Provider=Microsoft.Jet.OLEDB.4.0;Data Source=</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> Excel </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">;Extended Properties=Excel 8.0;</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> (OleDbConnection conn </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> OleDbConnection(connect)) { </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> (OleDbCommand cmd </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> OleDbCommand()) { cmd.Connection </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> conn; cmd.CommandText </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">INSERT INTO [MS Access;Database=</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> Access </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">].[Persons] SELECT * FROM [Sheet1$]</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; conn.Open(); cmd.ExecuteNonQuery(); } } </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> Access </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> Server.MapPath(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">App_Data/contacts.mdb</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> Excel </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> Server.MapPath(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">App_Data/Book1.xls</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> connect </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">Provider=Microsoft.Jet.OLEDB.4.0;Data Source=</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> Excel </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">;Extended Properties=Excel 8.0;</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> (OleDbConnection conn </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> OleDbConnection(connect)) { </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> (OleDbCommand cmd </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> OleDbCommand()) { cmd.Connection </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> conn; cmd.CommandText </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">SELECT * INTO [MS Access;Database=</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> Access </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">].[New Table] FROM [Sheet1$]</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; conn.Open(); cmd.ExecuteNonQuery(); } } import data </span><span style="color: rgb(0,0,255)">from</span><span style="color: rgb(0,0,0)"> excel sheet to griedview directly. </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> Access </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> Server.MapPath(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">App_Data/contacts.mdb</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> Excel </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> Server.MapPath(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">App_Data/Book1.xls</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> connect </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">Provider=Microsoft.Jet.OLEDB.4.0;Data Source=</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> Excel </span><span style="color: rgb(0,0,0)">+</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">;Extended Properties=Excel 8.0;</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> (OleDbConnection conn </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> OleDbConnection(connect)) { </span><span style="color: rgb(0,0,255)">using</span><span style="color: rgb(0,0,0)"> (OleDbCommand cmd </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> OleDbCommand()) { cmd.Connection </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> conn; cmd.CommandText </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">SELECT * FROM [Sheet1$]</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; conn.Open(); OleDbDataReader dr </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> cmd.ExecuteReader(); GridView1.DataSource </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> dr; GridView1.DataBind(); conn.Close(); } } Reading Text files </span><span style="color: rgb(0,0,255)">into</span><span style="color: rgb(0,0,0)"> Access with ASP.NET </span><span style="color: rgb(0,128,0)">/*</span><span style="color: rgb(0,128,0)"> FirstName, SecondName Joe,Bloggs Fred,Bassett Archie,Falls Doris,Knight Gladys,Day </span><span style="color: rgb(0,128,0)">*/</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> connect </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|Contacts.mdb</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">; OleDbConnection conn </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> OleDbConnection(connect); </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> path </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> Server.MapPath(</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">App_Data</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">); </span><span style="color: rgb(0,0,255)">string</span><span style="color: rgb(0,0,0)"> query </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">INSERT INTO Persons (FirstName, SecondName) SELECT FirstName, SecondName FROM </span><span style="color: rgb(128,0,0)"> </span><span style="color: rgb(0,0,0)">[Text;DATABASE</span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)"> + path + </span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(0,0,0)">;].[test.txt]</span><span style="color: rgb(128,0,0)">"</span><span style="color: rgb(128,0,0)">;</span><span style="color: rgb(128,0,0)"> </span><span style="color: rgb(0,0,0)">OleDbCommand cmd </span><span style="color: rgb(0,0,0)">=</span><span style="color: rgb(0,0,0)"> </span><span style="color: rgb(0,0,255)">new</span><span style="color: rgb(0,0,0)"> OleDbCommand(query, conn); conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); </span> <span style="color: rgb(0,0,0)">Export GridView with Images from database to Word, Excel and PDF Formats</span> <span style="color: rgb(0,0,0)"><a href="http://www.aspsnippets.com/post/2009/04/22/Export-GridView-with-Images-from-database-to-Word-Excel-and-PDF-Formats.aspx" target="_blank">http://www.aspsnippets.com/post/2009/04/22/Export-GridView-with-Images-from-database-to-Word-Excel-and-PDF-Formats.aspx</a></span> <span style="color: rgb(0,0,0)">Read and Import Excel Sheet into ASP.Net GridView Control</span> <span style="color: rgb(0,0,0)"><a href="http://www.aspsnippets.com/post/2009/06/04/Read-and-Import-Excel-Sheet-into-ASPNet-GridView-Control.aspx" target="_blank">http://www.aspsnippets.com/post/2009/06/04/Read-and-Import-Excel-Sheet-into-ASPNet-GridView-Control.aspx</a></span> </div>
试试其它关键字
导出
同语言下
.
gzip压缩
.
实现http多线程断点续传下载文件
.
实现多线程断点续传下载大文件
.
生成字符串的 CheckSum
.
根据 UserAgent 获取浏览器的类型和版本
.
根据 Agent 判断是否是智能手机
.
隐藏手机号中间四位为*方法
.
合并图片(二维码和其他图片合并)
.
ASP.NET CORE中判断是否移动端打开网页
.
ASP.NET(C#)实现页面计时(定时)自动跳转
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
曾祥展
贡献的其它代码
(
13
)
.
C#加密算法汇总
.
根据不同的条件查询不同的表
.
有小时、分钟,求平均工作时间
.
PHP操作Sql Server数据库时使用事务的示例
.
SQL Server 多条件查询
.
Ajax 自动提示 AutoCompleteExtender
.
监视MySQL 查询缓存性能
.
看看当前缓存中有多少条信息
.
仿Google自动提示 SearchSuggess
.
GridView 导出到 Word/Excel/PDF/CSV
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3