Microsoft MVP성태의 닷넷 이야기
.NET : 117. CSV 파일을 다루는 방법 [링크 복사], [링크+제목 복사],
조회: 27597
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 1개 있습니다.)

.NET에서 CSV 파일을 다루는 방법


물론, ^^ 만들어도 좋습니다. 대신, 진짜로 ", (Comma)"만을 염두에 두고 코딩을 해서는 안 됩니다. 왜냐하면 다음과 같은 데이터들도 나올 수 있기 때문입니다.

"""test""", 1, 5
==> ["test"], [1], [5]

test, "1,5", 6
==> [test], [1,5], [6]

프로그램 공부하는 거라면 느긋하게 하겠지만, 업무 프로그램 만들면서 이런 것까지 신경쓰기에는 시간이 아쉬울 때가 있는데요. 대충 얹혀가는 방법으로 2가지 정도가 있습니다.

첫 번째는, 대부분의 PC에 설치되어 있는 "Microsoft.Jet.OLEDB.4.0" 제공자를 사용하는 것입니다.

C# Tutorial - Using The Built In OLEDB CSV Parser
; http://www.switchonthecode.com/tutorials/csharp-tutorial-using-the-built-in-oledb-csv-parser

DB 처리 방법과 유사하게 CSV 파싱 기능이 제공되기 때문에 그런대로 쓸만한데요. 단점이 하나 있다면, 64비트 운영체제의 경우에 기본적으로 "Microsoft Jet 4.0 OLE DB Provider"가 없다는 것입니다.

32bit/64bit OLE DB Provider
; https://www.sysnet.pe.kr/2/0/558

그렇지만 아쉬워 하지 않아도 됩니다. 두 번째 방법이 있으니. ^^

[C#] CSV 파일 읽어 처리하는 방법 
; http://lifehack.kr/90019935782

간단히, Microsoft.VisualBasic.dll에서 제공되는 TextFieldParser 타입을 사용하시면 됩니다.

위의 2가지 방법 모두, 헤더를 포함할지 여부에 대한 지정 및 별도의 구분자(delimiter)를 지정하는 것도 가능합니다.



[연관 글]






[최초 등록일: ]
[최종 수정일: 6/28/2021]


비밀번호

댓글 작성자
 



2021-04-09 09시01분
JoshClose/CsvHelper - A library for reading and writing CSV files.
; https://github.com/JoshClose/CsvHelper

Cinchoo ETL - CSV Reader
; https://www.codeproject.com/Articles/1145337/Cinchoo-ETL-CSV-Reader
정성태

... 31  32  33  34  35  36  37  38  [39]  40  41  42  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
213정성태4/13/20068994Introduction to the MSN Messenger Activity SDK
212정성태4/13/200611042FIN_WAIT_2 상태에 대하여
211정성태4/13/20069651Override CLR Assembly Probing Logic
210정성태4/13/200610107Web.config의 기본 <appSettings /> Handler 교체
209정성태3/25/200610017Win32 FileID API Library
208정성태4/13/20069595(거의)모든 DB 에 대한 ADO.NET Data Provider (유료)목록
205정성태4/13/20069664Static Code Analyzer
206정성태4/13/20069360    답변글 Visual C++ Express를 사용한 보안 응용 프로그램 빌드
203정성태4/13/20069263WGF (Windows Graphic Foundation) [1]
202정성태4/13/20069085사용자 컴퓨터 환경 조사 결과(외국 사례)
201정성태4/13/200612826MySQLDirect .NET Data Provider
207정성태4/13/20068619    답변글 무료: Download Connector/Net 1.0 (MySQL) [1]
200정성태4/13/20069057Understanding Classic COM Interoperability With .NET Applications파일 다운로드1
199정성태4/13/20069320How to get a V2.0 ICorDebug object
198정성태4/13/20069398Whidbey breaking change --- Caching binding failures [1]
197정성태4/13/20068695The JIT does dead-code elimination in Debuggable code
195정성태4/13/20068752910442 - Working with Web Resources in ASP.NET 2.0
194정성태4/13/20069300ASP.NET 2.0 WebPart - SQL Server Error 26: Error Locating Server/Instance Specified
193정성태4/13/20069286WCF - Breaking Changes between Jan CTP and Feb CTP파일 다운로드1
192정성태4/13/20068861Cassini Update
191정성태4/13/20069918LeechBlocker ISAPI Filter
189정성태4/13/20069195The New Anonymous Types Feature in C# 3.0 [1]
188정성태3/8/20069263Microsoft Anti-Cross Site Scripting Library V1.0
196정성태4/13/20068786    답변글 왜 사용해야 하는가?
187정성태4/13/20068616제 1회 INETA 세미나
186정성태4/13/20069332Internet Information Services (IIS) 6.0 Manager for Windows XP
... 31  32  33  34  35  36  37  38  [39]  40  41  42  43  44  45  ...