FileStream fileStream = new FileStream(@FileName, FileMode.Open, FileAccess.Read); FileStream fileStream2; if (FileName.IndexOf(".xlsx") > 0) // 2007版本 { workbook1 = new XSSFWorkbook(fileStream); //xlsx数据读入workbook } else if (FileName.IndexOf(".xls") > 0) // 2003版本 { workbook1 = new HSSFWorkbook(fileStream); //xls数据读入workbook } ISheet sheet = workbook1.GetSheetAt(0); //获取第一个工作表 IRow row = sheet.GetRow(0); row.Height = 20 * 20; using (fileStream2 = File.OpenWrite(FileName)) { workbook1.Write(fileStream2);//向打开的这个xls文件中写入数据 } fileStream.Close(); workbook1.Close(); fileStream2.Close(); fileStream2.Dispose();
用fileStream不知道为啥就是写不上??修改FileAccess也不行,只能再定义一个这种笨办法了