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.

12 <strong>Excel</strong> <strong>Add</strong>-<strong>in</strong> <strong>Development</strong> <strong>in</strong> C/<strong>C++</strong>Table 2.3 (cont<strong>in</strong>ued)Literal arrays are enclosed <strong>in</strong> curly braces { and }, row-by-row (sometimesreferred to as row-major). Row elements are delimited by commas, androws themselves are delimited by semi-colons. For example, {1, “A”;TRUE, NA()} represents the 2 × 2matrix[1 ATRUE #N/A]2.5 EXCEL INPUT PARSERWhen a user types <strong>in</strong>put to a cell <strong>in</strong> <strong>Excel</strong> and commits the data (by press<strong>in</strong>g enter, tabor select<strong>in</strong>g another cell), <strong>Excel</strong> performs several operations <strong>in</strong> the order outl<strong>in</strong>ed below.In essence, it is attempt<strong>in</strong>g to guess what k<strong>in</strong>d of <strong>in</strong>put the user was provid<strong>in</strong>g, and thentries to <strong>in</strong>terpret accord<strong>in</strong>gly. Understand<strong>in</strong>g the order <strong>in</strong> which <strong>Excel</strong> does these th<strong>in</strong>gsmay help you when creat<strong>in</strong>g your own functions or commands.1. If the <strong>in</strong>put starts with a str<strong>in</strong>g prefix (a s<strong>in</strong>gle quote mark) <strong>Excel</strong> places all of the<strong>in</strong>put characters <strong>in</strong> the cell as typed, with no modification. (The str<strong>in</strong>g prefix is notdisplayed.) If the <strong>in</strong>put beg<strong>in</strong>s with =, + or -, it assumes a formula and uses its formulaparser to check the syntax. An error dialog appears if the formula does not make sense.Otherwise <strong>Excel</strong> will try and figure out if the user typed someth<strong>in</strong>g that looked like adate, a time, a currency amount, a percentage, or just a number. If none of these, itreverts to consider<strong>in</strong>g the <strong>in</strong>put as a str<strong>in</strong>g and places it <strong>in</strong> the cell unchanged.Note: This tendency to recognise dates and times before text can be quite annoy<strong>in</strong>g,especially if you <strong>in</strong>tended to <strong>in</strong>put a str<strong>in</strong>g such as the ratio “2:1”. <strong>Excel</strong> willchange the format of the cell to a time format and convert the <strong>in</strong>put to the numericvalue 0.084027777 (the fraction of the day that has passed at 02:10 a.m.). Hav<strong>in</strong>g toremember to prefix such <strong>in</strong>puts with a s<strong>in</strong>gle quote mark can be frustrat<strong>in</strong>g.2. Where the <strong>in</strong>put is seen as a possible formula, <strong>Excel</strong> attempts to identify, convert andevaluate function arguments and nested functions start<strong>in</strong>g with the <strong>in</strong>nermost, i.e., mostnested. Cell references and ranges are converted to values, which are then convertedto the right data types if necessary and so on. Where a token that is not recognised asa function or def<strong>in</strong>ed name is encountered, the conversion and evaluation fails with a#NAME? error. Otherwise def<strong>in</strong>ed names are converted just as the cells or expressionsthey represent would be.3. Once the <strong>in</strong>put has been accepted, <strong>Excel</strong> attempts to recalculate those th<strong>in</strong>gs thatdepend on the new <strong>in</strong>put. If the <strong>in</strong>put was a number and cell previously conta<strong>in</strong>ed anumber, <strong>Excel</strong> will only recalculate if the value has changed. If a new formula has beenentered with references to new <strong>in</strong>puts, <strong>Excel</strong> verifies that no circular references havebeen created by this new formula. If a cell does depend on <strong>in</strong>puts which themselvesdepend on the value of this cell, <strong>Excel</strong> compla<strong>in</strong>s.4. Depend<strong>in</strong>g on the optional <strong>Excel</strong> or cell format sett<strong>in</strong>gs, <strong>Excel</strong> may resize the columnwidth or row height.2.6 DATA TYPE CONVERSION<strong>Excel</strong> always attempts to convert data from one type to another where required. Thissection expla<strong>in</strong>s when <strong>Excel</strong> tries to do this, and when it is and is not successful.

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

Saved successfully!

Ooh no, something went wrong!