EXCEL 읽기

3153 단어 Excel
            using (FileStream fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read))

            {

                HSSFWorkbook workbook = new HSSFWorkbook(fs);

                HSSFSheet sheet1 = (HSSFSheet)workbook.GetSheetAt(0);





                using (FileStream csv = new FileStream(outputFile, FileMode.Create, FileAccess.Write))

                {

                    using (StreamWriter write = new StreamWriter(csv, Encoding.UTF8))

                    {

                        for (int i = sheet1.FirstRowNum; i < sheet1.LastRowNum; i++)

                        {

                            HSSFRow row = (HSSFRow)sheet1.GetRow(i);

                            if (row == null)

                                continue;

                            string content = "";

                            for (int j = row.FirstCellNum; j < row.LastCellNum; j++)

                            {

                                HSSFCell cell = (HSSFCell)row.GetCell(j);

                                if (cell == null)

                                    continue;

                                content += cell.ToString().Replace("
", "") + ","; } content = content.Substring(0, content.Length - 1); write.WriteLine(content); } } }

좋은 웹페이지 즐겨찾기