简体   繁体   English

从gridview c#format导出到excel标题文本

[英]Export to excel from gridview c# format Header text

I am exporting to excel from gridview. 我从gridview导出到excel。 Is there any way to format the header text and wrap it in the excel ?. 有没有办法格式化标题文本并将其包装在Excel中? My export to excel code as 我导出到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;

I tried adding as below to format the header column in excel. 我尝试添加如下格式化excel中的标题列。 but the excel header doesnt gets wraped 但是excel标题并没有被包裹起来

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

and modified this method 并修改了这个方法

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

Any suggestions... 有什么建议么...

Here is a solution of the formating gridview header. 这是格式化gridview标头的解决方案。

grdCommon.HeaderRow.CssClass = "header";

<style>
    .header
    {
        background-color:Silver;
        color:White;
    }
</style>

Using header css class you can add the css properties value. 使用header css类可以添加css属性值。

From what I see here I think the grdcommon is an "excel" object. 从我在这里看到的我认为grdcommon是一个“excel”对象。 If not then the wrapping should be when you send the data to the excel file upon creation. 如果没有,那么包装应该是在创建时将数据发送到excel文件。

If it is an "Excel" object then maybe try this link: Wrap Text in excel MSDN 如果它是一个“Excel”对象,那么可以试试这个链接: 在Excel MSDN中包装文本

I hope this helps because I haven't touched any interop documents so I can't tell for sure if this is related or not. 我希望这有帮助,因为我没有触及任何互操作文件,所以我无法确定这是否相关。

And I don't know where you could find these objects but I think this is a step in the right direction. 我不知道你在哪里可以找到这些物品,但我认为这是朝着正确方向迈出的一步。

I hope I helped you. 我希望我帮助过你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM