NPIO 로 Excel 조작 하기

4206 단어 Excel
using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using NPOI.SS.UserModel;

using NPOI.HSSF.UserModel;

using System.IO;



namespace _02  NOPI  excel

{

    class Program

    {

        static void Main(string[] args)

        {

            //1、  EXCEL Filestream

            using (FileStream fs = File.OpenRead("1.xls"))

            {

                //2、     fs    Workbook

                using (Workbook wk = new HSSFWorkbook(fs))

                {

                    //3、            wk.NumberOfSheets

                    for (int i = 0; i < wk.NumberOfSheets; i++)

                    {

                        //4、         

                        using (Sheet sheet = wk.GetSheetAt(i))

                        {

                           Console.WriteLine("===================={0}===============", sheet.SheetName);

                            //5、       sheet.LastRowNum         

                            for (int r = 0; r <= sheet.LastRowNum; r++)

                            {

                               

                                Row row = sheet.GetRow(r);

                                //6、        

                                for (int c = 0; c < row.LastCellNum; c++)

                                {

                                     Cell cell = row.GetCell(c);

                                     Console.Write(cell.ToString()+"\t");

                                 }

                                 Console.WriteLine();

                            }

                        }

                    }

                }

            }

            Console.ReadKey();

        }

    }

}

좋은 웹페이지 즐겨찾기