欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

Create a CSV file

系統 2634 0

Create a CSV file | Groovy Examples

Create a CSV file

For this example, let’s assume we have an array of maps as our data.

            
              def
            
             planets 
            
              =
            
            
              [
            
            
              [
            
            id:
            
              '1'
            
            ,color:
            
              'red'
            
            ,planet:
            
              'mars'
            
            ,description:
            
              'Mars, the "red" planet'
            
            
              ]
            
            ,
    
            
              [
            
            id:
            
              '2'
            
            ,color:
            
              'green'
            
            ,planet:
            
              'neptune'
            
            ,description:
            
              'Neptune, the "green" planet'
            
            
              ]
            
            ,
    
            
              [
            
            id:
            
              '3'
            
            ,color:
            
              'blue'
            
            ,planet:
            
              'earth'
            
            ,description:
            
              'Earth, the "blue" planet'
            
            
              ]
            
            ,

            
              ]
            
          

Next, we can create our CSV file as follows:

            
              def
            
             out 
            
              =
            
            
              new
            
            
              File
            
            
              (
            
            
              'planets.csv'
            
            
              )
            
            
planets.
            
              each
            
            
              {
            
            
              def
            
             row 
            
              =
            
            
              [
            
            it.
            
              id
            
            , it.
            
              color
            
            , it.
            
              planet
            
            
              ]
            
            
    out.
            
              append
            
             row.
            
              join
            
            
              (
            
            
              ','
            
            
              )
            
            
    out.
            
              append
            
            
              '
              
                \n
              
              '
            
            
              }
            
          

Which creates a file with the following content:

        1,red,mars
2,green,neptune
3,blue,earth

      

However, this does not contain our description field. If you need to also handle double quotes and commas in your data then you can:

  1. qualify your values with a double quote, and
  2. replace double quotes in your data with an escaped double quote.

In this case our code may look like:

            
              def
            
             out 
            
              =
            
            
              new
            
            
              File
            
            
              (
            
            
              'planets.csv'
            
            
              )
            
            
planets.
            
              each
            
            
              {
            
            
              def
            
             row 
            
              =
            
            
              [
            
            it.
            
              id
            
            , it.
            
              color
            
            , it.
            
              planet
            
            , it.
            
              description
            
            
              ]
            
            
                        .
            
              collect
            
            
              {
            
            
              '"'
            
            
              +
            
             it.
            
              replace
            
            
              (
            
            
              '"'
            
            ,
            
              '""'
            
            
              )
            
            
              +
            
            
              '"'
            
            
              }
            
            
    out.
            
              append
            
             row.
            
              join
            
            
              (
            
            
              ','
            
            
              )
            
            
    out.
            
              append
            
            
              '
              
                \n
              
              '
            
            
              }
            
          

Which creates a file with the following content:

        "1","red","mars","Mars, the ""red"" planet"
"2","green","neptune","Neptune, the ""blue"" planet"
"3","blue","earth","Earth, the ""blue"" planet"
      

Create a CSV file


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 色www 永久免费网站 | 99热国产精品 | 最新中文字幕日本 | 久久久久久亚洲精品 | 欧美卡一卡二卡新区网站 | 日本黄视色视频在线观看 | 99亚洲视频| 欧美一级特黄aaaaaaa在线观看 | 亚洲一二三区视频 | 五月婷婷综合在线视频 | 色婷婷精品综合久久狠狠 | 久久久精品免费热线观看 | 欧美色xx | av大片| 天堂网果冻传媒 | 国产精品福利视频免费观看 | 国产一区在线播放 | 久久草在线视频国产一 | 欧美a性| 国产一级毛片高清视频 | 福利色 | 国产gav成人免费播放视频 | 青青艹视频在线 | 这里只有精品视频 | 国内精品视频在线观看 | 午夜精品一区二区三区在线观看 | 天天射天天操天天 | 日韩福利在线 | 91精品国产日韩91久久久久久 | 欧美一区二区在线播放 | 国产一级毛片夜一级毛片 | 欧美一区二区三区大片 | 91久操| 国产片侵犯亲女视频播放 | 一区二区不卡在线观看 | 亚洲国产精品人人爽夜夜爽 | 国产美女自卫慰视频福利 | 精品国产成a人在线观看 | 特黄特色大片免费高清视频 | 久久综合九色综合97婷婷群聊 | 免费一级毛片在线播放视频 |