2017-05-24 53 views
3

我正在學習OpenUI5作爲我的新工作/實習的一部分,並且在我正在處理的產品中遇到了一些障礙。導出的csv是正確的,只要我們想要的所有內容都被正確導出,但是如果項目的字符串/輸入包含新的行字符,或者以回車鍵結束,它會中斷csv導出,但表格中的模型仍能正確顯示。在openUI5中刪除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

有時候字符串分隔符來存放,否則將打破CSV字符,如逗號,換行,比如:'1,約翰,「這字符串有一個偶然的逗號,這裏是「,516」。常用的字符串分隔符包括單引號或雙引號,還包括管道符號等。 – criticalfix

回答

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," "); 
       } 
      } 
     } 
}]