Hi,
A first version of the formula API is now in the cvs for the
"xmlfilter02" CWS.
Because much of ScToken's functionality is needed only within the
context of the RPN code used for calculation, and this new API only
deals with the non-RPN code, it can be simpler than in the previous
mail. Instead of having different token structs and a sequence<any>, we
now use sequence<FormulaToken>, where FormulaToken is a struct
consisting of just an integer for the OpCode and an any for extra data.
The extra data can have the following types:
- double: Only with ocPush, for numeric constants.
- string:
-- With ocPush for string constants.
-- With ocExternal or ocMacro for function names.
-- With ocBad for text that couln't be parsed.
- long:
-- With ocName or ocDBArea for named ranges or database ranges.
-- With ocSpaces for the count of spaces.
- struct SingleReference:
-- With ocPush for a single cell reference.
-- With ocColRowName for an automatic cell reference.
- struct ComplexReference: Only with ocPush for a range reference.
When array constants are finished, that will be another type
(sequence<sequence<any>>, probably) with ocPush.
The following is available now:
- The cell supports the interface XFormulaTokens, with getTokenArray and
setTokenArray.
- The new parser object
(createInstance("com.sun.star.sheet.FormulaParser") from the document)
supports XFormulaParser (parseFormula, printFormula) and XPropertySet
for options. Currently the only option property is "ReferencePosition",
a CellAddress struct with the position used for parsing. This will have
to be extended, to select things like the reference style. The
implementation is in sc/source/ui/unoobj/tokenuno.cxx.
This little Basic macro shows the steps to parse and apply a formula:
Sub Main
dim aCellPos as new com.sun.star.table.CellAddress
aCellPos.Row = 3
oDoc = ThisComponent
oParser = oDoc.createInstance("com.sun.star.sheet.FormulaParser")
oParser.ReferencePosition = aCellPos
' TODO: set parser options (separator, reference style etc)
aCode = oParser.parseFormula("SUM(A1:A3)")
' TODO: manipulate the token sequence if needed
oSheet = oDoc.Sheets(aCellPos.Sheet)
oCell = oSheet.getCellByPosition(aCellPos.Column, aCellPos.Row)
oCell.TokenArray = aCode
End Sub
I'll be on vacation next week, but I hope this helps to get started with
the formula import.
Niklas
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]