日期:2014-05-19  浏览次数:20391 次

哪位大侠有Aspose.Excel.dll,请帮忙?在线等……
我在CSDN论坛上看很多人说利用Aspose.Excel.dll可以很方便的把DataGrid的数据倒入到Excel中,可是怎么都找不到,哪位大侠能给我一个吗,如何使用,再给一段调用代码可以吗,谢谢了,我的邮箱dqwzh@126.com

------解决方案--------------------
我的经验是如果你对导出的excel的格式没有特别的要求,那么就自己写代码,通过http流的形式导出excel(指定 Response.ContentType = "application/ms-excel ";)足够了;
如果你对导出的excel文件需要复杂的格式控制,那么可以考虑使用Aspose.Excel,但是它是商业软件,网上有下载注册机的。还有一个shiyo
------解决方案--------------------
直接用DataGrid导出到excel实际是一个HTML文件(用记事本打开生成的XLS文件就看得到)
它不是原生的excel,如果想生成原生excel,GemBox.ExcelLite是个不错的选择,很方便,速度也很快。
------解决方案--------------------
protected void Page_Load(object sender, EventArgs e)
{
// GridView1.Attributes.Add( "style ", "word-break:keep-all;word-wrap:normal ");
//下面这行是自动换行
//GridView1.Attributes.Add( "style ", "word-break:break-all;word-wrap:break-word ");
if (!IsPostBack)
{
SqlConnection sqlcon = new SqlConnection( "Data Source=(local);Database=db_04;Uid=sa;Pwd= ");
SqlDataAdapter myda = new SqlDataAdapter( "select * from tb_Card ", sqlcon);
DataSet myds = new DataSet();
myda.Fill(myds);
GridView1.DataSource = myds;
GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Ex( "application/ms-excel ", "学生成绩报表.xls ");
}
private void Ex(string FileType, string FileName)
{
Response.Charset = "GB2312 ";
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.AddHeader( "Content-Disposition ", "attachment;filename= " + HttpUtility.UrlEncode(FileName, Encoding.UTF8).ToString());
Response.ContentType = FileType;
this.EnableViewState = false;
StringWriter tw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(tw);
GridView1.RenderControl(hw);
Response.Write(tw.ToString());
Response.End();
}
public override void VerifyRenderingInServerForm(Control control)
{
}


----------------------------------------------------------------数据格试化
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[3].Attributes.Add( "style ", "vnd.ms-excel.numberformat:¥#,###.00 ");
}
}


接分