在Unity中使用NPOI

时间:2017-07-15 19:34:15

标签: c# excel unity3d npoi

我是整个npoi的新手,但我想在excel表格中为特定单元格添加一些值(“exceltest.xls,单元格A1,A2”),并从单元格 A3 中读取答案。问题是excel不重新计算公式并在此处发送旧值是代码

string path = "d:/testexcel2.xls";

HSSFWorkbook book = new HSSFWorkbook(new FileStream(@path, FileMode.Open));

ISheet sheet = book.GetSheet("sheet1");
IRow datarow = sheet.GetRow (0);
datarow.GetCell (0).SetCellValue (22222);
datarow.GetCell (1).SetCellValue (3333);
sheet.ForceFormulaRecalculation=true;
ICell res2 = sheet.GetRow (0).GetCell (2);
res=res2.NumericCellValue.ToString();
Debug.Log (res);

如何保存文件?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案

string path =  "testexcel2.xls";
        Debug.Log (path);
        no1s = no1.text;
        no2s =  no2.text;

    HSSFWorkbook book = new HSSFWorkbook(new FileStream(@path, FileMode.Open));

        ISheet sheet = book.GetSheet("sheet1");
        IRow datarow = sheet.GetRow (0);
        datarow.GetCell (0).SetCellValue (no1s);
        datarow.GetCell (1).SetCellValue (no2s);
        HSSFFormulaEvaluator.EvaluateAllFormulaCells (book);
        ICell res2 = sheet.GetRow (0).GetCell (2);
        res=res2.NumericCellValue.ToString();
        result.text = res;
        Debug.Log (res);

但是如何从资源加载文件?