numbers-parser 4.8.0__tar.gz → 4.9.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/PKG-INFO +96 -74
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/README.md +95 -73
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/pyproject.toml +2 -1
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/cell.py +110 -13
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/cell_storage.py +48 -12
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/constants.py +109 -6
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/containers.py +2 -2
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/document.py +303 -136
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/file.py +9 -4
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/model.py +104 -7
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/LICENSE.rst +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/__init__.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/_cat_numbers.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/_unpack_numbers.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/bullets.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/currencies.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/data/empty.numbers +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/exceptions.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/experimental.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/formula.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TNArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TNArchives_sos_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TNCommandArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TNCommandArchives_sos_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSAArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSAArchives_sos_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSACommandArchives_sos_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSCEArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSCH3DArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSCHArchives_Common_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSCHArchives_GEN_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSCHArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSCHArchives_sos_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSCHCommandArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSCHPreUFFArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSDArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSDArchives_sos_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSDCommandArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSKArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSKArchives_sos_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSPArchiveMessages_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSPDatabaseMessages_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSPMessages_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSSArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSSArchives_sos_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSTArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSTArchives_sos_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSTCommandArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSTStylePropertyArchiving_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSWPArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSWPArchives_sos_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/TSWPCommandArchives_pb2.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/__init__.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/fontmap.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/generated/functionmap.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/iwafile.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/mapping.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/numbers_cache.py +0 -0
- {numbers_parser-4.8.0 → numbers_parser-4.9.0}/src/numbers_parser/numbers_uuid.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: numbers-parser
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.9.0
|
|
4
4
|
Summary: Read and write Apple Numbers spreadsheets
|
|
5
5
|
Home-page: https://github.com/masaccio/numbers-parser
|
|
6
6
|
License: MIT
|
|
@@ -57,14 +57,16 @@ For Intel Macs:
|
|
|
57
57
|
|
|
58
58
|
```bash
|
|
59
59
|
brew install snappy python3
|
|
60
|
-
CPPFLAGS="-I/usr/local/include -L/usr/local/lib"
|
|
60
|
+
CPPFLAGS="-I/usr/local/include -L/usr/local/lib" \
|
|
61
|
+
python3 -m pip install python-snappy
|
|
61
62
|
```
|
|
62
63
|
|
|
63
64
|
For Apple Silicon Macs:
|
|
64
65
|
|
|
65
66
|
```bash
|
|
66
67
|
brew install snappy python3
|
|
67
|
-
CPPFLAGS="-I/opt/homebrew/include -L/opt/homebrew/lib"
|
|
68
|
+
CPPFLAGS="-I/opt/homebrew/include -L/opt/homebrew/lib" \
|
|
69
|
+
python3 -m pip install python-snappy
|
|
68
70
|
```
|
|
69
71
|
|
|
70
72
|
For Linux (your package manager may be different):
|
|
@@ -78,10 +80,10 @@ binary libraries compiled by [Christoph Gohlke](https://www.lfd.uci.edu/~gohlke/
|
|
|
78
80
|
version for your installation. For example for python 3.11:
|
|
79
81
|
|
|
80
82
|
```text
|
|
81
|
-
|
|
83
|
+
pip install python_snappy-0.6.1-cp311-cp311-win_amd64.whl
|
|
82
84
|
```
|
|
83
85
|
|
|
84
|
-
|
|
86
|
+
## Quick Start
|
|
85
87
|
|
|
86
88
|
Reading documents:
|
|
87
89
|
|
|
@@ -121,7 +123,7 @@ the column values.
|
|
|
121
123
|
'Debit'
|
|
122
124
|
```
|
|
123
125
|
|
|
124
|
-
|
|
126
|
+
### Cell Data
|
|
125
127
|
|
|
126
128
|
Cells are objects with a common base class of `Cell`. All cell types
|
|
127
129
|
have a property `value` which returns the contents of the cell as a
|
|
@@ -129,17 +131,17 @@ python datatype. `numbers-parser` uses
|
|
|
129
131
|
[pendulum](https://pendulum.eustace.io) instead of python’s builtin
|
|
130
132
|
types. Available cell types are:
|
|
131
133
|
|
|
132
|
-
| Cell type
|
|
133
|
-
|
|
134
|
-
|
|
|
135
|
-
| TextCell
|
|
136
|
-
|
|
|
137
|
-
| EmptyCell
|
|
138
|
-
| BoolCell
|
|
139
|
-
| DateCell
|
|
140
|
-
|
|
|
141
|
-
| ErrorCell
|
|
142
|
-
|
|
|
134
|
+
| Cell type | value type | Additional properties |
|
|
135
|
+
|--------------|---------------------|--------------------------------------------------------------------------------------------------------|
|
|
136
|
+
| NumberCell | `float` | |
|
|
137
|
+
| TextCell | `str` | |
|
|
138
|
+
| RichTextCell | `str` | See [Rich text](https://masaccio.github.io/numbers-parser/api/cells.html#numbers_parser.RichTextCell) |
|
|
139
|
+
| EmptyCell | `None` | |
|
|
140
|
+
| BoolCell | `bool` | |
|
|
141
|
+
| DateCell | `pendulum.datetime` | |
|
|
142
|
+
| DurationCell | `pendulum.duration` | |
|
|
143
|
+
| ErrorCell | `None` | |
|
|
144
|
+
| MergedCell | `None` | See [Merged cells](https://masaccio.github.io/numbers-parser/api/cells.html#numbers_parser.MergedCell) |
|
|
143
145
|
|
|
144
146
|
Cell references can be either zero-offset row/column integers or an
|
|
145
147
|
Excel/Numbers A1 notation. Where cell values are not `None` the
|
|
@@ -161,7 +163,7 @@ any kind `ErrorCell`.
|
|
|
161
163
|
'£1,234.50'
|
|
162
164
|
```
|
|
163
165
|
|
|
164
|
-
|
|
166
|
+
### Pandas Support
|
|
165
167
|
|
|
166
168
|
Since the return value of `rows()` is a list of lists, you can pass
|
|
167
169
|
this directly to pandas. Assuming you have a Numbers table with a single
|
|
@@ -178,15 +180,15 @@ data = tables[0].rows(values_only=True)
|
|
|
178
180
|
df = pd.DataFrame(data[1:], columns=data[0])
|
|
179
181
|
```
|
|
180
182
|
|
|
181
|
-
|
|
183
|
+
### Writing Numbers Documents
|
|
182
184
|
|
|
183
185
|
Whilst support for writing numbers files has been stable since version
|
|
184
186
|
3.4.0, you are highly recommended not to overwrite working Numbers files
|
|
185
187
|
and instead save data to a new file.
|
|
186
188
|
|
|
187
189
|
Cell values are written using
|
|
188
|
-
[Table.write()](https://masaccio.github.io/numbers-parser
|
|
189
|
-
|
|
190
|
+
[Table.write()](https://masaccio.github.io/numbers-parser/api/table.html#numbers_parser.Table.write) and
|
|
191
|
+
`numbers-parser` will automatically create empty rows and columns
|
|
190
192
|
for any cell references that are out of range of the current table.
|
|
191
193
|
|
|
192
194
|
```python
|
|
@@ -199,12 +201,9 @@ table.write("B7", datetime(2020, 12, 25))
|
|
|
199
201
|
doc.save("new-sheet.numbers")
|
|
200
202
|
```
|
|
201
203
|
|
|
202
|
-
Additional tables and worksheets can be added to a `Document` before
|
|
203
|
-
|
|
204
|
-
[
|
|
205
|
-
and
|
|
206
|
-
[Sheet.add_table()](https://masaccio.github.io/numbers-parser/#numbers_parser.Sheet.add_table)
|
|
207
|
-
respectively:
|
|
204
|
+
Additional tables and worksheets can be added to a `Document` before saving using
|
|
205
|
+
[Document.add_sheet()](https://masaccio.github.io/numbers-parser/api/document.html#numbers_parser.Document.add_sheet) and
|
|
206
|
+
[Sheet.add_table()](https://masaccio.github.io/numbers-parser/api/sheet.html#numbers_parser.Sheet.add_table) respectively:
|
|
208
207
|
|
|
209
208
|
```python
|
|
210
209
|
doc = Document()
|
|
@@ -217,37 +216,48 @@ table.write(1, 3, 3000)
|
|
|
217
216
|
doc.save("sheet.numbers")
|
|
218
217
|
```
|
|
219
218
|
|
|
220
|
-
|
|
219
|
+
### Styles
|
|
221
220
|
|
|
222
221
|
`numbers_parser` currently only supports paragraph styles and cell
|
|
223
|
-
styles. The following
|
|
222
|
+
styles. The following styles are supported:
|
|
224
223
|
|
|
225
224
|
- font attributes: bold, italic, underline, strikethrough
|
|
226
225
|
- font selection and size
|
|
227
226
|
- text foreground color
|
|
228
227
|
- horizontal and vertical alignment
|
|
229
228
|
- cell background color
|
|
229
|
+
- cell background images
|
|
230
230
|
- cell indents (first line, left, right, and text inset)
|
|
231
231
|
|
|
232
232
|
Numbers conflates style attributes that can be stored in paragraph
|
|
233
233
|
styles (the style menu in the text panel) with the settings that are
|
|
234
234
|
available on the Style tab of the Text panel. Some attributes in Numbers
|
|
235
|
-
are not applied to new cells when a style is applied.
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
object. When a document is saved, the attributes
|
|
239
|
-
paragraph style are applied to each cell that includes it.
|
|
235
|
+
are not applied to new cells when a style is applied.
|
|
236
|
+
|
|
237
|
+
To keep the API simple, `numbers-parser` packs all styling into a single
|
|
238
|
+
[Style](https://masaccio.github.io/numbers-parser/api/style.html) object. When a document is saved, the attributes
|
|
239
|
+
not stored in a paragraph style are applied to each cell that includes it.
|
|
240
240
|
|
|
241
241
|
Styles are read from cells using the
|
|
242
|
-
[Cell.style](https://masaccio.github.io/numbers-parser
|
|
243
|
-
|
|
244
|
-
[Document.add_style](https://masaccio.github.io/numbers-parser
|
|
242
|
+
[Cell.style](https://masaccio.github.io/numbers-parser/api/cells.html#numbers_parser.Cell.style) property and you can
|
|
243
|
+
add new styles with
|
|
244
|
+
[Document.add_style](https://masaccio.github.io/numbers-parser/api/document.html#numbers_parser.Document.add_style).
|
|
245
245
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
246
|
+
```python
|
|
247
|
+
red_text = doc.add_style(
|
|
248
|
+
name="Red Text",
|
|
249
|
+
font_name="Lucida Grande",
|
|
250
|
+
font_color=RGB(230, 25, 25),
|
|
251
|
+
font_size=14.0,
|
|
252
|
+
bold=True,
|
|
253
|
+
italic=True,
|
|
254
|
+
alignment=Alignment("right", "top"),
|
|
255
|
+
)
|
|
256
|
+
table.write("B2", "Red", style=red_text)
|
|
257
|
+
table.set_cell_style("C2", red_text)
|
|
258
|
+
```
|
|
249
259
|
|
|
250
|
-
|
|
260
|
+
### Cell Data Formatting
|
|
251
261
|
|
|
252
262
|
Numbers has two different cell formatting types: data formats and custom
|
|
253
263
|
formats.
|
|
@@ -260,23 +270,37 @@ internally by the package. Changing a data format for cell has no impact
|
|
|
260
270
|
on any other cells.
|
|
261
271
|
|
|
262
272
|
Cell formats are changed using
|
|
263
|
-
[Table.set_cell_formatting](https://masaccio.github.io/numbers-parser
|
|
273
|
+
[Table.set_cell_formatting()](https://masaccio.github.io/numbers-parser/api/table.html#numbers_parser.Table.set_cell_formatting):
|
|
264
274
|
|
|
265
275
|
```python
|
|
266
|
-
table.set_cell_formatting(
|
|
267
|
-
|
|
276
|
+
table.set_cell_formatting(
|
|
277
|
+
"C1",
|
|
278
|
+
"date",
|
|
279
|
+
date_time_format="EEEE, d MMMM yyyy"
|
|
280
|
+
)
|
|
281
|
+
table.set_cell_formatting(
|
|
282
|
+
0,
|
|
283
|
+
4,
|
|
284
|
+
"number",
|
|
285
|
+
decimal_places=3,
|
|
286
|
+
negative_style=NegativeNumberStyle.RED
|
|
287
|
+
)
|
|
268
288
|
```
|
|
269
289
|
|
|
270
290
|
Custom formats are shared across a Document and can be applied to
|
|
271
291
|
multiple cells in multiple tables. Editing a custom format changes the
|
|
272
292
|
appearance of data in all cells that share that format. You must first
|
|
273
293
|
add a custom format to the document using
|
|
274
|
-
[Document.add_custom_format](https://masaccio.github.io/numbers-parser
|
|
294
|
+
[Document.add_custom_format()](https://masaccio.github.io/numbers-parser/api/document.html#numbers_parser.Document.add_custom_format)
|
|
275
295
|
before assigning it to cells using
|
|
276
|
-
[Table.set_cell_formatting](https://masaccio.github.io/numbers-parser
|
|
296
|
+
[Table.set_cell_formatting()](https://masaccio.github.io/numbers-parser/api/table.html#numbers_parser.Table.set_cell_formatting):
|
|
277
297
|
|
|
278
298
|
```python
|
|
279
|
-
long_date = doc.add_custom_format(
|
|
299
|
+
long_date = doc.add_custom_format(
|
|
300
|
+
name="Long Date",
|
|
301
|
+
type="date",
|
|
302
|
+
date_time_format="EEEE, d MMMM yyyy"
|
|
303
|
+
)
|
|
280
304
|
table.set_cell_formatting("C1", "custom", format=long_date)
|
|
281
305
|
```
|
|
282
306
|
|
|
@@ -287,7 +311,7 @@ example, US dollars are referred to as `US$` whereas Euros and British
|
|
|
287
311
|
Pounds are referred to using their symbols of `€` and `£`
|
|
288
312
|
respectively.
|
|
289
313
|
|
|
290
|
-
|
|
314
|
+
### Borders
|
|
291
315
|
|
|
292
316
|
`numbers-parser` supports reading and writing cell borders, though the
|
|
293
317
|
interface for each differs. Individual cells can have each of their four
|
|
@@ -296,13 +320,11 @@ table to allow for drawing borders across multiple cells. Setting the
|
|
|
296
320
|
border of merged cells is not possible unless the edge of the cells is
|
|
297
321
|
at the end of the merged region.
|
|
298
322
|
|
|
299
|
-
Borders are represented using the
|
|
300
|
-
|
|
301
|
-
class that can be initialized with line width, color and line style. The
|
|
323
|
+
Borders are represented using the [Border](https://masaccio.github.io/numbers-parser/api/border.html) class
|
|
324
|
+
that can be initialized with line width, color and line style. The
|
|
302
325
|
current state of a cell border is read using the
|
|
303
|
-
[Cell.border](https://masaccio.github.io/numbers-parser
|
|
304
|
-
|
|
305
|
-
[Table.set_cell_border](https://masaccio.github.io/numbers-parser/#numbers_parser.Table.set_cell_border)
|
|
326
|
+
[Cell.border](https://masaccio.github.io/numbers-parser/api/cells.html#numbers_parser.Cell.border) property
|
|
327
|
+
and [Table.set_cell_border()](https://masaccio.github.io/numbers-parser/api/table.html#numbers_parser.Table.set_cell_border)
|
|
306
328
|
sets the border for a cell edge or a range of cells.
|
|
307
329
|
|
|
308
330
|
## API
|
|
@@ -319,25 +341,30 @@ format, iterating through all the spreadsheets passed on the
|
|
|
319
341
|
command-line.
|
|
320
342
|
|
|
321
343
|
```text
|
|
322
|
-
usage: cat-numbers [-h] [-T | -S | -b] [-V] [--
|
|
323
|
-
|
|
344
|
+
usage: cat-numbers [-h] [-T | -S | -b] [-V] [--formulas] [--formatting]
|
|
345
|
+
[-s SHEET] [-t TABLE] [--debug]
|
|
346
|
+
[document ...]
|
|
324
347
|
|
|
325
348
|
Export data from Apple Numbers spreadsheet tables
|
|
326
349
|
|
|
327
350
|
positional arguments:
|
|
328
|
-
document
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
-h, --help
|
|
332
|
-
-T, --list-tables
|
|
333
|
-
-S, --list-sheets
|
|
334
|
-
-b, --brief
|
|
351
|
+
document Document(s) to export
|
|
352
|
+
|
|
353
|
+
options:
|
|
354
|
+
-h, --help show this help message and exit
|
|
355
|
+
-T, --list-tables List the names of tables and exit
|
|
356
|
+
-S, --list-sheets List the names of sheets and exit
|
|
357
|
+
-b, --brief Don't prefix data rows with name of sheet/table
|
|
358
|
+
(default: false)
|
|
335
359
|
-V, --version
|
|
336
|
-
--
|
|
337
|
-
--
|
|
338
|
-
|
|
339
|
-
-s SHEET, --sheet SHEET
|
|
340
|
-
|
|
360
|
+
--formulas Dump formulas instead of formula results
|
|
361
|
+
--formatting Dump formatted cells (durations) as they appear
|
|
362
|
+
in Numbers
|
|
363
|
+
-s SHEET, --sheet SHEET
|
|
364
|
+
Names of sheet(s) to include in export
|
|
365
|
+
-t TABLE, --table TABLE
|
|
366
|
+
Names of table(s) to include in export
|
|
367
|
+
--debug Enable debug logging
|
|
341
368
|
```
|
|
342
369
|
|
|
343
370
|
Note: `--formatting` will return different capitalization for 12-hour
|
|
@@ -358,10 +385,6 @@ Current known limitations of `numbers-parser` are:
|
|
|
358
385
|
worksheet which does not take into account title or caption size
|
|
359
386
|
- New sheets insert tables with formats copied from the first table in
|
|
360
387
|
the previous sheet rather than default table formats
|
|
361
|
-
- Creating custom cell formats and cell data formats is experimental
|
|
362
|
-
and not all formats are supported. See
|
|
363
|
-
[Table.set_cell_formatting](https://masaccio.github.io/numbers-parser/#numbers_parser.Table.set_cell_formatting)
|
|
364
|
-
for more details.
|
|
365
388
|
- Due to a limitation in Python’s
|
|
366
389
|
[ZipFile](https://docs.python.org/3/library/zipfile.html), Python
|
|
367
390
|
versions older than 3.11 do not support image filenames with UTF-8
|
|
@@ -373,6 +396,5 @@ Current known limitations of `numbers-parser` are:
|
|
|
373
396
|
|
|
374
397
|
## License
|
|
375
398
|
|
|
376
|
-
All code in this repository is licensed under the [MIT
|
|
377
|
-
License](https://github.com/masaccio/numbers-parser/blob/master/LICENSE.rst)
|
|
399
|
+
All code in this repository is licensed under the [MIT License](https://github.com/masaccio/numbers-parser/blob/master/LICENSE.rst).
|
|
378
400
|
|
|
@@ -27,14 +27,16 @@ For Intel Macs:
|
|
|
27
27
|
|
|
28
28
|
```bash
|
|
29
29
|
brew install snappy python3
|
|
30
|
-
CPPFLAGS="-I/usr/local/include -L/usr/local/lib"
|
|
30
|
+
CPPFLAGS="-I/usr/local/include -L/usr/local/lib" \
|
|
31
|
+
python3 -m pip install python-snappy
|
|
31
32
|
```
|
|
32
33
|
|
|
33
34
|
For Apple Silicon Macs:
|
|
34
35
|
|
|
35
36
|
```bash
|
|
36
37
|
brew install snappy python3
|
|
37
|
-
CPPFLAGS="-I/opt/homebrew/include -L/opt/homebrew/lib"
|
|
38
|
+
CPPFLAGS="-I/opt/homebrew/include -L/opt/homebrew/lib" \
|
|
39
|
+
python3 -m pip install python-snappy
|
|
38
40
|
```
|
|
39
41
|
|
|
40
42
|
For Linux (your package manager may be different):
|
|
@@ -48,10 +50,10 @@ binary libraries compiled by [Christoph Gohlke](https://www.lfd.uci.edu/~gohlke/
|
|
|
48
50
|
version for your installation. For example for python 3.11:
|
|
49
51
|
|
|
50
52
|
```text
|
|
51
|
-
|
|
53
|
+
pip install python_snappy-0.6.1-cp311-cp311-win_amd64.whl
|
|
52
54
|
```
|
|
53
55
|
|
|
54
|
-
|
|
56
|
+
## Quick Start
|
|
55
57
|
|
|
56
58
|
Reading documents:
|
|
57
59
|
|
|
@@ -91,7 +93,7 @@ the column values.
|
|
|
91
93
|
'Debit'
|
|
92
94
|
```
|
|
93
95
|
|
|
94
|
-
|
|
96
|
+
### Cell Data
|
|
95
97
|
|
|
96
98
|
Cells are objects with a common base class of `Cell`. All cell types
|
|
97
99
|
have a property `value` which returns the contents of the cell as a
|
|
@@ -99,17 +101,17 @@ python datatype. `numbers-parser` uses
|
|
|
99
101
|
[pendulum](https://pendulum.eustace.io) instead of python’s builtin
|
|
100
102
|
types. Available cell types are:
|
|
101
103
|
|
|
102
|
-
| Cell type
|
|
103
|
-
|
|
104
|
-
|
|
|
105
|
-
| TextCell
|
|
106
|
-
|
|
|
107
|
-
| EmptyCell
|
|
108
|
-
| BoolCell
|
|
109
|
-
| DateCell
|
|
110
|
-
|
|
|
111
|
-
| ErrorCell
|
|
112
|
-
|
|
|
104
|
+
| Cell type | value type | Additional properties |
|
|
105
|
+
|--------------|---------------------|--------------------------------------------------------------------------------------------------------|
|
|
106
|
+
| NumberCell | `float` | |
|
|
107
|
+
| TextCell | `str` | |
|
|
108
|
+
| RichTextCell | `str` | See [Rich text](https://masaccio.github.io/numbers-parser/api/cells.html#numbers_parser.RichTextCell) |
|
|
109
|
+
| EmptyCell | `None` | |
|
|
110
|
+
| BoolCell | `bool` | |
|
|
111
|
+
| DateCell | `pendulum.datetime` | |
|
|
112
|
+
| DurationCell | `pendulum.duration` | |
|
|
113
|
+
| ErrorCell | `None` | |
|
|
114
|
+
| MergedCell | `None` | See [Merged cells](https://masaccio.github.io/numbers-parser/api/cells.html#numbers_parser.MergedCell) |
|
|
113
115
|
|
|
114
116
|
Cell references can be either zero-offset row/column integers or an
|
|
115
117
|
Excel/Numbers A1 notation. Where cell values are not `None` the
|
|
@@ -131,7 +133,7 @@ any kind `ErrorCell`.
|
|
|
131
133
|
'£1,234.50'
|
|
132
134
|
```
|
|
133
135
|
|
|
134
|
-
|
|
136
|
+
### Pandas Support
|
|
135
137
|
|
|
136
138
|
Since the return value of `rows()` is a list of lists, you can pass
|
|
137
139
|
this directly to pandas. Assuming you have a Numbers table with a single
|
|
@@ -148,15 +150,15 @@ data = tables[0].rows(values_only=True)
|
|
|
148
150
|
df = pd.DataFrame(data[1:], columns=data[0])
|
|
149
151
|
```
|
|
150
152
|
|
|
151
|
-
|
|
153
|
+
### Writing Numbers Documents
|
|
152
154
|
|
|
153
155
|
Whilst support for writing numbers files has been stable since version
|
|
154
156
|
3.4.0, you are highly recommended not to overwrite working Numbers files
|
|
155
157
|
and instead save data to a new file.
|
|
156
158
|
|
|
157
159
|
Cell values are written using
|
|
158
|
-
[Table.write()](https://masaccio.github.io/numbers-parser
|
|
159
|
-
|
|
160
|
+
[Table.write()](https://masaccio.github.io/numbers-parser/api/table.html#numbers_parser.Table.write) and
|
|
161
|
+
`numbers-parser` will automatically create empty rows and columns
|
|
160
162
|
for any cell references that are out of range of the current table.
|
|
161
163
|
|
|
162
164
|
```python
|
|
@@ -169,12 +171,9 @@ table.write("B7", datetime(2020, 12, 25))
|
|
|
169
171
|
doc.save("new-sheet.numbers")
|
|
170
172
|
```
|
|
171
173
|
|
|
172
|
-
Additional tables and worksheets can be added to a `Document` before
|
|
173
|
-
|
|
174
|
-
[
|
|
175
|
-
and
|
|
176
|
-
[Sheet.add_table()](https://masaccio.github.io/numbers-parser/#numbers_parser.Sheet.add_table)
|
|
177
|
-
respectively:
|
|
174
|
+
Additional tables and worksheets can be added to a `Document` before saving using
|
|
175
|
+
[Document.add_sheet()](https://masaccio.github.io/numbers-parser/api/document.html#numbers_parser.Document.add_sheet) and
|
|
176
|
+
[Sheet.add_table()](https://masaccio.github.io/numbers-parser/api/sheet.html#numbers_parser.Sheet.add_table) respectively:
|
|
178
177
|
|
|
179
178
|
```python
|
|
180
179
|
doc = Document()
|
|
@@ -187,37 +186,48 @@ table.write(1, 3, 3000)
|
|
|
187
186
|
doc.save("sheet.numbers")
|
|
188
187
|
```
|
|
189
188
|
|
|
190
|
-
|
|
189
|
+
### Styles
|
|
191
190
|
|
|
192
191
|
`numbers_parser` currently only supports paragraph styles and cell
|
|
193
|
-
styles. The following
|
|
192
|
+
styles. The following styles are supported:
|
|
194
193
|
|
|
195
194
|
- font attributes: bold, italic, underline, strikethrough
|
|
196
195
|
- font selection and size
|
|
197
196
|
- text foreground color
|
|
198
197
|
- horizontal and vertical alignment
|
|
199
198
|
- cell background color
|
|
199
|
+
- cell background images
|
|
200
200
|
- cell indents (first line, left, right, and text inset)
|
|
201
201
|
|
|
202
202
|
Numbers conflates style attributes that can be stored in paragraph
|
|
203
203
|
styles (the style menu in the text panel) with the settings that are
|
|
204
204
|
available on the Style tab of the Text panel. Some attributes in Numbers
|
|
205
|
-
are not applied to new cells when a style is applied.
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
object. When a document is saved, the attributes
|
|
209
|
-
paragraph style are applied to each cell that includes it.
|
|
205
|
+
are not applied to new cells when a style is applied.
|
|
206
|
+
|
|
207
|
+
To keep the API simple, `numbers-parser` packs all styling into a single
|
|
208
|
+
[Style](https://masaccio.github.io/numbers-parser/api/style.html) object. When a document is saved, the attributes
|
|
209
|
+
not stored in a paragraph style are applied to each cell that includes it.
|
|
210
210
|
|
|
211
211
|
Styles are read from cells using the
|
|
212
|
-
[Cell.style](https://masaccio.github.io/numbers-parser
|
|
213
|
-
|
|
214
|
-
[Document.add_style](https://masaccio.github.io/numbers-parser
|
|
212
|
+
[Cell.style](https://masaccio.github.io/numbers-parser/api/cells.html#numbers_parser.Cell.style) property and you can
|
|
213
|
+
add new styles with
|
|
214
|
+
[Document.add_style](https://masaccio.github.io/numbers-parser/api/document.html#numbers_parser.Document.add_style).
|
|
215
215
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
```python
|
|
217
|
+
red_text = doc.add_style(
|
|
218
|
+
name="Red Text",
|
|
219
|
+
font_name="Lucida Grande",
|
|
220
|
+
font_color=RGB(230, 25, 25),
|
|
221
|
+
font_size=14.0,
|
|
222
|
+
bold=True,
|
|
223
|
+
italic=True,
|
|
224
|
+
alignment=Alignment("right", "top"),
|
|
225
|
+
)
|
|
226
|
+
table.write("B2", "Red", style=red_text)
|
|
227
|
+
table.set_cell_style("C2", red_text)
|
|
228
|
+
```
|
|
219
229
|
|
|
220
|
-
|
|
230
|
+
### Cell Data Formatting
|
|
221
231
|
|
|
222
232
|
Numbers has two different cell formatting types: data formats and custom
|
|
223
233
|
formats.
|
|
@@ -230,23 +240,37 @@ internally by the package. Changing a data format for cell has no impact
|
|
|
230
240
|
on any other cells.
|
|
231
241
|
|
|
232
242
|
Cell formats are changed using
|
|
233
|
-
[Table.set_cell_formatting](https://masaccio.github.io/numbers-parser
|
|
243
|
+
[Table.set_cell_formatting()](https://masaccio.github.io/numbers-parser/api/table.html#numbers_parser.Table.set_cell_formatting):
|
|
234
244
|
|
|
235
245
|
```python
|
|
236
|
-
table.set_cell_formatting(
|
|
237
|
-
|
|
246
|
+
table.set_cell_formatting(
|
|
247
|
+
"C1",
|
|
248
|
+
"date",
|
|
249
|
+
date_time_format="EEEE, d MMMM yyyy"
|
|
250
|
+
)
|
|
251
|
+
table.set_cell_formatting(
|
|
252
|
+
0,
|
|
253
|
+
4,
|
|
254
|
+
"number",
|
|
255
|
+
decimal_places=3,
|
|
256
|
+
negative_style=NegativeNumberStyle.RED
|
|
257
|
+
)
|
|
238
258
|
```
|
|
239
259
|
|
|
240
260
|
Custom formats are shared across a Document and can be applied to
|
|
241
261
|
multiple cells in multiple tables. Editing a custom format changes the
|
|
242
262
|
appearance of data in all cells that share that format. You must first
|
|
243
263
|
add a custom format to the document using
|
|
244
|
-
[Document.add_custom_format](https://masaccio.github.io/numbers-parser
|
|
264
|
+
[Document.add_custom_format()](https://masaccio.github.io/numbers-parser/api/document.html#numbers_parser.Document.add_custom_format)
|
|
245
265
|
before assigning it to cells using
|
|
246
|
-
[Table.set_cell_formatting](https://masaccio.github.io/numbers-parser
|
|
266
|
+
[Table.set_cell_formatting()](https://masaccio.github.io/numbers-parser/api/table.html#numbers_parser.Table.set_cell_formatting):
|
|
247
267
|
|
|
248
268
|
```python
|
|
249
|
-
long_date = doc.add_custom_format(
|
|
269
|
+
long_date = doc.add_custom_format(
|
|
270
|
+
name="Long Date",
|
|
271
|
+
type="date",
|
|
272
|
+
date_time_format="EEEE, d MMMM yyyy"
|
|
273
|
+
)
|
|
250
274
|
table.set_cell_formatting("C1", "custom", format=long_date)
|
|
251
275
|
```
|
|
252
276
|
|
|
@@ -257,7 +281,7 @@ example, US dollars are referred to as `US$` whereas Euros and British
|
|
|
257
281
|
Pounds are referred to using their symbols of `€` and `£`
|
|
258
282
|
respectively.
|
|
259
283
|
|
|
260
|
-
|
|
284
|
+
### Borders
|
|
261
285
|
|
|
262
286
|
`numbers-parser` supports reading and writing cell borders, though the
|
|
263
287
|
interface for each differs. Individual cells can have each of their four
|
|
@@ -266,13 +290,11 @@ table to allow for drawing borders across multiple cells. Setting the
|
|
|
266
290
|
border of merged cells is not possible unless the edge of the cells is
|
|
267
291
|
at the end of the merged region.
|
|
268
292
|
|
|
269
|
-
Borders are represented using the
|
|
270
|
-
|
|
271
|
-
class that can be initialized with line width, color and line style. The
|
|
293
|
+
Borders are represented using the [Border](https://masaccio.github.io/numbers-parser/api/border.html) class
|
|
294
|
+
that can be initialized with line width, color and line style. The
|
|
272
295
|
current state of a cell border is read using the
|
|
273
|
-
[Cell.border](https://masaccio.github.io/numbers-parser
|
|
274
|
-
|
|
275
|
-
[Table.set_cell_border](https://masaccio.github.io/numbers-parser/#numbers_parser.Table.set_cell_border)
|
|
296
|
+
[Cell.border](https://masaccio.github.io/numbers-parser/api/cells.html#numbers_parser.Cell.border) property
|
|
297
|
+
and [Table.set_cell_border()](https://masaccio.github.io/numbers-parser/api/table.html#numbers_parser.Table.set_cell_border)
|
|
276
298
|
sets the border for a cell edge or a range of cells.
|
|
277
299
|
|
|
278
300
|
## API
|
|
@@ -289,25 +311,30 @@ format, iterating through all the spreadsheets passed on the
|
|
|
289
311
|
command-line.
|
|
290
312
|
|
|
291
313
|
```text
|
|
292
|
-
usage: cat-numbers [-h] [-T | -S | -b] [-V] [--
|
|
293
|
-
|
|
314
|
+
usage: cat-numbers [-h] [-T | -S | -b] [-V] [--formulas] [--formatting]
|
|
315
|
+
[-s SHEET] [-t TABLE] [--debug]
|
|
316
|
+
[document ...]
|
|
294
317
|
|
|
295
318
|
Export data from Apple Numbers spreadsheet tables
|
|
296
319
|
|
|
297
320
|
positional arguments:
|
|
298
|
-
document
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
-h, --help
|
|
302
|
-
-T, --list-tables
|
|
303
|
-
-S, --list-sheets
|
|
304
|
-
-b, --brief
|
|
321
|
+
document Document(s) to export
|
|
322
|
+
|
|
323
|
+
options:
|
|
324
|
+
-h, --help show this help message and exit
|
|
325
|
+
-T, --list-tables List the names of tables and exit
|
|
326
|
+
-S, --list-sheets List the names of sheets and exit
|
|
327
|
+
-b, --brief Don't prefix data rows with name of sheet/table
|
|
328
|
+
(default: false)
|
|
305
329
|
-V, --version
|
|
306
|
-
--
|
|
307
|
-
--
|
|
308
|
-
|
|
309
|
-
-s SHEET, --sheet SHEET
|
|
310
|
-
|
|
330
|
+
--formulas Dump formulas instead of formula results
|
|
331
|
+
--formatting Dump formatted cells (durations) as they appear
|
|
332
|
+
in Numbers
|
|
333
|
+
-s SHEET, --sheet SHEET
|
|
334
|
+
Names of sheet(s) to include in export
|
|
335
|
+
-t TABLE, --table TABLE
|
|
336
|
+
Names of table(s) to include in export
|
|
337
|
+
--debug Enable debug logging
|
|
311
338
|
```
|
|
312
339
|
|
|
313
340
|
Note: `--formatting` will return different capitalization for 12-hour
|
|
@@ -328,10 +355,6 @@ Current known limitations of `numbers-parser` are:
|
|
|
328
355
|
worksheet which does not take into account title or caption size
|
|
329
356
|
- New sheets insert tables with formats copied from the first table in
|
|
330
357
|
the previous sheet rather than default table formats
|
|
331
|
-
- Creating custom cell formats and cell data formats is experimental
|
|
332
|
-
and not all formats are supported. See
|
|
333
|
-
[Table.set_cell_formatting](https://masaccio.github.io/numbers-parser/#numbers_parser.Table.set_cell_formatting)
|
|
334
|
-
for more details.
|
|
335
358
|
- Due to a limitation in Python’s
|
|
336
359
|
[ZipFile](https://docs.python.org/3/library/zipfile.html), Python
|
|
337
360
|
versions older than 3.11 do not support image filenames with UTF-8
|
|
@@ -343,5 +366,4 @@ Current known limitations of `numbers-parser` are:
|
|
|
343
366
|
|
|
344
367
|
## License
|
|
345
368
|
|
|
346
|
-
All code in this repository is licensed under the [MIT
|
|
347
|
-
License](https://github.com/masaccio/numbers-parser/blob/master/LICENSE.rst)
|
|
369
|
+
All code in this repository is licensed under the [MIT License](https://github.com/masaccio/numbers-parser/blob/master/LICENSE.rst).
|
|
@@ -12,7 +12,7 @@ name = "numbers-parser"
|
|
|
12
12
|
packages = [{include = "numbers_parser", from = "src"}]
|
|
13
13
|
readme = "README.md"
|
|
14
14
|
repository = "https://github.com/masaccio/numbers-parser"
|
|
15
|
-
version = "4.
|
|
15
|
+
version = "4.9.0"
|
|
16
16
|
|
|
17
17
|
[tool.poetry.scripts]
|
|
18
18
|
cat-numbers = "numbers_parser._cat_numbers:main"
|
|
@@ -53,6 +53,7 @@ enum-tools = "^0.11.0"
|
|
|
53
53
|
sphinx-toolbox = "^3.5.0"
|
|
54
54
|
sphinx-nefertiti = "^0.2.1"
|
|
55
55
|
sphinx-markdown-builder = "^0.6.6"
|
|
56
|
+
sphinx-copybutton = "^0.5.2"
|
|
56
57
|
|
|
57
58
|
[build-system]
|
|
58
59
|
build-backend = "poetry.core.masonry.api"
|