-
Notifications
You must be signed in to change notification settings - Fork 4
/
tutorial1.bas
50 lines (38 loc) · 1.55 KB
/
tutorial1.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/'
* A simple program to write some data to an Excel file using the
* libxlsxwriter library.
*
* This program is shown, with explanations, in Tutorial 1 of the
* libxlsxwriter documentation.
*
* Copyright 2014-2017, John McNamara, [email protected]
*
* translated by Lee June by using https://github.com/retsyo/libxlsxwriter_freebasic
'/
' ~ #include "xlsxwriter.bi"
#include "auto_xlsxwriter.bi"
' ~ /* Some data we want to write to the worksheet. */
type expense
item As String * 32
cost As Integer
end Type
Dim Shared As expense expenses(0 to 3) => { ("Rent", 1000), ("Gas", 100), ("Food", 300), ("Gym", 50) }
function main() As Integer
'Rem Create a workbook and add a worksheet. */
dim as lxw_workbook ptr workbook => workbook_new("tutorial01.xlsx")
dim as lxw_worksheet ptr worksheet => workbook_add_worksheet(workbook, NULL)
'Rem Start from the first cell. Rows and columns are zero indexed. */
dim as integer row = 0
dim as integer col = 0
'Rem Iterate over the data and write it out element by element. */
for row = 0 to 3
worksheet_write_string(worksheet, row, col, expenses(row).item, NULL)
worksheet_write_number(worksheet, row, col + 1, expenses(row).cost, NULL)
next
'Rem Write a total using a formula. */
worksheet_write_string (worksheet, row, col, "Total", NULL)
worksheet_write_formula(worksheet, row, col + 1, "=SUM(B1:B4)", NULL)
'Rem Save the workbook and free any allocated memory. */
return workbook_close(workbook)
end function
main()