pagecreator:tutorials:excel:exporting_multiple_assortments
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| pagecreator:tutorials:excel:exporting_multiple_assortments [2012/09/17 21:49] – dave | pagecreator:tutorials:excel:exporting_multiple_assortments [2025/05/22 21:53] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 9: | Line 9: | ||
| The " | The " | ||
| - | < | + | < |
| - | dim slUPCs | + | // Declare our global variables that will need to hold their values in |
| + | // other routines | ||
| + | dim slUPCs | ||
| + | dim EndingRow // the EndingRow in Excel for each product | ||
| + | |||
| + | // A Function to retrieve a valid up or a blank | ||
| + | // index is the index into the extra rows of info | ||
| + | FUNCTION GetListValue(list, | ||
| + | if (list.count > index) then | ||
| + | | ||
| + | else | ||
| + | | ||
| + | end if | ||
| + | END FUNCTION | ||
| + | |||
| + | // function to output a formula | ||
| + | // ws - an excel Worksheet variable a la excel.ActiveSheet | ||
| + | // col - the column name - e.g. " | ||
| + | // row - the excel row number - e.g. 25 | ||
| + | // formula - a template for the formula with python like string format vars. | ||
| + | // e.g. "=B{0} + E{1} * F{2}" | ||
| + | // data - an array of variables to complete the formula | ||
| + | // e.g. [row, row - 4, 43] would replace {0} with the value of the row variable | ||
| + | // {1} with the value of row-4 | ||
| + | // {2} with 43 | ||
| + | SUB exportFormula(ws, | ||
| + | // enumerate through the data array and substitute the values | ||
| + | for i = low(data) to high(data) | ||
| + | formula = ReplaceAll(formula, | ||
| + | next | ||
| + | // output to Excel | ||
| + | addr = col + row | ||
| + | Rng = ws.Range(addr) | ||
| + | Rng.formula = formula | ||
| + | END SUB | ||
| </ | </ | ||
| === OnBeforeData === | === OnBeforeData === | ||
| + | <code sqbasic> | ||
| + | // We need to figure out if we have enough rows left on this worksheet to | ||
| + | // fill in all the assortment UPCs | ||
| + | |||
| + | // max_rows variable is used to find how many extra rows we have. | ||
| + | // Its not essential when only using one list, but useful if we | ||
| + | // have multiple lists. | ||
| + | max_rows = 0 | ||
| + | |||
| + | // Create our TStringList to hold the valid UPCs | ||
| + | slUPCs = TStringList.Create | ||
| + | // enumerate all of the " | ||
| + | for i = 1 to 40 | ||
| + | szUPC = trim(SQForm.Link(" | ||
| + | if (szUPC <> "" | ||
| + | | ||
| + | | ||
| + | end if | ||
| + | next | ||
| + | |||
| + | // EndingRow is the row offset of the last row for this group | ||
| + | // Since the first " | ||
| + | EndingRow = max_rows + Row | ||
| + | </ | ||
| === OnAfterData === | === OnAfterData === | ||
| + | <code sqbasic> | ||
| + | // FIRST_ROW is the first valid row in the Excel. | ||
| + | FIRST_ROW = 22 | ||
| + | // FORMULA_AG is a formula template - put here to make it easier to find if changes are necessary | ||
| + | FORMULA_AG = " | ||
| + | ws = excel.ActiveSheet | ||
| + | |||
| + | // main_row is the current row | ||
| + | main_row = FIRST_ROW + Row - 1 | ||
| + | |||
| + | // We want to export the correct formula in cell AG for the current row | ||
| + | exportFormula(ws, | ||
| + | |||
| + | // xlRow is the actual row in Excel we will output into | ||
| + | for xlRow = main_row + 1 to FIRST_ROW + EndingRow | ||
| + | // idx is the index into the current lists | ||
| + | idx = xlRow - main_row - 1 | ||
| + | // output to Excel - GetUPC is a Global function to make it easier to get the correct UPC value | ||
| + | ws.Range(" | ||
| + | | ||
| + | // We want to export the correct formula in cell AG for each UPC row | ||
| + | exportFormula(ws, | ||
| + | next | ||
| + | |||
| + | // Remember to free any lists you create in OnBeforeData | ||
| + | slUPCs.free | ||
| + | |||
| + | // Set the current row to the EndingRow. | ||
| + | Row = EndingRow | ||
| + | </ | ||
pagecreator/tutorials/excel/exporting_multiple_assortments.1347918565.txt.gz · Last modified: (external edit)
