winform or webfrom or ?
解决方案 »
- 换行字符串加了@还是编译通不过,怎么改
- 求助,asp.net+access网站问题
- 怎样把本地图片上传(插入到)到数据库(某一字段)中?
- girdview实例
- !!!!!!!!!!!!!日期时间格式问题,大家帮我看看那里错了?!!!!!!!!!!!
- 大家帮忙看看,为什么我这段脚本能在.htm中运行,但在.aspx中却不能(在线急等!)
- 哥们有个问题卡壳了,高手请进,帮小弟先,滴水之恩当泳泉相报!
- 我写了一自定义分页的存储过程,用的是游标,用command的ExecuteReader返回DataReader,会出问题
- 验证登陆,请各位帮忙,谢谢了
- 动网论坛首页的讨论区的分类是怎么做的呀?
- 2.0中WebConfig中配置问题!
- 关于超级字符串问题
sw.WriteLine("内容");
sw.Close();
string name="xxx";
Response.AddHeader("Content-Disposition", "attachment; filename="+HttpUtility.UrlEncode(name)+".csv");
Response.ContentType = "application/ms-excel";
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
Response.Write(sw);
Response.End();
通过datagrid导出如下:
Response.Clear();
Response.Buffer= true;
Response.Charset="GB2312";
Response.AppendHeader("Content-Disposition","attachment;filename=FileName.xls");
Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.DataGrid1.RenderControl(oHtmlTextWriter);
Response.Write(oStringWriter.ToString());
Response.End();
通过excel.application如下:
int RowNum = 1;
object missing=Missing.Value;
Excel.Application myExcel=new Excel.ApplicationClass( );
Excel.Workbook myBook = myExcel.Application.Workbooks.Add(missing);
myExcel.Visible=false;
Excel.Worksheet MySheet=(Excel.Worksheet)myBook.Worksheets[1];for(int i=0;i<TableDG.Rows.Count;i++)
{
MySheet.Cells[RowNum,1] = i+1;
for(int j=0;j<TableDG.Columns.Count;j++)
{
MySheet.Cells[RowNum,j+2] = TableDG.Rows[i][j].ToString();
}
RowNum ++;
}
myBook.SaveAs(StrFilePath,missing,missing,missing,missing,missing,Excel.XlSaveAsAccessMode.xlNoChange,missing,missing,missing,missing,missing);
myBook = null;
myExcel.Quit();
myExcel = null;