Академический Документы
Профессиональный Документы
Культура Документы
TNATIVEEXCEL
L I BR ARY
TNativeExcel Library
INTRODUCTION
INTRODUCTION
The Taboga TNativeExcel library is a native excel biff format interface for writing
Excel 2003 files (BIFF8).
Using this library you can create Excel 2003 compatible workbooks including both
data and formulas from your Clarion application.
I N S TA L L AT I O N
To install the
TNativeExcel.EXE.
template.
Please note that the Native Excel library contains the full source code, and a
template to simplify its use within your application. The following table explains in
which directories the library will be installed:
Templates
TNativeExcel.TPL
Source
Code
TWorkbook.INC
TWorkbook.CLW
TWorkbook.EQU
Clarion 6
%ROOT
%\3rdparty\Template
%ROOT%\Libsrc
Clarion 7
C:\Program
Files\Softvelocity\Cla
rion
7\Accessory\Template
\Win
C:\Program
Files\Softvelocity\Cla
rion
Documenta
tion
Examples
TXLS8Engine.INC
TXLS8Engine.CLW
TXLS8CELL.INC
TXLS8CELL.CLW
TXLS8F.INC
TXLS8F.CLW
TXLS8REC.EQU
TWBkUTIL.INC
TWBkUTIL.CLW
TPicture.INC
TPicture.CLW
TOleStorage.INC
TOleStorage.CLW
TNativeExcel.DOC
TNativeExcelTutorial
.DOC
TnativeExcelDemo.A
PP
7\Accessory\Libsrc\W
in
%ROOT%\3rdparty\docs\
Taboga\TNativeExcel
%ROOT
%\3rdparty\examples\
Taboga\TNativeExcel
Note: %ROOT% is the root directory where Clarion 6 was installed.
this would be C:\Clarion6.
Typically
The above table is just a reference for your convenience. The installation script
takes care of setting everything in the proper place, and it also registers the
template.
Q U I C K S TA RT
The best way to become familiarized with the library is to look at the included
TNativeExcelDemo.APP application. This application includes all the examples from
the tutorial, and provides the fastest route to start using the library.
The tutorial is contained in the TNativeExcelTutorial.DOC document, also
included.
INCLUDING THE LIBRARY IN YOUR APPLICATION
The easiest way to include the library in your application is to use the global
extension TEnableNativeExcel included in the TNativeExcel template set.
This global extension will properly include all the required library files into your
application, and set up all the required compiler directives to properly include the
library in single EXE and multi-dll applications.
USING THE LIBRARY
Here is a short example which illustrates the most simple use of the library:
program
map
end
INCLUDE('TWorkbook.INC')
wBook
TWorkbook
CODE
wBook.Init()
wBook.TakeLabel('A1','Some text...')
wBook.TakeLabel(1,2,'Another text...')
wBook.TakeNumber(A2,45.5563)
wBook.Save(simple.xls)
wBook.Kill
S O M E P R E L I M I N A RY C O N C E P T S
WORKBOOK IS BUILT IN MEMORY BEFORE WRITING TO DISK
A very important thing that should be understood before using the library is that
when you declare an object of the TWorkbook class, and start writing data and
formulas to the worksheet, and formatting it with different fonts, alignments, etc,
everything is being held in memory, and it is only until you save to disk that the
whole workbook is committed to disk.
There are some very important reasons and implications on why this is the case.
One very important reason/implication is that because of this, when you apply
formatting to a given cell, column or row, the formatting can and will override any
previous formatting on that same section.
This is similar to when you are working with Excel. If you specify a font to a
given cell for example -, and then you specify a different font for the column
on which the cell lies, the cell is reformatted to the column font (the last font
specified). In other words, the last format call remains.
When you are working with Excel this is rarely a source of problems because you
are visually overseeing the format changes; however, this is an area where caution
must be used on the Native Excel library because you will only see the final workbook
result.ing.
wBook.SetFont(Arial,10)
wBook.TakeLabel(A1,Example text)
wBook.ResetStyle()
...
...
...
wBook.SetFont(Arial,24)
wBook.TakeColumn(1,1)
wBook.ResetStyle()
24
FIRST column.
CHANGED to Arial 24...!!
to default values...
The above code shows the Last Format Applies principle we have been describing.
When the label in cell A1 was written, it was formatted using the font Arial 10.
However, further down, the whole first column (which contains the cell A1) was
formatted to use the font Arial 24.
At this moment, the cell A1 changed its
format to use Arial 24.
In our experience, this is the most common cause of getting unexpected results
when using the library. And extra caution must be taken when applying formatting to
rows or columns.
E N T E R I N G C E L L D ATA
Data is entered in the worksheet using one of the following library functions:
TakeLabel, TakeNumber, TakeInteger, TakeDate, and TakeTime. Depending on the
specific type of data you want to assign to a worksheet cell (i.e. label, number,
integer, date, or time) you choose the appropiate function.
TAKELABEL
In Excel, text strings are called labels; thus, when you want to write a text string
to a cell you use the TakeLabel function.
For example, the following function call writes the label Some Text string into
the cell A1 of the worksheet.
myWBookObj.TakeLabel(A1,Some Text string...)
These final two functions, as their name imply, are for writing dates and times
respectively.
REFERENCES AND ROW/COLUMN PAIRS
Each of the data entry functions have two versions: one that take references, and
one that takes Row/Column indexes.
Cell references are strings in the format column index as a letter, and row index
as number. Thus, the cell reference A1 refers to the first (A) column, and the first
(1) row. Below are some other examples of cell references.
Cell Reference
F45
AB32
Column
F = 6th column
AB = 26*1 + 2 = 28th column
Row
45th row
32nd row
MN4
4th row
Row/column indexes is where we actually specify the row and column pair. For
example 1,1 represent the first row, and the first column, 32,44 represent the 32nd
row and 44th column.
It is important to note that cell references are given in column/row order, whereas
row/column indexes are given in row/column order.
TWO VERSIONS OF EACH DATA ENTRY FUNCTION
Each one of the data entry functions (i.e. TakeLabel, TakeNumber, TakeInteger,
TakeDate, and Taketime) has two versions: one that uses cell references, and one
that uses row/column pairs.
Thus, for example, the following two function calls are equivalent:
myWBookObj.TakeNumber(B1,45.7)
myWBookObj.TakeNumber(1,2,45.7)
F O R M ATT I N G
After data entry the most used functionality is cell, column and row formatting.
Hence, a very powerful feature of the Taboga Native Excel library is the flexibility in
formatting cells, rows and columns.
We must caution also, that formatting it is the most common cause of getting
unexpected results as we saw in the Preliminary Concepts section above .
APPLYING FORMATTING
!Set the current font to Arial, size 10, blue in color, and BOLD+UNDERLINE...
wBook.SetFont('Arial', 10, COLOR:BLUE , FONT:BOLD+FONT:UNDERLINE)
!..Once the font is set, any data written will take on that font:
wBook.TakeLabel('A1','This text uses: Arial 10, Bold&Underline + Blue')
wBook.TakeLabel('A2','This ALSO uses the same font')
wBook.ResetStyle()
!Reset all formats to the default values...
wBook.TakeLabel('A3','This label however uses the NORMAL DEFAULT FONT')
Formatting applied to a column or row will affect all cells contained in that row
or column. The library will in fact go through all the cells in the given row or column
and apply the new formatting.
This again works in a very similar way to MS Excel.
In Excel, if you aply any
formatting to a column or row, that formatting is also applied to all the cells in the
given row or column.
FONT FORMATTING
FontColor: If you choose to specify a font color, you can use any of the clarion
COLOR equates, or specify a particular color using standard Clarion color values.
Excel BIFF8 however, has a limit of 54 different colors on a workbook. The library
will thus adjust the palette of colors saved to the workbook according to the colors
used.
FontStyle: Again, the library will accept using clarion equates. Thus you can set
the style to FONT:BOLD+FONT:UNDERLINE, and the library will understand these
equates.
FontUnderline: If you specify the style as underline, you can then specify the
particular style of underline. To do this you can use one of the following equates:
xlsUnderline::Single
xlsUnderline::Double
xlsUnderline::SingleAccounting
xlsUnderline::DoubleAccounting
Font is superscript
To
xlsFont:::Subscript
Font is subscript
FORMATTING SCOPE
The current formatting or style will remain in effect until it is reset to the default
values. For example, if you set a particular font, it becomes the current font. This
current font will be applied to all cells, columns and rows which are worked on while
it is selected:
wBook.SetFont('Arial', 10, COLOR:BLUE , FONT:BOLD+FONT:UNDERLINE)
!..Once the font is set, any data written will take on that font:
wBook.TakeLabel('A1','This text uses: Arial 10, Bold&Underline + Blue')
...
...
... At some other point in the code, we take another label.
The currently selected
... font is still the same.
...
wBook.TakeLabel('A2','This ALSO uses the same font')
...
...
wBook.TakeColumn(1,4) !The same font (Arial 10) is applied to columns 1 to 4...
...
...
wBook.ResetStyle()
!NOW all formatting is reset to default
Thus, when you are finished with a particular font, you should make sure to call
the method ResetFormat, to set all formatting to default.
An
alternative
to
the
TWorkbook.ResetFormat()
method,
is
TWorkbook.Style.Reset() method. Both methods exactly the same function.
the
Horizontal alignment is set using the SetAlignment method, with the desired
horizontal alignment style as the passed parameter:
Horizontal Alignment Style
constant
Description
xls::ALIGN_GENERAL
xls::ALIGN_LEFT
xls::ALIGN_CENTER
xls::ALIGN_RIGHT
xls::ALIGN_FILLCELL
xls::ALIGN_JUSTIFIED
xls::ALIGN_CENTERACCROSSSELECTION
xls::ALIGN_DISTRIBUTED
Vertical alignment is set using the SetVerticalAlignment method, with the desired
verticla alignment style as the parameter:
Vertical Alignment Style
constant
Description
xls::VERT_ALIGN_TOP
xls::VERT_ALIGN_CENTERED
xls::VERT_ALIGN_BOTTOM
xls::VERT_ALIGN_JUSTIFIED
xls::VERT_ALIGN_DISTRIBUTED
In accordance to all the formatting actions in the Native Excel library, you first set
the alignment, and then apply it to the cells, columns or rows:
wBook.SetAlignment(xls::ALIGN_RIGHT)
As you probably know, you can specify a cell picture in Excel (though in Excel
these are called Cell Formats).
In the Native Excel library you can specify the cell format picture by calling the
SetFormatPicture method. The parameter is then the Cell format, or picture desired.
The interesting thing is that the library recognizes Clarion style pictures, so you
can specify the format picture in either Clarions format (e.g. @N-12.4, @D4, etc),
or Excels own format picture syntax.
The library will correctly interpret either
syntax.
STYLE STRUCTURE
!..Once the font is set, any data written will take on that font:
wBook.TakeLabel('A1','This text uses: Arial 10, Bold&Underline + Blue')
wBook.TakeLabel('A2','This ALSO uses the same font')
wBook.ResetStyle()
wBook.TakeLabel('A3','This label however uses the NORMAL DEFAULT FONT')
This also works for alignment, and all the properties defined in the Style structure.
The code beow is identical to the alignment example given above.
wBook.Style.HorizontalAlignment = xls::ALIGN_RIGHT
It is very important to understand that any formatting (or style) which is applied
by altering the Style structure, remains in effect until you specifically reset it calling
either TWorkbook.ResetStyle(), or TWorkbook.Style.Reset().
Again, both of these method calls do exactly the same.
TWorkbook.ResetStyle() just call the Style.Reset() method internally.
In
fact,