导出到Excel中,并改​​变工作表名称 [英] Export to Excel, and change Sheet name

查看:106
本文介绍了导出到Excel中,并改​​变工作表名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的code我使用的是:

Here's the code I'm using:

HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("content-disposition", string.Format("attachment; filename={0}", "Single_Raw.xls"));
HttpContext.Current.Response.ContentType = "application/ms-excel";

using (StringWriter sw = new StringWriter())
{
    using (HtmlTextWriter htw = new HtmlTextWriter(sw))
    {
        Table tb = new Table();
        TableRow tr = new TableRow();

        tr.Cells.Add((rawRow((lblPOR1.Text.Substring(0, 4)), (lblPOR1.Text.Substring(5, 3)), (lblPOR1.Text.Substring(9, 3)), lblPNL.Text.ToString())));

        TableCell cell3 = new TableCell();
        cell3.Text = " ";

        TableRow tr2 = new TableRow();
        tr2.Cells.Add((rawRow((lblPOR2.Text.Substring(0, 4)), (lblPOR2.Text.Substring(5, 3)), (lblPOR2.Text.Substring(9, 3)), lblPNL.Text.ToString())));

        tb.Rows.Add(tr);
        tb.Rows.Add(tr2);

        tb.RenderControl(htw);

        HttpContext.Current.Response.Write(sw.ToString());
        HttpContext.Current.Response.End();
    }
}

它可以指定文件名,但不是工作表的名称。这可能吗?

It can specify the filename but not the Sheet name. Is it possible?

推荐答案

我使用 ExcelPackage 生成Excel表,你必须指定表名称太选项。

I am using ExcelPackage to generate excel sheets and you have the option to specify sheet name too.

例如:

ExcelWorksheet worksheet = xlPackage.Workbook.Worksheets.Add("Tinned Goods");

这篇关于导出到Excel中,并改​​变工作表名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆