【问题标题】:Export Telerik GridView to excel with borders将 Telerik GridView 导出为带边框的 excel
【发布时间】:2012-10-25 07:09:36
【问题描述】:

我有一个 Telerik radGridView1,我正在将其导出到 excel,但 excel 文件中没有显示边框。那么如何用边框导出它。我是这样导出的……

ExportToExcelML export = new ExportToExcelML(this.radGridView1);
export.ExportVisualSettings = true;
export.RunExport(saveFileDialog1.FileName);

提前致谢

【问题讨论】:

    标签: c# winforms telerik export telerik-grid


    【解决方案1】:

    您需要在导出前为边框设置 rad 网格的以下属性

    this.radGridView1.GridLines = Both;
    this.radGridView1.BorderStyle = BorderStyle.Solid;
    ExportToExcelML export = new ExportToExcelML(this.radGridView1);
    export.ExportVisualSettings = true;
    export.RunExport(saveFileDialog1.FileName);
    

    【讨论】:

    • 感谢您的回答,但它给了我一个 GridLines 和 BorderStyle 的错误行。有什么需要补充的吗?
    • 您可以在 aspx 页面本身中设置这些属性。
    • 我正在运行一个 Windows 应用程序
    【解决方案2】:

    ExcelCellFormatting 事件可能对您有所帮助:

    它提供对单个单元格的 SingleStyleElement 的访问,允许您为与导出的 RadGridView 相关的每个 excel 单元格进行其他格式设置(添加边框、设置对齐、文本字体、颜色、更改单元格值等):

    void exporter_ExcelCellFormatting(object sender,Telerik.WinControls.UI.Export.ExcelML.ExcelCellFormattingEventArgs e)
    {
        if (e.GridRowInfoType == typeof(GridViewTableHeaderRowInfo))
        {
            BorderStyles border = new BorderStyles();
            border.Color = Color.Black;
            border.Weight = 2;
            border.LineStyle = LineStyle.Continuous;
            border.PositionType = PositionType.Bottom;
            e.ExcelStyleElement.Borders.Add(border);
        }
        else if (e.GridRowIndex == 2 && e.GridColumnIndex == 1)
        {
            e.ExcelStyleElement.InteriorStyle.Color = Color.Yellow;
            e.ExcelStyleElement.AlignmentElement.WrapText = true;
        }
    }
    

    点击here了解更多信息。

    【讨论】:

      猜你喜欢
      • 2016-07-03
      • 1970-01-01
      • 2014-02-22
      • 1970-01-01
      • 2013-09-25
      • 1970-01-01
      相关资源
      最近更新 更多