Specify Maximum Rows of Shared Formula with C++
Possible Usage Scenarios
The default maximum rows of the shared formula are 64. It could be any number e.g., it could be 1000. The performance of the shared formula changes with a different number of rows. Therefore, Aspose.Cells provides the GetMaxRowsOfSharedFormula() property that can be used to specify the maximum rows of the shared formula. The shared formula will be split into several shared formulae if the total rows of the shared formula are greater than it, as shown in the following screenshot.
Specify Maximum Rows of Shared Formula
The following sample code explains the usage of the GetMaxRowsOfSharedFormula() property. It sets the maximum rows of the shared formula to 5 and adds the shared formula in cell D1 for 100 rows and saves to output Excel file. If you extract the contents of the output Excel file and check the sheet1.xml, you will see the shared formula splits after every 5 rows, as highlighted in the above screenshot.
Sample Code
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Create a new workbook
Workbook wb;
// Set the max rows of shared formula to 5
wb.GetSettings().SetMaxRowsOfSharedFormula(5);
// Access first worksheet
Worksheet ws = wb.GetWorksheets().Get(0);
// Access cell D1
Cell cell = ws.GetCells().Get(u"D1");
// Set the shared formula in 100 rows
cell.SetSharedFormula(u"=Sum(A1:A2)", 100, 1);
// Save the output Excel file
wb.Save(u"outputSpecifyMaximumRowsOfSharedFormula.xlsx");
std::cout << "Shared formula set successfully!" << std::endl;
Aspose::Cells::Cleanup();
}