0

I am new to the whole npoi thing but I want to put some values to specific cells in excel sheet ("exceltest.xls , cell A1,A2 ) and read the answer from cell A3. The problem is the excel doesn't recalculate the formula and send the old value here is the code

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

How to save the file?

1 Answers1

0

I found a solution

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

But How can i load the file from resources?