The underlying library is object-oriented, consisting of four classes:
Class |
Description |
---|---|
Book |
Each instance represents a workbook; methods including creating a workbook, loading one from a file, saving it to file, adding sheets, defining fonts and formats, etc. |
Sheet |
Each instance represents a worksheet; methods and properties relating to rows, columns, cells. |
Font |
Each instance defines an individual font; a font instance may be shared by multiple instances of the Format class. |
Format |
Each instance defines a combination of all the non-data attributes associated with cells—color, alignment, borders, font, etc. |
ASB is not object-oriented per se, but generally follows the class orientation of the underlying library. You create instances of the various classes, which are identified by handles, which are then passed to the method functions to identify the instance of the class being operated on. Module-level (libxl.bsi) private data is used to keep track internally of the handles and various associated properties.
Creating a spreadsheet from scratch typically involves the following:
• | ++INCLUDE libxl:libxl.bsi |
• | Map variables for the various Book, Sheet, Format and Font objects you’ll be needing (using the special types BookHandle, SheetHandle, FormatHandle and FontHandle), e.g. |
Map1 handles
Map2 book1,BookHandle,
Map2 sheet1,SheetHandle
Map2 fmt’header,FormatHandle
Map2 fmt’total,FormatHandle
Map2 font’bold,FontHandle
• | Load the library, e.g.: |
Call Fn’LibXL’Load(dlflags)
• | Create an instance of the Book class, e.g.: |
book1 = Fn’LibXL’CreateBook()
• | Create one or more Sheet instances, e.g.: |
sheet1 = Fn’LibXL’AddSheet(“Sheet1”, hbook=book1)
• | Create zero or more Font instances, assigning attributes such as facename, size, color, e.g. |
font’bold = Fn’LibXL’AddFont’SetAttributes(size=16, bold=1)
• | Create zero or more Format instances, assigning attributes such as borders, alignment, font, e.g. |
fmt’header = Fn’LibXL’AddFormat’SetAttributes(hfont=font’bold, alignh=ALIGNH_CENTER,…)
• | Use functions in the Sheet class to set column/row dimensions, add pictures, and write cells. (Formats may be associated with the cells when writing the data or by separate operations.) |
Call Fn’LibXL’SheetSetCol(hsheet=sheet1, colfirst=1, width=20)
Call Fn’LibXL’SheetWrite(row=1,col=2,”Hello World”, hformat=fmt’header)
• | Save the Book instance as a file, e.g. |
Call Fn’LibXL’SaveBook(“hello.xls”, hbook=book1)
• | Release the book (frees resources) |
call LibXL'ReleaseBook()
• | Unload the library |
call Fn'LibXL'Unload()