我收到来自服务器的CSV文件。其中的数据以分号分隔,并且采用UTF-8格式。例如,我们收到的数据是:
"NL 我喜"" mutilple""我喜"
当我们在中首次打开它时Excel 2010
,它将显示为
NL 我喜" mutilple"我喜
但是,当我修改(我刚刚从上面的文本中删除字母L)此文件并使用excel将其保存为CSV并第二次打开时,它看起来像
N inbetween我喜
(不带双引号)
我希望修改后的数据用双引号保存。
谢谢
我写了一个VBA宏,逻辑是:
double quote
数据单元格中有任何内容,则重复双引号。comman
或double quote
在数据单元存在,则括用双引号整个数据。例子:
NL 我喜" mutilple"我喜
将成为NL 我喜"" mutilple""我喜
"NL 我喜"" mutilple""我喜"
此代码与上面的描述匹配
tempString = Sheets(1).Cells(lRow, lCol).Text ' Get the data from cell.
tempString = Replace(tempString, Chr(34), Chr(34) & Chr(34)) ' If there is double quote, then duplicate it.
CurrTextStr = tempString
pos1 = InStr(tempString, Chr(34)) ' Get the position of double quote. If not present, it will be 0.
pos2 = InStr(tempString, ";") ' Get the position of semicolon. If not present, it will be 0.
If (pos1 <> 0 Or pos2 <> 0) Then ' If there is any double quote or semicolon, then the whole data
CurrTextStr = Chr(34) & tempString & Chr(34) ' should be enclosed with double quotes.
End If
oAdoS.WriteText (";" & CurrTextStr)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句