在openUI5中删除csv导出中不需要的行返回/中断

时间:2017-05-24 15:59:50

标签: data-binding export export-to-csv sapui5

我正在学习OpenUI5作为我新工作/实习的一部分,而且我在我正在研究的产品中遇到了麻烦。导出的csv是正确的,只要我们想要的所有内容都被正确导出,但如果项目的字符串/输入包含新的行字符或以enter键结束它会破坏csv导出但表格中的模型仍然正确显示

description.replace(/(\r\n|\n|\r)/gm," ");

是什么可以删除任何行返回或输入在字符串中找到但是数据绑定在此应用程序中的方式是在这种类型的结构中:

    exportType : new sap.ui.core.util.ExportTypeCSV({
                    separatorChar : "," //;
                }),
                models : table.getModel(),
                rows : {
                    path : "/interactions"
                },
                columns : [  {
                    name : "description",
                    template : {
                        content : "{description}"
                    }
                }] // There is more listings after this but it's not important
 // ... more items here
            }); // End of the bounded data to export 

如前所述,我的项目描述'可以包含换行符,但是当我在导出中转换为csv时,它会执行以下操作:

90000440,Information Protection Policy,Scene1_QuestionDraw01_Slide1_TrueFalse_0_0,The Information Security Officer is responsible for the review and revision of this policy.
(True or False),false,false,1,1

在输出的csv中不应该是实际的行返回,但由于描述中有新的行字符或行返回,因此在输出中输出一行。

导致我解决这个问题的任何数量的帮助都会很棒。

谢谢你,乔丹。

1 个答案:

答案 0 :(得分:0)

最好的方法是能够使用由criticalfix注释中指示的字符串分隔符。这通常在默认情况下有效,请参阅当前UI5代码库中的以下代码:github。可能你有一个不包含这个的UI5版本,因为这是去年夏天修复的(见this commit)。您可以在提交本身(紧靠作者行上方)中查看包含此提交的版本。

如果您无法升级到包含此提交的版本,那么您可能首先想到更换新行是合适的。您可以将格式化程序与绑定结合使用以删除换行符:

// all the stuff before
columns : [  {
    name : "description",
        template : {
            content : {
                 path: "description",
                 formatter: function (description) {
                     return description.replace(/(\r\n|\n|\r)/gm," ");
                 }
            }
        }
}]