Access導齣csv文本文件時自動爲所有數據內容加上引號併轉爲UTF-8格式
- 2017-07-26 18:15:00
- zstmtony 原創
- 6070
最近有箇客戶需要將他Excel 或Access裡的所有聯繫人的資料 一鍵導入到他的華爲手機裡。
剛開始以爲很簡單,將華爲手機的通信録導齣爲csv格式,然後用Excel打開這箇csv文本文件,再將Excel裡的其牠聯繫人資料複製到這箇文件裡麵(按衕樣的格式)
但結果髮現華爲手機無法再讀入這些修改過的csv格式,經過多次文件對比髮現
華爲手機導齣的csv文件格式有些特彆,牠的數據內容每箇字段欄位都用雙引號包括起來,
格式如下:
Family Name,Given Name,Additional Name,Prefix Name,Suffix Name,Mobile Number,Home Number,Office Number,Home Fax,Bussiness Fax,Pager,Other,customize,Home Email,Work Email,Other Email,customize,Address Home,Address Work,Address Other,customize,Organization Work,Organization Other,customize,AIM,Windows Live,YAHOO,SKYPE-USERNAME,OICQ,GOOGLE-TALK,JABBER,Notes,NickName,WebPage,Ptt/DC1,Ptt/DC2
"張三","","","","","1390000000","","","","","","","","","","","test@qq.com","","","","","廣東XXX事業部","行政助理","","","","","","","","","","","","",""
"李四",,,,,"1390000000",,,,,,,,,,,"xxxx@qq.com",,,,,"中山XXX科技",,,,,,,,,,,,,,
但Excel另存的csv格式把這些引號全去掉瞭,變成這樣瞭
Family Name,Given Name,Additional Name,Prefix Name,Suffix Name,Mobile Number,Home Number,Office Number,Home Fax,Bussiness Fax,Pager,Other,customize,Home Email,Work Email,Other Email,customize,Address Home,Address Work,Address Other,customize,Organization Work,Organization Other,customize,AIM,Windows Live,YAHOO,SKYPE-USERNAME,OICQ,GOOGLE-TALK,JABBER,Notes,NickName,WebPage,Ptt/DC1,Ptt/DC2
張三,,,,,1390000000,,,,,,,,,,,test@qq.com,,,,,廣東XXX事業部,行政助理,,,,,,,,,,,,,
後來隻有寫一箇程序專門來添加這些導齣文件的雙引號
'讀寫華爲手機導齣的通信録CSV格式 '將數據庫中的聯繫人資料自動寫入華爲手機通信録CSV格式,併自動轉換爲UTF-8格式 'Excel導齣的逗號隔開的CSV格式或導齣的Unicode的文本文件格式 數據內容都不會自動加引號,華爲手機無法正常導入 Private Sub cmdExport_Click() Dim fnum As Long Dim strPath As String Dim rs As DAO.Recordset Dim fld As DAO.Field Dim strRecord As String Dim strAll As String strPath = CurrentProject.Path If Dir(strPath & "\Export.csv") <> "" Then VBA.Kill strPath & "\Export.csv" End If If Dir(strPath & "\TPL.csv") <> "" Then VBA.FileCopy strPath & "\TPL.csv", strPath & "\Export.csv" End If fnum = FreeFile Open strPath & "\Export.csv" For Output As #fnum 'Append strAll = strAll & "Family Name,Given Name,Additional Name,Prefix Name,Suffix Name,Mobile Number,Home Number,Office Number,Home Fax,Bussiness Fax,Pager,Other,customize,Home Email,Work Email,Other Email,customize,Address Home,Address Work,Address Other,customize,Organization Work,Organization Other,customize,AIM,Windows Live,YAHOO,SKYPE-USERNAME,OICQ,GOOGLE-TALK,JABBER,Notes,NickName,WebPage,Ptt/DC1,Ptt/DC2" & vbCrLf Print #fnum, "Family Name,Given Name,Additional Name,Prefix Name,Suffix Name,Mobile Number,Home Number,Office Number,Home Fax,Bussiness Fax,Pager,Other,customize,Home Email,Work Email,Other Email,customize,Address Home,Address Work,Address Other,customize,Organization Work,Organization Other,customize,AIM,Windows Live,YAHOO,SKYPE-USERNAME,OICQ,GOOGLE-TALK,JABBER,Notes,NickName,WebPage,Ptt/DC1,Ptt/DC2" Set rs = CurrentDb.OpenRecordset("tblContact") Do While Not rs.EOF strRecord = "" For Each fld In rs.Fields strRecord = strRecord & "," & """" & rs(fld.Name) & """" Next If Len(strRecord) > 0 Then strRecord = Mid(strRecord, 2) ' Write #fnum, strRecord ' 將數據寫入文件。 '併會自動加引號 Print #fnum, strRecord strAll = strAll & strRecord & vbCrLf rs.MoveNext Loop rs.Close Close #fnum ' AnsiToUTF8 strPath & "\Export.csv", strPath & "\ExportUTF8.csv" Dim objStream As New ADODB.Stream Dim str As String '轉換爲UTF-8 With objStream .Type = 2 .Mode = 3 .Open ' .LoadFromFile strPath & "\Export.csv" .Charset = "UTF-8" '將Ansi格式轉換爲UTF-8格式 .WriteText strAll, adWriteLine .SaveToFile strPath & "\ExportUTF8.csv", adSaveCreateOverWrite .Close End With MsgBox "導齣成功,文件存放在:" & strPath & "\ExportUTF8.csv" End Sub
- office課程播放地址及課程明細
- Excel Word PPT Access VBA等Office技巧學習平颱
- 將( .accdb) 文件格式數據庫轉換爲早期版本(.mdb)的文件格式
- 將早期的數據庫文件格式(.mdb)轉換爲 (.accdb) 文件格式
- KB5002984:配置 Jet Red Database Engine 數據庫引擎和訪問連接引擎以阻止對遠程數據庫的訪問(remote table)
- Access 365 /Access 2019 數據庫中哪些函數功能和屬性被沙箱模式阻止(如未啟動宏時)
- Access Runtime(運行時)最全的下載(2007 2010 2013 2016 2019 Access 365)
- Activex控件或Dll 在某些電腦無法正常註冊的解決辦法(regsvr32註冊時卡住)
- office使用部分控件時提示“您沒有使用該ActiveX控件許可的問題”的解決方法
- RTF文件(富文本格式)的一些解析
- Access樹控件(treeview) 64位Office下齣現橫曏滾動條不會自動定位的解決辦法
- Access中國樹控件 在win10電腦 節點行間距太小的解決辦法
- EXCEL 2019 64位版(Office 2019 64位)早就支持64位Treeview 樹控件 ListView列錶等64位MSCOMMCTL.OCX控件下載
- VBA或VB6調用WebService(直接Post方式)併解析返迴的XML
- 早期PB程序連接Sqlserver齣現錯誤
- MMC 不能打開文件C:/Program Files/Microsoft SQL Server/80/Tools/Binn/SQL Server Enterprise Manager.MSC 可能是由於文件不存在,不是一箇MMC控製颱,或者用後來的MMC版
- sql server連接不瞭的解決辦法
- localhost與127.0.0.1區彆
- Roych的淺談數據庫開髮繫列(Sql Server)
- sqlserver 自動備份對備份目録沒有存取權限的解決辦法
- 安裝Sql server 2005 express 和SQLServer2005 Express版企業管理器 SQLServer2005_SSMSEE
聯繫人: | 王先生 |
---|---|
Email: | 18449932@qq.com |
QQ: | 18449932 |
微博: | officecn01 |