Lvyue schrieb:
> Hi, Daniel 
> I'm working on the new function EUROCONVERT(), 
> and now I come to the Excel import/export part.
> because Excel has this function already,
> so I want to add it to the corresponding XclFunctionInfo table in 
> xlformula.cxx.
> but I don't know much about that, can you tell me more details, if you are 
> not very busy. :)

I think just adding an entry there will not work, because EUROCONVERT is
implemented in a separate add-in in Excel, so there will be a bit more
work needed to import/export this function.

Some theory first:

If you use the EUROCONVERT function, Excel creates a new reference to an
external document (EXTERNALBOOK record) named "\001\008EUROTOOL.XLA"
(\001 is the ASCII character 1, \008 is the ASCII character 8). The
value \001 denotes an encoded URL, the value \008 is a placeholder for
the default Excel add-in directory (e.g.
C:\Programs\MSOffice\OFFICE11\Macro\), see chapter 2.5.9 in
http://sc.openoffice.org/excelfileformat.pdf for details. The function
name "EUROCONVERT" follows as external name (EXTERNALNAME record). In
the formula, the function is represented by a tNameX token pointing to
the external name mentioned above. This token is the first parameter in
an EXTERN.CALL function, followed by the actual parameters of the function.

Example:

REC  size=0x00000083=131  id=0x01AE  name=EXTERNALBOOK
...

REC  size=0x00000083=131  id=0x01AE  name=EXTERNALBOOK
...

REC  size=0x00000083=131  id=0x01AE  name=EXTERNALBOOK
  sheet-count=16
  workbook-url=(len=14),'\x01\x08EUROTOOL.XLA'
  sheet-name[0]=(len=4),'1033'
  sheet-name[1]=(len=4),'1030'
  sheet-name[2]=(len=4),'1032'
  sheet-name[3]=(len=4),'1035'
  sheet-name[4]=(len=4),'1036'
  sheet-name[5]=(len=4),'1040'
  sheet-name[6]=(len=4),'1043'
  sheet-name[7]=(len=4),'1053'
  sheet-name[8]=(len=4),'2070'
  sheet-name[9]=(len=4),'3082'
  sheet-name[10]=(len=4),'1031'
  sheet-name[11]=(len=4),'2052'
  sheet-name[12]=(len=4),'1028'
  sheet-name[13]=(len=4),'1041'
  sheet-name[14]=(len=4),'1042'
  sheet-name[15]=(len=4),'1069'

REC  size=0x00000015=21  id=0x0023  name=EXTERNALNAME
  flags=0x0000=(clipboard-format=0)
  externsheet-idx=0
  unused=00,00
  name=(len=11),'euroconvert'
  remaining-data  size=2
    00 00                                             ..

REC  size=0x00000026=38  id=0x0017  name=EXTERNSHEET
  ref-count=6
  ref[0]    extbook-idx=0    first-sheet=0           last-sheet=0
  ref[1]    extbook-idx=1    first-sheet=-2=special  last-sheet=-2=special
  ref[2]    extbook-idx=0    first-sheet=5           last-sheet=5
  ref[3]    extbook-idx=2    first-sheet=-2=special  last-sheet=-2=special
  ref[4]    extbook-idx=0    first-sheet=2           last-sheet=2
  ref[5]    extbook-idx=0    first-sheet=2           last-sheet=3

The third EXTERNALBOOK record (index 2) contains the external name with
the function name. The 4th entry "ref[3]" in the list of the EXTERNSHEET
record points to the EXTERNALBOOK that contains the "EUROTOOL.XLA" file
name. This index is used in formulas.

A formula cell may look like this:

REC  size=0x00000030=48  id=0x0006  name=FORMULA
  addr=P104
  xf-idx=15
  result=00,00,00,00,00,00,F0,3F  value=1
  flags=0x0020=(?unknown=0x20)
  unused=67,00,11,FF
  formula  formula-size=26
    0x0000  0x39=tNameXR      ref-idx=3  name-idx=1  unused=00,00
    0x0007  0x1E=tInt         value=1
    0x000A  0x17=tStr         value=(len=3),'EUR'
    0x0010  0x17=tStr         value=(len=3),'EUR'
    0x0016  0x42=tFuncVarV    param-count=4
func-id=0x00FF=(func-id=255)='EXTERN.CALL'
    formula=EXTERN.CALL(REF[3]!NAME[1],1,"EUR","EUR")
    classes=V(R,B,B,B)

The first parameter of the function EXTERN.CALL is the tNameXR token
pointing to REF[3] (the entry in EXTERNSHEET pointing to EUROTOOL.XLA
add-in), and name with index 1 (the EXTERNALNAME record with the
function name "EUROCONVERT", these indexes are one-based). So, Excel
loads the formula
  =EXTERN.CALL(REF[3]!NAME[1],1,"EUR","EUR")
resolves REF[3]!NAME[1] to the function name "EUROCONVERT" and creates
the formula
  =EUROCONVERT(1,"EUR","EUR")

Ok, this is the theory. Most of the stuff described above is already
implemented (import/export of Analysis add-in functions works similar).

This is an overview of what to do next (all mentioned files are located
in sc/source/filter/inc or sc/source/filter/excel):

1) add a new book type in xllink.hxx, enum XclSupbookType, e.g.
"EXC_SBTYPE_EUROTOOL" (note that the old term "SUPBOOK" is used for
"EXTERNALBOOK" here).

2) in xilink.cxx, XclImpSupbook::XclImpSupbook(), the call to
XclImpUrlHelper::DecodeUrl() tries to decode the file name in aEncUrl,
and returns the name "\008EUROTOOL.XLA" in maXclUrl. The leading
character \001 is already removed here. Here, test on this name, and set
the new type EXC_SBTYPE_EUROTOOL in meType if found (similar to
EXC_SBTYPE_SPECIAL below).

3) the external name with the function name will be loaded in
xilink.cxx, XclImpExtName::XclImpExtName(). Depending on how your new
function is implemented, true may have to be passed here as second
parameter (called from XclImpSupbook::ReadExternname()). If true is
passed, the constructor tries to resolve the function name to the
programmatical name used by Calc, e.g.
"com.sun.star.sheet.addin.Analysis.getEomonth" for the EOMONTH analysis
add-in function.

That should be enough for import. The external name is registered to be
an add-in function. This information will be used by the formula
importer to create a call to our add-in.

If all *that* works, we may talk about the export. :-)


Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to