using System.IO
public static void ToTXT(string contents, string fileName)
{
HttpContext.Current.Response.Buffer = true
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Charset = "UTF-8"
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8
HttpContext.Current.Response.ContentType = "application/ms-txt"
HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachmentfilename=" + "" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8))
TextWriter tw = HttpContext.Current.Response.Output
tw.WriteLine(contents)
HttpContext.Current.Response.End()
}
这是我自己写的导出txt文件的代码,调试通过,你可以修改下ContentType来得到自己需要的文件格式
问题很简单,建立excel类,在using代码段加入3个引用using
Excel
=
Microsoft.Office.Interop.Excel
using
System.Reflection
using
System.ComponentModel
然后在程序中
写如下代码
Excel.Application
xapp
=
new
Excel.Application()
xapp.Application.Workbooks.Add(true)
Excel.Worksheet
xsheet
=
xapp.Sheets[1]
xsheet.Cells[1,1]
=
"单元格内容"
string
filepath
=@"D:\XX.xls"//
文件路径及文件名
xsheet.SaveAs(filepath)
xapp.Workbooks.Close()
xapp.Quit()
System.GC.Collect()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)