-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexcel_writer.txt
138 lines (106 loc) · 4.33 KB
/
excel_writer.txt
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
Intro to Excel Writer
=====================
The Excel Writer consists of an Ada package, Excel_Out,
which produces Excel files - as physical files, or as
other types of data streams.
The creation of an Excel file is as simple as this
small procedure:
with Excel_Out;
procedure Small_demo is
xl : Excel_Out.Excel_Out_File;
begin
xl.Create ("Small.xls");
xl.Put_Line ("Hello world !");
xl.Close;
end;
Contents
========
Excel Writer
============
- excel_out.ads : package specification
- excel_out.adb : package body
- excel_out-* : private packages used by excel_out.adb
- excel_out_demo.adb : demo procedure
- excel_out.gpr : project file for the AdaCore GNAT compiler
- excel_out.prj : project file for the PTC ObjectAda64 compiler
- excel_writer.txt : this file
Some goodies - around Excel, CSV's, spreadsheets in general
===========================================================
- extras/biff_dump.adb : procedure for viewing the Excel BIFF format
- extras/csv.ads : CSV parser (specification)
- extras/csv.adb : (body)
- extras/csv2html.adb : a CSV to HTML translation tool
- extras/csv2tex.adb : a CSV to LaTeX translation tool
- extras/spreadsheet_references.ads : converts (i,j) to or from the "A1" or "R1C1" format (specification)
- extras/spreadsheet_references.adb : (body)
- extras/spreadsheet_references_demo.adb : demo procedure for Spreadsheet_references
Testing various features of Excel Writer
========================================
- test/ew_test.adb
License / Warning / Legal stuff
===============================
There is NO WARRANTY in the Excel Writer software.
Excel Writer is licensed under the MIT License.
You find the full license and copyright notice in excel_out.ads.
Portability
===========
Excel Writer can be compiled for any target machine, and with any Ada 95 or later compiler.
The compiler's Interfaces package must provide an Unsigned_64 type (this is for the portable
IEEE double-precision export).
How to build Excel Writer and its demo
======================================
Here is how to build with GNAT/GCC:
- run build.cmd (Windows)
or
- type "gnatmake -P excel_out_gnat" in the command line
or
- type "gnatmake excel_out_demo" in the command line
or
- open the excel_out_gnat.gpr file with the GNAT Studio,
press F4
or
- open excel_out_demo.adb with AdaGIDE, press F3
or
- your way...
Here is how to build with ObjectAda:
- open the excel_out_objectada.prj file with the ObjectAda IDE,
press F7
As a result there is a excel_out_demo[.exe] executable.
Type hierarchy
==============
In Excel_Out:
|- Excel_Out_Stream : root type, abstract
\
|- Excel_Out_File : type for writing to files (defined in Excel_Out)
|- Excel_Out_String : type for writing to strings (defined in Excel_Out)
|
In your own extension, if needed:
|
|- (your own stream!)
How to create properly Excel files or streams
=============================================
Most, if not all possibilities are in the Big_demo procedure
nested in Excel_Out_Demo. So it is a good place to pick code...
To summarize, you need to define the spreadsheet contents in
a certain order:
1. Create
2. Optional settings, before any data output:
| Define page layout (see Header, Footer, Page_Setup, ...)
| Write_default_column_width
| Write_column_width for specific columns
| Write_default_row_height
| Write_row_height for specific rows
| Define_font, then Define_format
3. | Write(xl, row, column, data): row by row, column by column
| Put(xl, data) : same, but column is auto-incremented
| New_Line(xl),... : other "Text_IO"-like
| Use_format, influences the format of data written next
4. Close
5. (Excel_Out_String only) function Contents returns the full .xls
As you observed, you can write cell contents by setting for each cell
the target row and column, with Write, or by using Put,
Put_Line, New_Line, just like Ada.Text_IO. Both ways can be mixed
ad libitum.
Enjoy!
Gautier de Montmollin
gautier.de.montmollin, at: gmail dot com.