Microsoft MVP성태의 닷넷 이야기
.NET : 117. CSV 파일을 다루는 방법 [링크 복사], [링크+제목 복사],
조회: 27592
글쓴 사람
정성태 (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)
269정성태5/4/20069013Visual Studio 2005 Team System Level 200 Course Material
268정성태5/4/20069285Microsoft Component Installer Software Development Kit for Windows (x86) Version 2.0
267정성태5/4/20069184101 Code Samples for Visual Basic 2005
266정성태5/3/200611012Consolas Font Pack for Microsoft Visual Studio 2006 [2]
264정성태5/1/200610191Team System for C++ Developers
262정성태5/1/200619762Registry 등록 없이 COM 개체 사용 [1]파일 다운로드2
261정성태4/30/2006100164GB 메모리 인식 [2]
259정성태4/30/20069077Building ASP.NET 2.0 Web Sites Using Web Standards
260정성태4/30/20068794    답변글 XHTML Validator Modulle
258정성태4/29/20069388WebServiceStudio 2.0
263정성태5/1/20069026    답변글 Calling an Arbitrary Web Service
257정성태4/29/20068998TypeForwardedToAttribute
256정성태4/29/20069258Windows API - Using Condition Variables
252정성태4/26/20069453한글 관련 메세지 정리파일 다운로드1
251정성태4/26/20069906IIS 7.0 에서 소개되는 새로운 기능들 [1]
250정성태4/25/200610623툴 소개: VisualNDepend
249정성태4/25/200616615Integrating a debugger into Reflector
265정성태5/1/200610859    답변글 Deblector: First Version
285정성태5/15/20068967    답변글 New Deblector version ( an Add-In to debug with reflector )
248정성태4/21/20069318VS.NET 2005 Add-In : CSS Properties Window
247정성태4/21/20069253VS.NET 2005 Add-In : Spell Checker for HTML and ASP.NET pages
244정성태4/19/20069210SQL Server 2005 Service Pack 1
241정성태4/19/20068660VSTS Annotations for C++: Beyond Just Documenting Method Behavior [1]파일 다운로드1
240정성태4/18/20069303Accessing System Power and Network Status Using SENS
253정성태4/29/20069654    답변글 [HowToUse]: Accessing System Power and Network Status Using SENS
239정성태4/18/20069231Display a Web Page in a Plain C Win32 Application
... 31  32  33  34  35  36  [37]  38  39  40  41  42  43  44  45  ...