12.07.2015 Views

Excel Add-in Development in C/C++: Applications in ... - F9

Excel Add-in Development in C/C++: Applications in ... - F9

Excel Add-in Development in C/C++: Applications in ... - F9

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

22 <strong>Excel</strong> <strong>Add</strong>-<strong>in</strong> <strong>Development</strong> <strong>in</strong> C/<strong>C++</strong>The all-or-noth<strong>in</strong>g edit feature of array formulae makes them useful for help<strong>in</strong>g toprotect calculations from be<strong>in</strong>g accidentally overwritten. The worksheet protection featureof <strong>Excel</strong> is stronger. It allows precise control over what can be modified with passwordprotection. However, it also disables other features that you might want to be accessible,such as the collapse and expansion of grouped rows and columns. Array formulae providea half-way house alternative.Functions and operators that usually take s<strong>in</strong>gle cell references can also be passedrange arguments <strong>in</strong> array formulae. How <strong>Excel</strong> deals with these is covered above <strong>in</strong>section 2.6.8.2.9.3 Required, optional and miss<strong>in</strong>g arguments and variable argument listsSome functions take a fixed number of arguments, all of which need to be suppliedotherwise an error will be returned, for example DATE(). Some take required and optionalarguments, for example, VLOOKUP(). Some take a variable number such as SUM(). Afewfunctions have more than one form of argument-list, such as INDEX(), equivalent to theconcept of overload<strong>in</strong>g <strong>in</strong> <strong>C++</strong>.With C/<strong>C++</strong> DLL functions, <strong>Excel</strong> handles variable length argument lists by alwayspass<strong>in</strong>g an argument, regardless of whether the user provided one. A special miss<strong>in</strong>g datatype is passed. If the argument can take different types, say, a str<strong>in</strong>g or a number, thefunction can be declared <strong>in</strong> such a way that <strong>Excel</strong> will pass a general data type. It is thenup to the function’s code whether to execute or fail with the arguments as provided. Thisand related subjects are covered <strong>in</strong> detail <strong>in</strong> Chapter 6 Pass<strong>in</strong>g Data between <strong>Excel</strong> andthe DLL on page 105.2.10.1 Data Tables2.10 COMPLEX FUNCTIONS AND COMMANDSData Tables provide a very useful way of creat<strong>in</strong>g dynamic tables without hav<strong>in</strong>g toreplicate the calculations for each cell <strong>in</strong> the table. Once the calculation has been setup for a s<strong>in</strong>gle result cell (not <strong>in</strong> the table), a table of results for a range of <strong>in</strong>puts isproduced. <strong>Excel</strong> plugs your <strong>in</strong>puts <strong>in</strong> one-by-one and then places the result<strong>in</strong>g value <strong>in</strong>the Data Table. Data Tables can be based on one <strong>in</strong>put to produce a s<strong>in</strong>gle row or columnof results, or on two <strong>in</strong>puts to produce a 2-dimensional table.Tables are set up with the Data/Table...command, <strong>in</strong>vok<strong>in</strong>g a simple wizard that promptsyou to specify the <strong>in</strong>put row and/or column for the table. This book doesn’t go <strong>in</strong>to anydetail (refer to <strong>Excel</strong>’s help to f<strong>in</strong>d out more), but it is worth consider<strong>in</strong>g what they are.If you look at the formula that <strong>Excel</strong> puts <strong>in</strong> part of the table where the results are placed,you will see that there is an array formula {=TABLE(...)}. On the face of it, therefore, itlooks like a Data Table is just another function entered as an array formula. It gives theappearance of be<strong>in</strong>g recalculated like a function, except that <strong>Excel</strong> enables you to turnthe automatic recalculation of tables off us<strong>in</strong>g Tools/Options.../Calculation.However: you can’t edit and re-enter the cells under the TABLE() function, even if youhave changed noth<strong>in</strong>g; the Paste Function dialog does not recognise TABLE() as a validfunction; you can’t move the cells that are immediately above or to the left of the cells

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!