日期:2014-05-20  浏览次数:20443 次

asp.net中如何创建一个excel对象,并自定义写入值?
我说的是ASP.NET中,比如命名空间是什么?
期待帮助~
谢谢
最好是给一段代码

------解决方案--------------------
////abc.aspx.cs文件
private void Page_Load(object sender, System.EventArgs e)
{

//Excel文件名
string myfilename = "我的Excel文件名 ";
string myfilecontent = "Excel的内容,也可以是Cookie之类. ";
Response.Clear();
Response.AddHeader( "Content-disposition ", "filename= " + myfilename + ".xsl ");
Response.AddHeader( "Content-type ", "Application/x-msexcel ");
Response.ContentEncoding = System.Text.Encoding.GetEncoding( "GB2312 ");
Response.Write(Session[ "NewCardsReport "].ToString());
}

需要注意的是,在abc.aspx页面中所有的代码都去掉,只保留
<%@ Page language= "c# " Codebehind= "abc.aspx.cs " AutoEventWireup= "false " Inherits= "myproj.abc " %>
这句VS会自动产生

------解决方案--------------------
Excel.ApplicationClass el = new Excel.ApplicationClass(); object o = Type.Missing; Excel.Workbook book = el.Workbooks.Open( "d:\\aa.xls ",o,o,o,o,o,o,o,o,o,o, o,o,o,o); Excel.Worksheet sheet = (Excel.Worksheet)book.Worksheets[1]; Excel.Style s = (Excel.Style) ((Excel.Range)sheet.Cells[1,2]).Style; s.Font.Size = 20; s.Font.Bold = true; book.Save(); book.Close(null,null,null); el.Quit();