找回密码
 立即注册

QQ登录

只需一步,快速开始

Ethan

葡萄城公司职员

10

主题

38

帖子

406

积分

葡萄城公司职员

积分
406
Ethan
葡萄城公司职员   /  发表于:2019-1-3 13:31  /   查看:3071  /  回复:4
用此链接的代码,可以导出到excel   https://blog.csdn.net/longshengguoji/article/details/9664209

但对于绑定关联表字段的栏位,没有处理到,该处何调整代码?谢谢。

如: <c1ataGridTextColumn Header="产品编号" Binding="{Binding table1.table2.Code}"/>
以上绑定关联表table2的字段Code,便导出是空。

4 个回复

倒序浏览
Ethan
葡萄城公司职员   /  发表于:2019-1-3 16:11:40
沙发
感觉是以下代码某个地方需要做调整,请帮指导一下。
if (col is DataGridTemplateColumn)
                            {
                                //This is a template column... let us see the underlying dependency object
                                DependencyObject objDO = (col as DataGridTemplateColumn).CellTemplate.LoadContent();
                                FrameworkElement oFE = (FrameworkElement)objDO;
                                FieldInfo oFI = oFE.GetType().GetField("TextProperty");
                                if (oFI != null)
                                {
                                    if (oFI.GetValue(null) != null)
                                    {
                                        if (oFE.GetBindingExpression((DependencyProperty)oFI.GetValue(null)) != null)
                                            objBinding = oFE.GetBindingExpression((DependencyProperty)oFI.GetValue(null)).ParentBinding;
                                    }
                                }
                            }
                            if (objBinding != null)
                            {
                                if (objBinding.Path.Path != "")
                                {
                                    PropertyInfo pi = data.GetType().GetProperty(objBinding.Path.Path);
                                    if (pi != null) strValue = pi.GetValue(data, null).ToString();
                                }
回复 使用道具 举报
JeffryLI
葡萄城公司职员   /  发表于:2019-1-3 17:50:45
板凳
请提供一个demo,我这边测试一下。
请点击评分,对我5分评价,谢谢!

葡萄城控件服务团队
官方网站: https://www.grapecity.com.cn/developer
回复 使用道具 举报
Ethan
葡萄城公司职员   /  发表于:2019-1-3 18:09:13
地板
回复 使用道具 举报
JeffryLI
葡萄城公司职员   /  发表于:2019-1-7 12:19:04
5#
好的,我看下
请点击评分,对我5分评价,谢谢!

葡萄城控件服务团队
官方网站: https://www.grapecity.com.cn/developer
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部