Auto-filling a range with data (two examples, one with formulas, another with numbers)Auto-filling a range in
xlsgen is the programmatic way by which it is possible to drag a selection in Excel vertically or horizontally and see the extension filled with data relevant to the data in the selection.
Formulas are replicated (the cell references are updated accordingly). Strings are replicated as is. Numbers are replicated by taking into account the difference between numbers in the data selection. The formatting is replicated.
The selection is defined by its depth. The depth means the height of the selection in case the fill is vertical. And the depth means the width in case the fill is horizontal. It is therefore possible to choose to auto-fill vertically or horizontally.
In the examples above, auto-fill is used for replicating formulas vertically, and numbers vertically. Since there is only one formula in the selection, the depth is set to 1. In the other example, numbers are replicated. The selection has three numbers, which implies the depth is set to 3. If the depth was set to 1 or 2, the result would be entirely different. Indeed the selection depth is used to infer the differences between numbers. The algorithm is always linear.
| C++ code |
xlsgen::IXlsWorkbookPtr wbk = engine->Open( L"data.xls", L"output.xls" );
xlsgen::IXlsWorksheetPtr wksht = wbk->WorksheetByIndex[1];
// auto-fill vertically our formula in the selection (see example above) wksht->NewRange(L"C3:C11")->AutoFill(1);
wbk->Close();
|