C# 如何在不限制Excel导出中相同文本的情况下限制网格列中的文本长度
我目前正在用Telerik RadGrid中的大量数据构建一个asp.net应用程序。我的网格中的许多列包含大量文本。为了限制这些列中文本的大小并保留网格的格式,我截断了ItemDataBound中的每个字段。。。方法在以下代码段中:C# 如何在不限制Excel导出中相同文本的情况下限制网格列中的文本长度,c#,asp.net,telerik,export-to-excel,telerik-grid,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_Result
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中也会被截断
问:如何在网格视图中截断数据,但在导出到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;
}
radgrid的excel导出根据绑定到网格的数据生成一张工作表
如果希望在导出中显示全文,但不希望在屏幕上显示全文,则需要使用css和/或javascript隐藏文本 radgrid的excel导出根据绑定到网格的数据生成一张工作表
如果希望在导出中显示全文,但不希望在屏幕上显示全文,则需要使用css和/或javascript隐藏文本 一种方法是处理NeedDataSource事件。在这种情况下,根据您是否正在导出,为数据源提供全文或截断文本。您尚未提供此代码,但您应该能够判断您是否正在使用GridExport事件、按钮单击事件或类似事件进行导出。一种方法是处理NeedDataSource事件。在这种情况下,根据您是否正在导出,为数据源提供全文或截断文本。您尚未提供此代码,但您应该能够知道您是否正在使用GridExport事件、按钮单击事件或类似事件进行导出。我可以通过在ItemDataBound中的截断代码周围放置条件语句Export/not Export来获得所需的功能。。。。然后,我使用了一个全局布尔变量,并在export button click事件中将其标记为true
static bool exportBool;
在ItemDataBound中…:
if (ActionItem.exportBool != true) // MK CHANGE
{
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) + "...";
}
导出按钮单击事件:
protected void imgbtnexcel_Click(object sender, ImageClickEventArgs e)
{
ActionItem.exportBool = true;
BindGrid();
ConfigureExport();
RadGridActionItem.MasterTableView.ExportToExcel();
}
请注意,在页面加载中,布尔值设置为false
谢谢 通过在ItemDataBound中的截断代码周围放置条件语句export/not export,我能够获得我想要的功能。。。。然后,我使用了一个全局布尔变量,并在export button click事件中将其标记为true
static bool exportBool;
在ItemDataBound中…:
if (ActionItem.exportBool != true) // MK CHANGE
{
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) + "...";
}
导出按钮单击事件:
protected void imgbtnexcel_Click(object sender, ImageClickEventArgs e)
{
ActionItem.exportBool = true;
BindGrid();
ConfigureExport();
RadGridActionItem.MasterTableView.ExportToExcel();
}
请注意,在页面加载中,布尔值设置为false
谢谢 你能在RadGrid中设置CSS样式吗?是否可以接受将所有文本放在那里,但通过CSS将其截断 在普通表中,可以执行以下操作: 在表格本身上设置此样式:
table { table-layout: fixed; width: 100%; }
在实际单元格上,您可以在下面的示例中设置样式标题:
td.title { white-space:nowrap; overflow: hidden; width: 200px; }
数据仍然存在,只是被截断了。你能在RadGrid中设置CSS样式吗?是否可以接受将所有文本放在那里,但通过CSS将其截断 在普通表中,可以执行以下操作: 在表格本身上设置此样式:
table { table-layout: fixed; width: 100%; }
在实际单元格上,您可以在下面的示例中设置样式标题:
td.title { white-space:nowrap; overflow: hidden; width: 200px; }
数据仍然存在,只是被截断了。在FarPoint中,我可以创建一个从文本继承的自定义单元格类型,然后覆盖它“显示”值的方式,而不实际更改值。在FarPoint中,我可以做一个从文本继承的自定义单元格类型,然后覆盖它“显示”值的方式,而不实际更改值。