c# - 如何限制网格列中的文本长度而不限制 Excel 导出中的相同文本

标签 c# asp.net telerik export-to-excel telerik-grid

我目前正在 Telerik RadGrid 中构建一个包含大量数据的 asp.net 应用程序。我的网格中的许多列包含大量文本。为了限制这些列中文本的大小(并保留网格的格式),我在以下代码段中截断了 ItemDataBound(...) 方法中的每个字段:

if (item["Title"].Text.Length > 21)
    item["Title"].Text = item["Title"].Text.Substring(0, 21);

if (item["Investigation_Results"].Text.Length > 30)
    item["Investigation_Results"].Text = item["Investigation_Results"].Text.Substring(0, 30);

if (item["Resolution_Steps"].Text.Length > 30)
    item["Resolution_Steps"].Text = item["Resolution_Steps"].Text.Substring(0, 30);

问题是,当使用 RadGrid 的 Excel 导出功能时,被截断的字段在导出的 csv 中也会被截断。

问:如何在 GridView 中截断数据,但在导出到 Excel 时保持完整?

附加信息:

在此按钮单击事件上调用导出:

protected void imgbtnexcel_Click(object sender, ImageClickEventArgs e)
{
    ConfigureExport();
    RadGridActionItem.MasterTableView.ExportToExcel();
}

protected void ConfigureExport()
{
    RadGridActionItem.ExportSettings.ExportOnlyData = true;
    RadGridActionItem.ExportSettings.IgnorePaging = true;
    RadGridActionItem.ExportSettings.OpenInNewWindow = true;
}

最佳答案

执行此操作的一种方法是处理 NeedDataSource 事件。在这种情况下,根据您是否要导出,为数据源提供完整或截断的文本。您没有提供此代码,但您应该能够判断您是否正在使用 GridExporting 事件、按钮单击事件或类似事件进行导出。

关于c# - 如何限制网格列中的文本长度而不限制 Excel 导出中的相同文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29517111/

相关文章:

c# - 并发读写 NamePipeClientStream

c# - Monodroid 环境变量

c# - visual studio XAML 设计器未加载

c# - 委托(delegate)使用 : Business Applications

c# - 在 DynamicLinq 查询中使用扩展方法

c# - 如何在循环中使用 UdpClient.BeginReceive

c# - IFormFile 拒绝 ASP.Net Core 访问路径

c# - 动态 GridView 生成

javascript - Telerik RadGrid 如何显示确认消息

asp.net - 设置 Telerik 的默认值 :GridDropDownColumn inside of telerik:RadGrid