|
发表于 2013-7-20 10:58:44
|
显示全部楼层
本帖最后由 i-wiki 于 2013-7-20 20:04 编辑
: `4 r4 Q% S1 @' r
$ J% l% Y& y6 n0 i7 Z7 a! ~为什么要使用FSO?VBA有自己的文件处理语句,可以对文本或二进制数据操作,结合kernel32函数调用可完成Unicode到utf8代码转换。 M$ h$ E" G9 W3 o: r
程序中疑似函数tran_ado转换时,从流中读出并返回串时有问题。
! `7 w* z5 C+ q. _1 w# U4 M5 s5 H" ^ADODB的Stream本身就可以保存为文件,试一试下面代码如何?- Sub main(), Z) J! C) v: {! S0 K
- Dim i As Integer2 H: u, S# h3 x1 _7 |6 G
- Dim sft As String
) n O4 q0 a% i9 u) ~$ L8 B0 c& ` - Dim spy As String* ~8 a' ~4 B& U6 {$ S7 W$ I9 F
- Dim szm As String
. F R2 b! s/ I$ ?! P5 O - Dim s As String
. e# q/ k7 z) v9 F* X/ z/ M* [( X) }2 p - Dim Stm As New ADODB.Stream8 H( A2 F- }! c" r0 m
- - i" K8 A; }) ]1 P! y) i
- Stm.Type = adTypeText
9 U$ k; e- ~/ f- \ - Stm.Mode = adModeUnknown
! n, I! y& D* [6 A4 c9 L& m& n - Stm.Open
+ |9 a7 \% |& Z - Stm.Charset = "utf-8"
( A5 d3 v$ @* o
% X! X) Y* Q1 t, _- For i = 1 To 7
0 `0 @0 @$ F$ u3 m - sft = Cells(i, 1)
; d6 e; d, b& h6 f - szm = Cells(i, 2)# d- a% ]4 l5 @, U1 W
- spy = Cells(i, 3)4 y$ J0 D7 b9 P6 ]$ S9 m% x
- s = "<a href=""entry://" & sft & "/"">" & sft & "</a>" & spy & "/" & szm* t( v6 M* i: Z( x. V8 Q, w. ?
) ^- K9 Z; w; ~( _& l- Stm.WriteText s & vbLf( D! s+ O" r7 N' D9 w* U" A& D
- Next
: ]* q6 k& e* J; h+ U- b# s
5 e( C% j' s: ` `) s+ f5 ~- If Dir("z:\vba.txt") <> "" Then Kill "z:\vba.txt"
1 X: l" N# L/ |5 m: J - Stm.SaveToFile "z:\vba.txt"
8 i6 n; Z! y" `9 x - Stm.Close
" y( G0 Z( L# I m# q - End Sub& f }* F! w2 W! _$ O/ I R
复制代码 |
|