欧美三区_成人在线免费观看视频_欧美极品少妇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條評論
主站蜘蛛池模板: 久久精品视频日本 | 婷婷国产成人久久精品激情 | 亚洲日本va在线视频观看 | 97玖玖 | 色综合激情 | 亚洲精品一区二区三区在线看 | 中文字幕免费在线观看视频 | 深夜福利久久久 | 精品一区二区三区免费站 | 色在线看 | 国产成人精品日本亚洲麻豆 | 情侣av| 91 在线观看 | 男女国产视频 | 黄色在线播 | 日本aaa级片 | 国产a视频 | 亚洲国产第一页 | 久久久久成人精品免费播放动漫 | 欧美free性| 综合爱爱| 国产日产精品一区二区三区四区 | 亚洲欧美中文日韩在线 | 夜夜操夜夜骑 | 国产欧美综合一区二区 | 久久久久久免费一区二区三区 | v视界成人影院在线视频 | 婷婷精品 | 2019偷偷狠狠的日日 | 久久久噜噜噜久久中文字幕色伊伊 | 国产午夜大片 | 99久久久无码国产精品 | 成人精品在线 | 精品视频一区二区三区四区 | 婷婷综合久久狠狠色99h | 日韩中文有码高清 | 久久综合狠狠色综合伊人 | 婷婷在线网 | 亚洲精品无码成人A片色欲 亚洲欧美日韩激情在线观看 | 日韩精品一区二区三区 | 亚洲欧美日韩精品久久奇米色影视 |