This is a created article in which the information may have evolved or changed. "' go//export device list information to Csvfunc (BA *businessactor) exportdevicelistinfo (devicelist []device]. Alldevice, filename string) error {//create file NewFile, err: = OS. Create (filename) if err! = Nil {return errors. Wrap (Err, "Create file Failed")}defer func () {Newfile.close ()} ()//write Utf-8newfile.writestring ("\XEF\XBB\XBF")//write UTF-8 BOM, Prevent Chinese garbled//write data to csv file W: = csv. Newwriter (newFile) Header: = []string{"Room Number", "door lock signal", "Lock Charge", "Pomelo Control Name", "Pomelo Control Status"}//Title data: = [][]string{header,}for k, _: = Ran GE devicelist {hostisonline: = "" If DEVICELIST[K]. boxonline {hostisonline: = "Online"} else {hostisonline: = "Offline"}context: = []string{devicelist[k]. Roomname,strconv. Itoa (Devicelist[k]. Rssi) + "%", StrConv. Itoa (Devicelist[k]. Electric) + "%", devicelist[k]. Boxname,hostisonline,}data = Append (data, context)}//Writeall method uses the Write method to write multiple records to W, and at last calls the Flush method to empty the cache. W.writeall (data) W.flush () Return err} "344 reads
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service