EPPlus 3.1 简单操作 Excel 2007/2010

using (ExcelPackage excelPackage = new ExcelPackage(new FileInfo(xlsxfullname)))
{
                ExcelWorkbook wp = excelPackage.Workbook;
                ExcelWorksheet sh = wp.Worksheets[sheetname];
                int col = 1; //1 为起始列
                int rowindex = 1; //1为起始行
                while (true)
                {
                    //取某行的一个单元格
                    ExcelRange cell = sh.Cells[rowindex, col];
                    if (cell.Value == null || cell.Value.ToString() == "")
                    {
                        break;
                    }

                    //修改单元格
                    cell.Value= "123456";

                    //取某行的多个单元格
                    //ExcelRange cells= sh.Cells[rowIndex,1,rowIndex,13];
                    
                    rowindex++;
                }
                //保存当前Excel文件
                excelPackage.Save();           
}
  

 

posted @ 2013-03-07 09:06  Yu  阅读(428)  评论(0编辑  收藏  举报