Расчет формул рабочей книги
Contents
[
Hide
]
Расчет формул рабочей книги
Пожалуйста, используйтеIWorkbook->Вычислитьформулу()метод для расчета формул вашей рабочей тетради. В следующем примере кода объясняется использование этого метода.
Образец кода
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Create a new workbook | |
intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook(); | |
//Get first worksheet which is created by default | |
intrusive_ptr<IWorksheet> ws = wb->GetIWorksheets()->GetObjectByIndex(0); | |
//Adding a value to "A1" cell | |
intrusive_ptr<ICell> cell = ws->GetICells()->GetObjectByIndex(new String("A1")); | |
cell->PutValue(5); | |
//Adding a value to "A2" cell | |
cell = ws->GetICells()->GetObjectByIndex(new String("A2")); | |
cell->PutValue(15); | |
//Adding a value to "A3" cell | |
cell = ws->GetICells()->GetObjectByIndex(new String("A3")); | |
cell->PutValue(25); | |
//Adding SUM formula to "A4" cell | |
cell = ws->GetICells()->GetObjectByIndex(new String("A4")); | |
cell->SetFormula(new String("=SUM(A1:A3)")); | |
//Calculating the results of formulas | |
wb->CalculateFormula(); | |
//Get the calculated value of the cell "A4" and print it on console | |
cell = ws->GetICells()->GetObjectByIndex(new String("A4")); | |
StringPtr sCalcuInfo = new String(L"Calculated Value of Cell A4: "); | |
Console::WriteLine(sCalcuInfo->StringAppend(cell->GetStringValue())); |
Консольный вывод
Это консольный вывод приведенного выше примера кода.
Calculated Value of Cell A4: 45