modFileTool 函式庫 |
風禹科技驗證有限公司 網站 提供 .Net 原始碼 |
說明
讀取 CSV 檔案
本函數之引數列表
引數 |
型態 |
位元組 |
選項 |
預設值 |
說明 |
strFile |
String |
- |
必須 |
(無) |
CSV 檔案完整路徑。 |
srcCodePage |
enuStandardCodePages |
4 |
可省略 |
SCP_big5 |
來源位元組陣列編碼方式:
常數名 |
數值 |
說明 |
SCP_CP_ACP |
0 |
預設為 ANSI 字碼頁 |
SCP_CP_OEMCP |
1 |
預設為 OEM 字碼頁 |
SCP_CP_MACCP |
2 |
|
SCP_CP_THREAD_ACP |
3 |
目前執行緒的 ANSI 字碼頁 |
SCP_CP_SYMBO |
42 |
SYMBOL 轉譯 |
SCP_ibm852 |
852 |
Central European (DOS) |
SCP_ibm866 |
866 |
Cyrillic (DOS) |
SCP_windows_874 |
874 |
Thai |
SCP_Japanese |
932 |
日文 |
SCP_cseucpkdfmtjapanese |
932 |
Japanese (EUC) |
SCP_csiso2022jp |
932 |
Japanese (JIS_Allow 1 byte Kana) |
SCP_csshiftjis |
932 |
Shift_JIS |
SCP_extended_unix_code_... |
932 |
Japanese (EUC) |
SCP_iso_2022_jp |
932 |
Japanese (JIS) |
SCP_ms_kanji |
932 |
Shift_JIS |
SCP_shift_jis |
932 |
Shift_JIS |
SCP_x_euc |
932 |
Japanese (EUC) |
SCP_x_euc_jp |
932 |
Japanese (EUC) |
SCP_x_sjis |
932 |
Shift_JIS |
SCP_chinese |
936 |
簡體中文 |
SCP_csgb2312 |
936 |
Chinese Simplified (GB2312) |
SCP_csiso58gb231280 |
936 |
Chinese Simplified (GB2312) |
SCP_gb_2312_80 |
936 |
Chinese Simplified (GB2312) |
SCP_gb2312 |
936 |
Chinese Simplified (GB2312) |
SCP_hz_gb_2312 |
936 |
Chinese Simplified (HZ) |
SCP_iso_ir_58 |
936 |
Chinese Simplified (GB2312) |
SCP_cseuckr |
949 |
Korean |
SCP_csksc56011987 |
949 |
Korean |
SCP_euc_kr |
949 |
Korean |
SCP_iso_ir_149 |
949 |
Korean |
SCP_korean |
949 |
韓文 |
SCP_ks_c_5601 |
949 |
Korean |
SCP_ks_c_5601_1987 |
949 |
Korean |
SCP_ks_c_5601_1989 |
949 |
Korean |
SCP_ksc_5601 |
949 |
Korean |
SCP_ksc5601 |
949 |
Korean |
SCP_big5 |
950 |
繁體中文 (BIG5) |
SCP_csbig5 |
950 |
繁體中文 (BIG5) |
SCP_x_x_big5 |
950 |
繁體中文 (BIG5) |
SCP_CP_Default_Windows |
1200 |
Windows |
SCP_CP_Little_Endian_Unicode |
1200 |
Windows |
SCP_CP_UTF_16LE |
1200 |
Windows |
SCP_CP_Big_Endian_Unicode |
1201 |
|
SCP_CP_UTF_16BE |
1201 |
|
SCP_windows_1250 |
1250 |
Central European (Windows) |
SCP_x_cp1250 |
1250 |
Central European (Windows) |
SCP_windows_1251 |
1251 |
Cyrillic (Windows) |
SCP_x_cp1251 |
1251 |
Cyrillic (Windows) |
SCP_ansi_x3_4_1968 |
1252 |
Western |
SCP_ansi_x3_4_1986 |
1252 |
Western |
SCP_ascii |
1252 |
Western |
SCP_cp367 |
1252 |
Western |
SCP_cp819 |
1252 |
Western |
SCP_csascii |
1252 |
Western |
SCP_ibm367 |
1252 |
Western |
SCP_ibm819 |
1252 |
Western |
SCP_iso_646_irv_1991 |
1252 |
Western |
SCP_iso_8859_1 |
1252 |
Western |
SCP_iso_8859_1_1987 |
1252 |
Western |
SCP_iso_ir_100 |
1252 |
Western |
SCP_iso_ir_6 |
1252 |
Western |
SCP_iso646_us |
1252 |
Western |
SCP_iso8859_1 |
1252 |
Western |
SCP_latin1 |
1252 |
Western |
SCP_us |
1252 |
Western |
SCP_us_ascii |
1252 |
Western |
SCP_windows_1252 |
1252 |
Western |
SCP_windows_1253 |
1253 |
Greek (Windows) |
SCP_windows_1254 |
1254 |
Turkish (Windows) |
SCP_csisolatinhebrew |
1255 |
Hebrew (ISO_Visual) |
SCP_hebrew |
1255 |
Hebrew |
SCP_iso_8859_8 |
1255 |
Hebrew (ISO_Visual) |
SCP_iso_8859_8_1988 |
1255 |
Hebrew (ISO_Visual) |
SCP_iso_ir_138 |
1255 |
Hebrew (ISO_Visual) |
SCP_windows_1255 |
1255 |
Hebrew |
SCP_windows_1256 |
1256 |
Arabic |
SCP_windows_1257 |
1257 |
Baltic (Windows) |
SCP_windows_1258 |
1258 |
Vietnamese |
SCP_CP_ASCII |
20127 |
|
SCP_cskoi8r |
20866 |
Cyrillic (KOI8_R) |
SCP_koi8_r |
20866 |
Cyrillic (KOI8_R) |
SCP_csisolatin2 |
28592 |
Central European (ISO) |
SCP_iso_8859_2 |
28592 |
Central European (ISO) |
SCP_iso_8859_2_1987 |
28592 |
Central European (ISO) |
SCP_iso_ir_101 |
28592 |
Central European (ISO) |
SCP_iso8859_2 |
28592 |
Central European (ISO) |
SCP_l2 |
28592 |
Central European (ISO) |
SCP_latin2 |
28592 |
Central European (ISO) |
SCP_csiso2022kr |
50225 |
Korean (ISO) |
SCP_iso_2022_kr |
50225 |
Korean (ISO) |
SCP_CP_GB18030 |
54936 |
簡體中文 |
SCP_CP_UTF7 |
65000 |
Unicode (UTF_7) |
SCP_CP_UTF8 |
65001 |
Unicode (UTF_8) |
|
bChangeVariant |
Boolean |
2 |
可省略 |
False |
是否依資料內容轉換為對應型態。 |
傳回值
傳回物件陣列
範例
Dim arrCSV As Object = MyReadCSVFile("D:\Staff\南區水資源局\區域水資源營運管理\個人\鄭子璉\程式\測試\10Day\Kaohsiung\out.csv", , True)
Dim ibr, ibc As Integer
For ibr = 0 To UBound(arrCSV)
For ibc = 0 To UBound(arrCSV(ibr))
Debug.Write(arrCSV(ibr)(ibc) & "(" & TypeName(arrCSV(ibr)(ibc)) & ")" & vbTab)
Next
Debug.WriteLine("")
Next
更進一步
本函數可處理非 ANSI 編碼之檔案,若檔案為非 big5 編碼,則需指定 srcCodePage 編碼。
本函數需呼叫字串工具模組的 SplitMixDelimiterString 分割 CSV 檔,可分割複雜的 CSV 格式,可處理 " 及 "" 的轉換,需引用字串工具模組。
傳回的陣列使用方式為 陣列(行)(欄) ,以 0 為基底,例如 Excel 內之 C2 則使用 陣列(1)(2) 。
基本條件
Visual Studio .Net 2002 以後相容版本 | 需同時引用modStrTools模組 | FileTool.vb
請參閱
modFileTool 函式庫 | MyGetFullTextFile | SplitMixDelimiterString