asp.net(C#) 导出到word excel [100分]
寻asp.net生成wordexcel的代码或者解决方案。最好是不涉及gridview的,因为有些表格的单元格可能合并。数据是在数据库中读出的。贴代码的话,最好自己试一下...
寻asp.net生成word excel 的代码或者解决方案。最好是不涉及gridview的,因为有些表格的单元格可能合并。数据是在数据库中读出的。贴代码的话,最好自己试一下能否成功。
展开
5个回答
2013-09-26
展开全部
这个分我拿定了。和我以前做的一个功能很像。网站数据,转换成 淘宝数据包文件 (csv 或者 excel) private void bind_db()
{
DataSet ds = bus.GetGoodData(txt_start.Text,txt_end.Text);
this.Results.Columns.Add("g_name",typeof(string)); //宝贝名称
this.Results.Columns.Add("g_type",typeof(string)); //宝贝类目【50000671】
this.Results.Columns.Add("s_type",typeof(string)); //店铺类目【19165853】
this.Results.Columns.Add("g_old",typeof(string)); //新旧程度【5】
this.Results.Columns.Add("g_province",typeof(string)); //省【海外】
this.Results.Columns.Add("g_city",typeof(string)); //市【海外】
this.Results.Columns.Add("g_sell",typeof(string)); //出售方式【b】
this.Results.Columns.Add("g_price",typeof(string)); //宝贝价格【】
this.Results.Columns.Add("g_uprice",typeof(string)); //加价幅度【0】
this.Results.Columns.Add("g_count",typeof(string)); //宝贝数量【10000】
this.Results.Columns.Add("g_date",typeof(string)); //有效期【14】
this.Results.Columns.Add("g_posstake",typeof(string)); //运费承担【1】
this.Results.Columns.Add("g_poss",typeof(string)); //平邮【10】
this.Results.Columns.Add("g_ems",typeof(string)); //EMS【25】
this.Results.Columns.Add("g_express",typeof(string)); //快递【10】
this.Results.Columns.Add("g_pay",typeof(string)); //付款方式【0】
this.Results.Columns.Add("g_payment",typeof(string)); //支付宝【1】
this.Results.Columns.Add("g_receipt",typeof(string)); //发票【0】
this.Results.Columns.Add("g_guarantee",typeof(string)); //保修【0】
this.Results.Columns.Add("g_again",typeof(string)); //自动重发【1】
this.Results.Columns.Add("g_deport",typeof(string)); //放入仓库【0】
this.Results.Columns.Add("g_recommend",typeof(string)); //橱窗推荐【0】
this.Results.Columns.Add("g_pubtime",typeof(string)); //发布时间【1980-1-1 0:00:00】
this.Results.Columns.Add("g_story",typeof(string)); //心情故事【每天有个好心情!】
this.Results.Columns.Add("g_info",typeof(string)); //宝贝描述【】
this.Results.Columns.Add("g_img",typeof(string)); //宝贝图片【】
//20661:29444;20662:29914;20663:29448;20664:29920;20665:29454;20666:29937;20666:29457;20666:29938;20509:28314;20509:28315;20509:28383;20510:28320;20511:28386;
this.Results.Columns.Add("g_property",typeof(string)); //宝贝属性【】
this.Results.Columns.Add("g_team",typeof(string)); //团购价【0】
this.Results.Columns.Add("g_teamnum",typeof(string)); //最小团购件数【10】
this.Results.Columns.Add("g_posstype",typeof(string)); //邮费模版ID【10】
this.Results.Columns.Add("g_member",typeof(string)); //会员打折【0】
this.Results.Columns.Add("g_updatetime",typeof(string)); //修改时间【】
this.Results.Columns.Add("g_state",typeof(string)); //上传状态【100】
this.Results.Columns.Add("g_imgstate",typeof(string)); //图片状态【0】 for(int n=0;n<ds.Tables[0].Rows.Count;n++)
{
DataRow newrow = Results.NewRow();
newrow["g_name"] = ds.Tables[0].Rows[n]["g_id"].ToString() + ds.Tables[0].Rows[n]["g_name"].ToString();
newrow["g_type"] = "50000671";
newrow["s_type"] = "19165853";
newrow["g_old"] = "5";
newrow["g_province"] = "上海";
newrow["g_city"] = "上海";
newrow["g_sell"] = "b";
newrow["g_price"] = ds.Tables[0].Rows[n]["g_marketprice"].ToString();
newrow["g_uprice"] = "0";
newrow["g_count"] = ds.Tables[0].Rows[n]["g_count"].ToString();
newrow["g_date"] = "14";
newrow["g_posstake"] = "1";
newrow["g_poss"] = "10";
newrow["g_ems"] = "25";
newrow["g_express"] = "10";
newrow["g_pay"] = "0";
newrow["g_payment"] = "1";
newrow["g_receipt"] = "0";
newrow["g_guarantee"] = "0";
newrow["g_again"] = "1";
newrow["g_deport"] = "0";
newrow["g_recommend"] = "0";
newrow["g_pubtime"] = ds.Tables[0].Rows[n]["g_publishtime"].ToString();
newrow["g_story"] = "每天有个好心情!";// string Ginfo = ds.Tables[0].Rows[n]["g_info"].ToString();
// Ginfo = System.Text.RegularExpressions.Regex.Replace(Ginfo,"/<(font|\\/font).*?(?!align).*?>/ig","");
// // Ginfo = System.Text.RegularExpressions.Regex.Replace(Ginfo,"<[^>]+>","");
// newrow["g_info"] = Ginfo;
// //newrow["g_info"] = System.Text.RegularExpressions.Regex.Replace(Ginfo,"<[^>]+>","");
newrow["g_info"] = ds.Tables[0].Rows[n]["g_info"].ToString().Replace("<","<").Replace(">",">");
//Info有字数限制。。。。。。。。。。。。。
newrow["g_img"] = @"F:\SootaoData\" + ds.Tables[0].Rows[n]["g_img"].ToString() + ".jpg";
newrow["g_property"] = "20661:29444;20662:29914;20663:29448;20664:29920;20665:29454;20666:29937;20666:29457;20666:29938;20509:28314;20509:28315;20509:28383;20510:28320;20511:28386";
newrow["g_team"] = "0";
newrow["g_teamnum"] = "10";
newrow["g_posstype"] = "10";
newrow["g_member"] = "0";
newrow["g_updatetime"] = "";
newrow["g_state"] = "100";
newrow["g_imgstate"] = "0"; Results.Rows.Add(newrow); PagedDataSource ps = new PagedDataSource();
ps.DataSource = Results.DefaultView;
dg_data.DataSource = ps;
dg_data.DataBind();
//fileRead.Close();
}
}
{
DataSet ds = bus.GetGoodData(txt_start.Text,txt_end.Text);
this.Results.Columns.Add("g_name",typeof(string)); //宝贝名称
this.Results.Columns.Add("g_type",typeof(string)); //宝贝类目【50000671】
this.Results.Columns.Add("s_type",typeof(string)); //店铺类目【19165853】
this.Results.Columns.Add("g_old",typeof(string)); //新旧程度【5】
this.Results.Columns.Add("g_province",typeof(string)); //省【海外】
this.Results.Columns.Add("g_city",typeof(string)); //市【海外】
this.Results.Columns.Add("g_sell",typeof(string)); //出售方式【b】
this.Results.Columns.Add("g_price",typeof(string)); //宝贝价格【】
this.Results.Columns.Add("g_uprice",typeof(string)); //加价幅度【0】
this.Results.Columns.Add("g_count",typeof(string)); //宝贝数量【10000】
this.Results.Columns.Add("g_date",typeof(string)); //有效期【14】
this.Results.Columns.Add("g_posstake",typeof(string)); //运费承担【1】
this.Results.Columns.Add("g_poss",typeof(string)); //平邮【10】
this.Results.Columns.Add("g_ems",typeof(string)); //EMS【25】
this.Results.Columns.Add("g_express",typeof(string)); //快递【10】
this.Results.Columns.Add("g_pay",typeof(string)); //付款方式【0】
this.Results.Columns.Add("g_payment",typeof(string)); //支付宝【1】
this.Results.Columns.Add("g_receipt",typeof(string)); //发票【0】
this.Results.Columns.Add("g_guarantee",typeof(string)); //保修【0】
this.Results.Columns.Add("g_again",typeof(string)); //自动重发【1】
this.Results.Columns.Add("g_deport",typeof(string)); //放入仓库【0】
this.Results.Columns.Add("g_recommend",typeof(string)); //橱窗推荐【0】
this.Results.Columns.Add("g_pubtime",typeof(string)); //发布时间【1980-1-1 0:00:00】
this.Results.Columns.Add("g_story",typeof(string)); //心情故事【每天有个好心情!】
this.Results.Columns.Add("g_info",typeof(string)); //宝贝描述【】
this.Results.Columns.Add("g_img",typeof(string)); //宝贝图片【】
//20661:29444;20662:29914;20663:29448;20664:29920;20665:29454;20666:29937;20666:29457;20666:29938;20509:28314;20509:28315;20509:28383;20510:28320;20511:28386;
this.Results.Columns.Add("g_property",typeof(string)); //宝贝属性【】
this.Results.Columns.Add("g_team",typeof(string)); //团购价【0】
this.Results.Columns.Add("g_teamnum",typeof(string)); //最小团购件数【10】
this.Results.Columns.Add("g_posstype",typeof(string)); //邮费模版ID【10】
this.Results.Columns.Add("g_member",typeof(string)); //会员打折【0】
this.Results.Columns.Add("g_updatetime",typeof(string)); //修改时间【】
this.Results.Columns.Add("g_state",typeof(string)); //上传状态【100】
this.Results.Columns.Add("g_imgstate",typeof(string)); //图片状态【0】 for(int n=0;n<ds.Tables[0].Rows.Count;n++)
{
DataRow newrow = Results.NewRow();
newrow["g_name"] = ds.Tables[0].Rows[n]["g_id"].ToString() + ds.Tables[0].Rows[n]["g_name"].ToString();
newrow["g_type"] = "50000671";
newrow["s_type"] = "19165853";
newrow["g_old"] = "5";
newrow["g_province"] = "上海";
newrow["g_city"] = "上海";
newrow["g_sell"] = "b";
newrow["g_price"] = ds.Tables[0].Rows[n]["g_marketprice"].ToString();
newrow["g_uprice"] = "0";
newrow["g_count"] = ds.Tables[0].Rows[n]["g_count"].ToString();
newrow["g_date"] = "14";
newrow["g_posstake"] = "1";
newrow["g_poss"] = "10";
newrow["g_ems"] = "25";
newrow["g_express"] = "10";
newrow["g_pay"] = "0";
newrow["g_payment"] = "1";
newrow["g_receipt"] = "0";
newrow["g_guarantee"] = "0";
newrow["g_again"] = "1";
newrow["g_deport"] = "0";
newrow["g_recommend"] = "0";
newrow["g_pubtime"] = ds.Tables[0].Rows[n]["g_publishtime"].ToString();
newrow["g_story"] = "每天有个好心情!";// string Ginfo = ds.Tables[0].Rows[n]["g_info"].ToString();
// Ginfo = System.Text.RegularExpressions.Regex.Replace(Ginfo,"/<(font|\\/font).*?(?!align).*?>/ig","");
// // Ginfo = System.Text.RegularExpressions.Regex.Replace(Ginfo,"<[^>]+>","");
// newrow["g_info"] = Ginfo;
// //newrow["g_info"] = System.Text.RegularExpressions.Regex.Replace(Ginfo,"<[^>]+>","");
newrow["g_info"] = ds.Tables[0].Rows[n]["g_info"].ToString().Replace("<","<").Replace(">",">");
//Info有字数限制。。。。。。。。。。。。。
newrow["g_img"] = @"F:\SootaoData\" + ds.Tables[0].Rows[n]["g_img"].ToString() + ".jpg";
newrow["g_property"] = "20661:29444;20662:29914;20663:29448;20664:29920;20665:29454;20666:29937;20666:29457;20666:29938;20509:28314;20509:28315;20509:28383;20510:28320;20511:28386";
newrow["g_team"] = "0";
newrow["g_teamnum"] = "10";
newrow["g_posstype"] = "10";
newrow["g_member"] = "0";
newrow["g_updatetime"] = "";
newrow["g_state"] = "100";
newrow["g_imgstate"] = "0"; Results.Rows.Add(newrow); PagedDataSource ps = new PagedDataSource();
ps.DataSource = Results.DefaultView;
dg_data.DataSource = ps;
dg_data.DataBind();
//fileRead.Close();
}
}
2013-09-26
展开全部
你可以找找微软的excel的slk,以前看过肯定有这个东西。就是用纯文本的方式表达excel的内容。下面有个简单的例子,转贴于oracle开发论坛 ID;PWXL;N;E
P;PGeneral
P;P0
P;P0.00
P;P#,##0
P;P#,##0.00
P;P#,##0;;\-#,##0
P;P#,##0;;[Red]\-#,##0
P;P#,##0.00;;\-#,##0.00
P;P#,##0.00;;[Red]\-#,##0.00
P;P"$"#,##0;;"$"\-#,##0
P;P"$"#,##0;;[Red]"$"\-#,##0
P;P"$"#,##0.00;;"$"\-#,##0.00
P;P"$"#,##0.00;;[Red]"$"\-#,##0.00
P;P0%
P;P0.00%
P;P0.00E+00
P;P##0.0E+0
P;P#\ ?/?
P;P#\ ??/??
P;Pyyyy/m/d
P;Pd/mmm/yy
P;Pd/mmm
P;Pmmm/yy
P;Ph:mm\ AM/PM
P;Ph:mm:ss\ AM/PM
P;Ph:mm
P;Ph:mm:ss
P;Pyyyy/m/d\ h:mm
P;Pmm:ss
P;Pmm:ss.0
P;P@
P;P[h]:mm:ss
P;P_ "$"* #,##0_ ;;_ "$"* \-#,##0_ ;;_ "$"* "-"_ ;;_ @_
P;P_ * #,##0_ ;;_ * \-#,##0_ ;;_ * "-"_ ;;_ @_
P;P_ "$"* #,##0.00_ ;;_ "$"* \-#,##0.00_ ;;_ "$"* "-"??_ ;;_ @_
P;P_ * #,##0.00_ ;;_ * \-#,##0.00_ ;;_ * "-"??_ ;;_ @_
P;P\$#,##0_);;\(\$#,##0\)
P;P\$#,##0_);;[Red]\(\$#,##0\)
P;P\$#,##0.00_);;\(\$#,##0.00\)
P;P\$#,##0.00_);;[Red]\(\$#,##0.00\)
P;Pm/d/yy
P;Pyyyy"年"m"月"d"日"
P;Ph"时"mm"分"
P;Ph"时"mm"分"ss"秒"
P;Pyyyy"年"m"月"
P;Pm"月"d"日"
P;P上午/下午h"时"mm"分"
P;P上午/下午h"时"mm"分"ss"秒"
P;P"是";;"是";;"否"
P;P"真";;"真";;"假"
P;P"开";;"开";;"关"
P;F宋体;M240
P;F宋体;M240
P;F宋体;M240
P;F宋体;M240
P;E宋体;M240
P;E宋体;M240
P;E宋体;M240
P;E宋体;M240
P;E宋体;M240
P;E宋体;M180
P;ETimes New Roman;M240
P;ETimes New Roman;M240;L11
P;E宋体;M240;SU;L13
P;E宋体;M240;SU;L37
P;ETimes New Roman;M360;L11
P;E黑体;M360;L11
F;P0;DG0G8;M285
B;Y1;X2;D0 0 0 1
O;L;D;V0;K47;G100 0.001
F;W1 1 14
F;M510;R1
F;P0;FG0C;Y1;X1
C;K"这是对中"
F;SM16;X2
C;K"红色"
E
P;PGeneral
P;P0
P;P0.00
P;P#,##0
P;P#,##0.00
P;P#,##0;;\-#,##0
P;P#,##0;;[Red]\-#,##0
P;P#,##0.00;;\-#,##0.00
P;P#,##0.00;;[Red]\-#,##0.00
P;P"$"#,##0;;"$"\-#,##0
P;P"$"#,##0;;[Red]"$"\-#,##0
P;P"$"#,##0.00;;"$"\-#,##0.00
P;P"$"#,##0.00;;[Red]"$"\-#,##0.00
P;P0%
P;P0.00%
P;P0.00E+00
P;P##0.0E+0
P;P#\ ?/?
P;P#\ ??/??
P;Pyyyy/m/d
P;Pd/mmm/yy
P;Pd/mmm
P;Pmmm/yy
P;Ph:mm\ AM/PM
P;Ph:mm:ss\ AM/PM
P;Ph:mm
P;Ph:mm:ss
P;Pyyyy/m/d\ h:mm
P;Pmm:ss
P;Pmm:ss.0
P;P@
P;P[h]:mm:ss
P;P_ "$"* #,##0_ ;;_ "$"* \-#,##0_ ;;_ "$"* "-"_ ;;_ @_
P;P_ * #,##0_ ;;_ * \-#,##0_ ;;_ * "-"_ ;;_ @_
P;P_ "$"* #,##0.00_ ;;_ "$"* \-#,##0.00_ ;;_ "$"* "-"??_ ;;_ @_
P;P_ * #,##0.00_ ;;_ * \-#,##0.00_ ;;_ * "-"??_ ;;_ @_
P;P\$#,##0_);;\(\$#,##0\)
P;P\$#,##0_);;[Red]\(\$#,##0\)
P;P\$#,##0.00_);;\(\$#,##0.00\)
P;P\$#,##0.00_);;[Red]\(\$#,##0.00\)
P;Pm/d/yy
P;Pyyyy"年"m"月"d"日"
P;Ph"时"mm"分"
P;Ph"时"mm"分"ss"秒"
P;Pyyyy"年"m"月"
P;Pm"月"d"日"
P;P上午/下午h"时"mm"分"
P;P上午/下午h"时"mm"分"ss"秒"
P;P"是";;"是";;"否"
P;P"真";;"真";;"假"
P;P"开";;"开";;"关"
P;F宋体;M240
P;F宋体;M240
P;F宋体;M240
P;F宋体;M240
P;E宋体;M240
P;E宋体;M240
P;E宋体;M240
P;E宋体;M240
P;E宋体;M240
P;E宋体;M180
P;ETimes New Roman;M240
P;ETimes New Roman;M240;L11
P;E宋体;M240;SU;L13
P;E宋体;M240;SU;L37
P;ETimes New Roman;M360;L11
P;E黑体;M360;L11
F;P0;DG0G8;M285
B;Y1;X2;D0 0 0 1
O;L;D;V0;K47;G100 0.001
F;W1 1 14
F;M510;R1
F;P0;FG0C;Y1;X1
C;K"这是对中"
F;SM16;X2
C;K"红色"
E
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-26
展开全部
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace SteelManagement
{
public class MYEXCEL
{
public MYEXCEL()
{
}
public void Save(DataTable dt, string path)
{
string sql = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0;", path);
//连接Excel,如果该XLS文件不存在,系统会自动创建一个
OleDbConnection objConn = new OleDbConnection(sql);
OleDbCommand objCmd;
string content, columnName;//用于创建EXCEL命令
try
{
objConn.Open();
objCmd = new OleDbCommand();
objCmd.Connection = objConn;
//创建表
content = "";
columnName = "";
for (int i = 0; i < dt.Columns.Count; i++)
{
if (!content.Equals(""))
{
content += ",";
columnName += ",";
}
columnName += dt.Columns[i].ColumnName;//获取列名
content += string.Format("{0} {1}", dt.Columns[i].ColumnName, "Nvarchar(50)");//初始化EXCEL列数据类型
}
objCmd.CommandText = string.Format("Create table {0}({1})", dt.TableName, content);
objCmd.ExecuteNonQuery();
//添加内容
for (int i = 0; i < dt.Rows.Count; i++)
{
content = "";
for (int j = 0; j < dt.Columns.Count; j++)
{
if (!content.Equals(""))
{
content += ",";
}
content += "'" + Convert.ToString(dt.Rows[i][j]) + "'";
}
objCmd.CommandText = string.Format("Insert into {0} ({1}) values({2})", dt.TableName, columnName, content);
objCmd.ExecuteNonQuery();
}
System.Windows.Forms.MessageBox.Show("导出成功!", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
finally
{
objConn.Close();
}
}
}
}
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.OleDb;
namespace SteelManagement
{
public class MYEXCEL
{
public MYEXCEL()
{
}
public void Save(DataTable dt, string path)
{
string sql = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0;", path);
//连接Excel,如果该XLS文件不存在,系统会自动创建一个
OleDbConnection objConn = new OleDbConnection(sql);
OleDbCommand objCmd;
string content, columnName;//用于创建EXCEL命令
try
{
objConn.Open();
objCmd = new OleDbCommand();
objCmd.Connection = objConn;
//创建表
content = "";
columnName = "";
for (int i = 0; i < dt.Columns.Count; i++)
{
if (!content.Equals(""))
{
content += ",";
columnName += ",";
}
columnName += dt.Columns[i].ColumnName;//获取列名
content += string.Format("{0} {1}", dt.Columns[i].ColumnName, "Nvarchar(50)");//初始化EXCEL列数据类型
}
objCmd.CommandText = string.Format("Create table {0}({1})", dt.TableName, content);
objCmd.ExecuteNonQuery();
//添加内容
for (int i = 0; i < dt.Rows.Count; i++)
{
content = "";
for (int j = 0; j < dt.Columns.Count; j++)
{
if (!content.Equals(""))
{
content += ",";
}
content += "'" + Convert.ToString(dt.Rows[i][j]) + "'";
}
objCmd.CommandText = string.Format("Insert into {0} ({1}) values({2})", dt.TableName, columnName, content);
objCmd.ExecuteNonQuery();
}
System.Windows.Forms.MessageBox.Show("导出成功!", "提示", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Question);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
finally
{
objConn.Close();
}
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-09-26
展开全部
ASP.NET(C#)将数据导出到Word或Excel命名空间:using System.IO;
using System.Text;将DataGrid的数据导出到Excel string excelname="excel文件名";
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment;filename=" + excelname + ".xls");
dr1.Page.EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);
dr1.RenderControl(tw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
将DataGrid的数据导出到Word string excelname="word文件名";
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-winword";
HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment;filename=" + excelname + ".doc");
dr1.Page.EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);
dr1.RenderControl(tw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
using System.Text;将DataGrid的数据导出到Excel string excelname="excel文件名";
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-excel";
HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment;filename=" + excelname + ".xls");
dr1.Page.EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);
dr1.RenderControl(tw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
将DataGrid的数据导出到Word string excelname="word文件名";
HttpContext.Current.Response.Charset = "GB2312";
HttpContext.Current.Response.ContentEncoding = Encoding.UTF8;
HttpContext.Current.Response.ContentType = "application/ms-winword";
HttpContext.Current.Response.AppendHeader("Content-disposition", "attachment;filename=" + excelname + ".doc");
dr1.Page.EnableViewState = false;
StringWriter sw = new StringWriter();
HtmlTextWriter tw = new HtmlTextWriter(sw);
dr1.RenderControl(tw);
HttpContext.Current.Response.Write(sw.ToString());
HttpContext.Current.Response.End();
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这么麻烦。。。只要写一个类。。然后调用就可以。。。给我分的话我会考虑发类给你的
0
0
0
0
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询