View
![](https://blog.kakaocdn.net/dn/bTJnw9/btsytu8ioGK/Gz8H4oHqlSWu5qisiKfANK/img.png)
👉오늘의 목적
xlsx 파일을 넣고 해당 엑셀 데이터를 가져오자
😙 ExcelDatareader DLL 다운로드하기
[C# :: 엑셀 데이터 불러오기 , 가져오기 (Read data from excel file)
예전에 SheetJS를 이용해서 엑셀데이터를 가져오고 엑셀을 시트별로 만드는 것을 했었는데 javascript :: SheetJS 테이블들 엑셀 시트 별로 다운로드하기 이번에 엑셀다운로드를 구현하는 일을 맡게 되
w94dev.tistory.com](https://w94dev.tistory.com/53)
ExcelDatareader DLL을 통해 엑셀 데이터를 가져오는 방법을 예전에 한 번 작성한 적이 있다.
이 포스팅대로 Nuget 패키지관리에서 ExcelDatareader DLL 두 가지를 모두 다운로드 받아서 사용하면 된다.
😙 CS 파일
using ExcelDataReader;
using OfficeOpenXml;
protected void ChkWithDB(object sender, EventArgs e)
{
HttpPostedFile upFile= fileUpload.PostedFile;
if (upFile== null || upFile.ContentLength == 0)
{
// 경고 메세지 띄워주기
return;
}
//첨부파일 스트림
var upFileStream = upFile.PostedFile.InputStream;
//첨부파일 데이터 읽어오는 부분
using (var reader = ExcelReaderFactory.CreateReader(upFileStream )) //ExcelDataReader
{
var result = reader.AsDataSet().Tables[0];
}
}
먼저 엑셀을 사용하기 위해 using ExcelDataReader;을 해준다.
업로드한 xlsx 파일을 읽어오기 위해 using OfficeOpenXml;도 해준다.
업로드한 파일을 읽어오는 부분에서 나는 무조건 'xlsx' 형태의 파일만 넣을 계획이라 ExcelReaderFactory.CreateReader 를 사용하여 데이터를 읽어오기로 했다.
엑셀에도 다양한 파일 형식이 있기 때문에 해당 형식에 따라 알맞은 함수를 사용하면 된다.
해당 내용은 위에 첨부한 엑셀데이터 불러오기 포스팅에 자세하게 적혀있습니다 😁
이렇게 2편도 끝!
🐟 관련글
0. C# :: 엑셀 데이터와 데이터 베이스 데이터 비교하여 결과 엑셀 다운로드 하기 (0편)
1. C# :: ASP프레임 워크에서 클릭된 버튼 ID 가져오기 (How to get the ID of the clicked button)
2. C# :: ExcelDatareader DLL 을 이용한 엑셀데이터 가져오기
![](https://t1.daumcdn.net/keditor/emoticon/friends1/large/019.gif)
'C#' 카테고리의 다른 글
C# :: ASP프레임 워크에서 클릭된 버튼 ID 가져오기 (How to get the ID of the clicked button) (0) | 2023.10.13 |
---|---|
C# :: 엑셀 데이터와 데이터 베이스 데이터 비교하여 결과 엑셀 다운로드 하기 (0편) (0) | 2023.10.12 |
C# :: String.Equals 메소드 사용하기 (0) | 2023.10.11 |
C# :: 엑셀 데이터 불러오기 , 가져오기 (Read data from excel file) (0) | 2022.07.13 |
C# :: 비밀번호 같은 문자 3번 체크 , 연속된 키보드 문자열 체크 (0) | 2022.03.10 |