//FileStream stream = new FileStream(@"C:Documents and SettingsAdministrator桌面2.xls", FileMode.OpenOrCreate, FileAccess.ReadWrite); // HSSFWorkbook workbook=new HSSFWorkbook(stream); //读出来第一个sheet第一列第一行的东东 //HSSFSheet sheet=workbook.GetSheetAt(0);//第一个sheet //HSSFRow row=sheet.GetRow(0);//第一行 //HSSFCell cell=row.GetCell(0);//第一列 //MessageBox.Show(cell.StringCellValue); //写入东西 HSSFWorkbook workbook = new HSSFWorkbook();//引入的using NPOI.HSSF.UserModel;new一个hssfworkbook对象 HSSFSheet sheet = workbook.CreateSheet();//workbook对象创建一个sheet for (int i = 0; i < 254; i++) { for (int j = 0; j < 255; j++) { HSSFRow row = sheet.CreateRow(i);//sheet创建一个行 HSSFCell cell1 = row.CreateCell(j, HSSFCell.CELL_TYPE_NUMERIC);//row创建一个列(第几列,内容的类型) cell1.SetCellValue(i.ToString() + "," + j.ToString());//对这个cell1格子填东西 } } using (FileStream stream = new FileStream(@"C:Documents and SettingsAdministrator桌面2.xls", FileMode.OpenOrCreate, FileAccess.ReadWrite)) { workbook.Write(stream); }//new一个流,打开2.xls,openorcreat没有就创建一个,可读可写。