2017-07-15 170 views
0

我对整个npoi事物很陌生,但我想在excel表格(“exceltest.xls,单元格A1,A2)中放入一些特定单元格的值并从单元格A3中读取答案。问题是,Excel不重新计算公式,并送来旧值是代码在Unity中使用NPOI

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

这和'unity3d'有关吗? – MickyD

+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); 

但是我怎样才能从资源加载文件?

+0

[This](https://stackoverflow.com/questions/41326248/using-resources-folder-in-unity/41326276#41326276)是如何保存和加载资源文件夹 – Programmer

+0

我试过,但你不能从资源加载HSSFWORKBOOK,它给出了一个错误 –