NPOI处理Excel

using NPOI;
using NPOI.XSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.HSSF.UserModel;



                NPOI.SS.UserModel.IWorkbook excelbook = null;
                using (FileStream fs = new FileStream(Path, FileMode.OpenOrCreate, FileAccess.ReadWrite))
                {
                    if (fix == ".xls")
                    {
                        excelbook = new HSSFWorkbook(fs);
                    }
                    else if (fix == ".xlsx")
                    {
                        excelbook = new XSSFWorkbook(fs);
                    }
                

                    ISheet sheet = excelbook.GetSheetAt(0);

                    for (int i = 1; i < sheet.LastRowNum; i++)
                    {
                        IRow row = sheet.GetRow(i);

                        foreach (var item in row.Cells)
                        {
                            item.SetCellType(CellType.String);
                        }
                        var data = row.Cells[0].StringCellValue;
                        var data2 = row.Cells[1].StringCellValue;

                    }
                }

 

上一篇:Python 之路Day13


下一篇:并发包