2009-12-09 64 views
1

考慮下面的代碼:Aspose-Cells:我如何評估一個公式?

using Aspose.Cells 
// {...} 
Workbook workbook = new Workbook(); 
Worksheet virtualWorksheet = workbook.Worksheets[0]; 
virtualWorksheet.Cells[0, 0].Formula ="=1<2"; 

如何評估在單元格[0,0]公式?

bool isCellTrue = virtualWorksheet.Cells[0, 0].BoolValue; // will generate an exception at run-time 

回答

1

來自:http://www.aspose.com/community/forums/permalink/212217/212232/showthread.aspx#212232

呼叫Workbook.CalculateFormula()方法來計算所有公式在工作簿獲取/在運行時檢索計算出的值,例如前

Workbook workbook = new Workbook(); 
Worksheet virtualWorksheet = workbook.Worksheets[0]; 
virtualWorksheet.Cells[0, 0].Formula ="=1<2"; 
workbook.CalculateFormula(); 
bool isCellTrue = virtualWorksheet.Cells[0, 0].BoolValue;