关于c#操作excel的问题
创建完excel后,需要做一些合并单元格之类的操作,正常运行不报错,但是没反应
打断点后,发现workbook报IsReadOnly = {"未实现该方法或操作。"}
FileStream file = new FileStream(saveFileDialog.FileName, FileMode.Open, FileAccess.Read);
IWorkbook workbook = null;
if (Path.GetExtension(saveFileDialog.FileName) == ".xls")
{
workbook = new HSSFWorkbook(file);
}
else if (Path.GetExtension(saveFileDialog.FileName) == ".xlsx")
{
workbook = new XSSFWorkbook(file);
}
ISheet sheet = workbook.GetSheetAt(0);
int rowHeight = sheet.DefaultRowHeight;
//NPOI.SS.Util.CellRangeAddress cellRangeAddress = new NPOI.SS.Util.CellRangeAddress(2, 5, 0, 3);
// sheet.AddMergedRegion(cellRangeAddress);
sheet.AddMergedRegion(new CellRangeAddress(0, 6, 0, 4));
sheet.GetRow(2).GetCell(1).SetCellValue("1111111");
file.Close();
//SetCellRangeAddress(sheet, 2, 5, 0, 3);
System.Diagnostics.Process.Start(fileName);