将Telerik GridView导出为带边框的Excel

时间:2012-10-25 07:09:37

标签: c# winforms telerik export telerik-grid

我有一个Telerik radGridView1,我将它导出到excel,但excel文件中没有显示任何边框。那么如何用边框导出它。我这样出口......

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

提前致谢

2 个答案:

答案 0 :(得分:0)

您需要在导出前为边框设置以下radgrid属性

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

答案 1 :(得分:0)

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了解详情。