我想在excel中写入一个值,为什么加了倒数第六-倒数第三行的代码,excel就打不开了
class Program
{
static void Main(string[] args)
{
string name = "xxx";
string TempletFileName = System.AppDomain.CurrentDomain.BaseDirectory + "Data\\excel3.xlsx";
FileStream file = new FileStream(TempletFileName, FileMode.Open, FileAccess.Read);
IWorkbook hssfworkbook = new XSSFWorkbook(file);
ISheet ws = hssfworkbook.GetSheet("Sheet1");
IRow row = ws.GetRow(1);
ICell cell = row.GetCell(19);
cell.SetCellValue(name);
Console.WriteLine(cell);
ws.ForceFormulaRecalculation = true;
using (FileStream filess = File.OpenWrite(TempletFileName))
{
hssfworkbook.Write(filess);
}
Process.Start(TempletFileName);
}