【问题标题】:Export to excel from gridview c# format Header text从gridview c#格式导出到excel表头文本
【发布时间】:2012-08-01 07:04:46
【问题描述】:

我正在从 gridview 导出到 excel。有没有办法格式化标题文本并将其包装在 excel 中? 我导出到 excel 代码为

 grdCommon.Font.Size = FontUnit.XSmall;
 grdCommon.GridLines = GridLines.Both;
 grdCommon.Style["font-family"] = "Arial, Helvetica, sans-serif;";
 grdCommon.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
 grdCommon.HeaderStyle.ForeColor = System.Drawing.Color.White;
 grdCommon.HeaderStyle.BackColor = System.Drawing.Color.FromArgb(80, 124, 209);
 grdCommon.HeaderStyle.Font.Size = 8;
 grdCommon.HeaderStyle.Width = 30;

我尝试如下添加以格式化 excel 中的标题列。但是 excel 标头没有被换行

 grdCommon.HeaderRow.Style.Value = "word-break:break-all;word-wrap:break-word";
 grdCommon.HeaderRow.Cells[0].Wrap = true;

并修改了这个方法

 grdCommon.HeaderRow.Style.Add("background-color", "#FFFFFF"); as 
 grdCommon.HeaderRow.Style.Add("word-wrap","true");

任何建议...

【问题讨论】:

    标签: c# asp.net excel gridview export-to-excel


    【解决方案1】:

    这里是格式化gridview header的解决方案。

    grdCommon.HeaderRow.CssClass = "header";
    
    <style>
        .header
        {
            background-color:Silver;
            color:White;
        }
    </style>
    

    使用标题 css 类,您可以添加 css 属性值。

    【讨论】:

      【解决方案2】:

      从我在这里看到的情况来看,我认为 grdcommon 是一个“excel”对象。 如果不是,那么包装应该是在创建时将数据发送到 excel 文件。

      如果它是一个“Excel”对象,那么可以试试这个链接: Wrap Text in excel MSDN

      我希望这会有所帮助,因为我没有接触过任何互操作文档,所以我无法确定这是否相关。

      我不知道在哪里可以找到这些物品,但我认为这是朝着正确方向迈出的一步。

      希望对你有所帮助。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-05
        • 2012-11-24
        相关资源
        最近更新 更多