티스토리 뷰

using(OpenFileDialog ofd = new OpenFileDialog() {  Filter="Excel WorkBook|*.xlsx",ValidateNames = true })
            {
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    FileStream fs = File.Open(ofd.FileName, FileMode.Open, FileAccess.Read);

 
                    if(Path.GetExtension(ofd.FileName).ToUpper() == ".XLS")
                    {
                        reader = ExcelReaderFactory.CreateBinaryReader(fs);
                    }
                    else if(Path.GetExtension(ofd.FileName).ToUpper() == ".XLSX")
                    {
                        reader = ExcelReaderFactory.CreateOpenXmlReader(fs);
                    }
                    else
                    {
                        
                    }
                    
                    result = reader.AsDataSet(new ExcelDataSetConfiguration() // IsFirstRowColumnNames 
                    {
                        ConfigureDataTable = (_) => new ExcelDataTableConfiguration()
                        {
                            UseHeaderRow = true
                        }
                    });
 
                    comboBox1.Items.Clear();
 
                    foreach(DataTable dt in result.Tables)
                    {
                        comboBox1.Items.Add(dt.TableName);
                        reader.Close();
                    }
  



ExcelDataReader 를 이용하여 파일 읽을 때 기존에 있는 자료들로는

reader.IsFirstRowColumnNames = true; 

를 체크하게 되어있는데 현재 최신으로 업데이트 되어있는 API에는 

해당 IsFirstRowColumnNames 메서드가 AsDataSet 메서드에 포함되었습니다.

댓글