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;
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会自动产生
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();