将Telerik GridView导出为带边框的Excel

问题描述 投票:0回答:2

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

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

提前致谢

c# winforms telerik export telerik-grid
2个回答
0
投票

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

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

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获取更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.