简体   繁体   中英

Export TableView Data to CSV-file

How can I export my Tableview Cell Datas to an CSV-File? I will send this csv file as an Email attachment? Thanks for helping!!!

Since your data is an array (that is your Data Model!) and assuming its contents are type String you can convert it to another comma separated string using a simplified implementation shown below. You need to insert the code after you have done creating the array. Populating the table view is a separate issue unless you are using the table to create or modify the data array. Swift has powerful String handling capability and there is a more compact way of doing this. Also, you have more to do if you want to send the email directly from your view controller or if you want to save it locally or in the cloud.

import UIKit

var str = ["A","B","C"]
var csv:String = ""
var tmp = ""
for x in str {
    if x != str.last {
        csv += x+","
    } else {
        csv += x
}
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM