我需要做一个简单的在服务端生成EXCEL的程序,不是VS建立的工程,只有一个ASPX文件。引用了一个C#类文件,类里using Excel = Microsoft.Office.Interop.Excel;不能用,(因为没有添加引用),这个用什么方法可以解决,有像工程里添加引用的类似代码方法,谢谢。新手,不太了解VS工程的结构。
解决方案 »
- 求 用anthem.dll 写的无刷新文件上传完整示例
- 查询条件中有分号
- openstmp如何写发送带有完整uri附件的邮件代码?
- 绑定TreeView 显示checkbook 节点不对称
- 哪位能给个customValidator客户端验证的例子?
- 谁会使用SharePowerDataGrid?
- .NET2005 把GRIDVIEW放在UPDATEPANL里隐藏列为何取不出来值(急)
- Visual Studio .NET 2004 预览版界面
- RedirectToRoute、RedirectToAction如何指定target ?
- 如何用asp网页将本地图象文件存储到Oracle的blob字段?
- 这个类应该怎么设计才合理。
- ~~~~~~~~~~~帮忙解释下正则表达式~~~~~~~~~~~~
你还是得有一个项目,
参考:
/// <summary>
/// 将DataTable数据源导出为Excel文件
/// </summary>
/// <param name="dt">DataTable数据源</param>
/// <param name="fname">Excel文件名</param>
public static void ToExcel(DataTable dt, string fname)
{
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.Charset = "gb2312";
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF7; HttpContext.Current.Response.ContentType = "application/vnd.ms-xls";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite); DataGrid dg = new DataGrid();
//dg.Style.Add(HtmlTextWriterStyle.BorderWidth, "1px");
dg.DataSource = dt;
dg.DataBind();
dg.RenderControl(htmlWrite);
HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(fname));
HttpContext.Current.Response.Write(stringWrite.ToString());
HttpContext.Current.Response.End();
}