Access導(dǎo)齣csv文本文件時(shí)自動(dòng)爲(wèi)所有數(shù)據(jù)內(nèi)容加上引號(hào)併轉(zhuǎn)爲(wèi)UTF-8格式
- 2017-07-26 18:15:00
- zstmtony 原創(chuàng)
- 6276
最近有箇客戶需要將他Excel 或Access裡的所有聯(lián)繫人的資料 一鍵導(dǎo)入到他的華爲(wèi)手機(jī)裡。
剛開(kāi)始以爲(wèi)很簡(jiǎn)單,將華爲(wèi)手機(jī)的通信録導(dǎo)齣爲(wèi)csv格式,然後用Excel打開(kāi)這箇csv文本文件,再將Excel裡的其牠聯(lián)繫人資料複製到這箇文件裡麵(按衕樣的格式)
但結(jié)果髮現(xiàn)華爲(wèi)手機(jī)無(wú)法再讀入這些修改過(guò)的csv格式,經(jīng)過(guò)多次文件對(duì)比髮現(xiàn)
華爲(wèi)手機(jī)導(dǎo)齣的csv文件格式有些特彆,牠的數(shù)據(jù)內(nèi)容每箇字段欄位都用雙引號(hào)包括起來(lái),
格式如下:
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事業(yè)部","行政助理","","","","","","","","","","","","",""
"李四",,,,,"1390000000",,,,,,,,,,,"xxxx@qq.com",,,,,"中山XXX科技",,,,,,,,,,,,,,
但Excel另存的csv格式把這些引號(hào)全去掉瞭,變成這樣瞭
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事業(yè)部,行政助理,,,,,,,,,,,,,
後來(lái)隻有寫(xiě)一箇程序?qū)iT(mén)來(lái)添加這些導(dǎo)齣文件的雙引號(hào)
'讀寫(xiě)華爲(wèi)手機(jī)導(dǎo)齣的通信録CSV格式 '將數(shù)據(jù)庫(kù)中的聯(lián)繫人資料自動(dòng)寫(xiě)入華爲(wèi)手機(jī)通信録CSV格式,併自動(dòng)轉(zhuǎn)換爲(wèi)UTF-8格式 'Excel導(dǎo)齣的逗號(hào)隔開(kāi)的CSV格式或?qū)i的Unicode的文本文件格式 數(shù)據(jù)內(nèi)容都不會(huì)自動(dòng)加引號(hào),華爲(wèi)手機(jī)無(wú)法正常導(dǎo)入 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 ' 將數(shù)據(jù)寫(xiě)入文件。 '併會(huì)自動(dòng)加引號(hào) 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 '轉(zhuǎn)換爲(wèi)UTF-8 With objStream .Type = 2 .Mode = 3 .Open ' .LoadFromFile strPath & "\Export.csv" .Charset = "UTF-8" '將Ansi格式轉(zhuǎn)換爲(wèi)UTF-8格式 .WriteText strAll, adWriteLine .SaveToFile strPath & "\ExportUTF8.csv", adSaveCreateOverWrite .Close End With MsgBox "導(dǎo)齣成功,文件存放在:" & strPath & "\ExportUTF8.csv" End Sub
- office課程播放地址及課程明細(xì)
- Excel Word PPT Access VBA等Office技巧學(xué)習(xí)平颱
- 將( .accdb) 文件格式數(shù)據(jù)庫(kù)轉(zhuǎn)換爲(wèi)早期版本(.mdb)的文件格式
- 將早期的數(shù)據(jù)庫(kù)文件格式(.mdb)轉(zhuǎn)換爲(wèi) (.accdb) 文件格式
- KB5002984:配置 Jet Red Database Engine 數(shù)據(jù)庫(kù)引擎和訪問(wèn)連接引擎以阻止對(duì)遠(yuǎn)程數(shù)據(jù)庫(kù)的訪問(wèn)(remote table)
- Access 365 /Access 2019 數(shù)據(jù)庫(kù)中哪些函數(shù)功能和屬性被沙箱模式阻止(如未啟動(dòng)宏時(shí))
- Access Runtime(運(yùn)行時(shí))最全的下載(2007 2010 2013 2016 2019 Access 365)
- access vba代碼太長(zhǎng),換行,分行的寫(xiě)法
- VB6 VBA Access真正可用併且完美支持中英文的 URLEncode 與 URLDecode 函數(shù)源碼
- 自定義VB中的urlencode函數(shù),將URL中特殊部分進(jìn)行編碼
- Access 函數(shù)簡(jiǎn)化串接sql字符串,減少符號(hào)導(dǎo)緻的書(shū)寫(xiě)錯(cuò)誤
- vba完全關(guān)閉IE瀏覽器及調(diào)用IE瀏覽器的簡(jiǎn)單應(yīng)用
- 利用FollowHyperlink方法打開(kāi)超鏈接提示“無(wú)法下載您要求的信息”的解決方案
- 在access中用代碼打開(kāi)文本框中超鏈接地址
- Activex控件或Dll 在某些電腦無(wú)法正常註冊(cè)的解決辦法(regsvr32註冊(cè)時(shí)卡?。?/a>
- office使用部分控件時(shí)提示“您沒(méi)有使用該ActiveX控件許可的問(wèn)題”的解決方法
- RTF文件(富文本格式)的一些解析
- Access樹(shù)控件(treeview) 64位Office下齣現(xiàn)橫曏滾動(dòng)條不會(huì)自動(dòng)定位的解決辦法
- Access中國(guó)樹(shù)控件 在win10電腦 節(jié)點(diǎn)行間距太小的解決辦法
- EXCEL 2019 64位版(Office 2019 64位)早就支持64位Treeview 樹(shù)控件 ListView列錶等64位MSCOMMCTL.OCX控件下載
- VBA或VB6調(diào)用WebService(直接Post方式)併解析返迴的XML
- 早期PB程序連接Sqlserver齣現(xiàn)錯(cuò)誤
- MMC 不能打開(kāi)文件C:/Program Files/Microsoft SQL Server/80/Tools/Binn/SQL Server Enterprise Manager.MSC 可能是由於文件不存在,不是一箇MMC控製颱,或者用後來(lái)的MMC版
- sql server連接不瞭的解決辦法
- localhost與127.0.0.1區(qū)彆
- Roych的淺談數(shù)據(jù)庫(kù)開(kāi)髮繫列(Sql Server)
- sqlserver 自動(dòng)備份對(duì)備份目録沒(méi)有存取權(quán)限的解決辦法
- 安裝Sql server 2005 express 和SQLServer2005 Express版企業(yè)管理器 SQLServer2005_SSMSEE
聯(lián)繫人: | 王先生 |
---|---|
Email: | 18449932@qq.com |
QQ: | 18449932 |
微博: | officecn01 |