欧美三区_成人在线免费观看视频_欧美极品少妇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條評論
主站蜘蛛池模板: 久久久久琪琪免费影院 | 天天操夜夜噜 | 久久九九国产精品怡红院 | jvid精品资源在线观看 | 欧美国产视频 | 国产亚洲精品久久久久久小说 | 波多野结衣一区二区三区 | 成人国产精品齐天大性 | 日韩国产在线观看 | 国产精品福利短视在线播放频 | 国产成人综合网在线观看 | 国产一区二区三区在线观看免费 | 亚洲一区国产二区 | 欧美a一级大片 | 午夜亚洲| 亚洲三级视频 | 亚洲欧美18v中文字幕高清 | 亚洲伦理影院 | 一区二区三区免费在线观看 | 色欧美色| 鲁丝片一区二区三区毛片 | 成人午夜大片免费看爽爽爽 | 国产91一区二这在线播放 | 久草视频在线资源 | 天天爱天天做天天干 | 欧美日韩精品一区三区 | 久久99国产亚洲精品观看 | 亚洲国产区 | 手机在线看片国产日韩生活片 | 丝袜 亚洲 另类 欧美 综合 | 亚洲人成在线播放网站 | 日韩国产一区二区三区 | 2021最新国产成人精品视频 | 久久综合九色综合欧美狠狠 | 日韩精品视频免费观看 | 日韩精品一区二区三区国语自制 | 91精品国产色综合久久不卡蜜臀 | 深夜你懂的在线网址入口 | 国产一区二区三区在线电影 | 日本特黄特色大片免费视频 | 99re6在线视频精品免费 |