1 # -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
18 def parse_block(data
, index
):
19 start_row
= struct
.unpack('Q', data
[index
:index
+8])[0]
21 data_size
= struct
.unpack('Q', data
[index
:index
+8])[0]
23 block_type
= struct
.unpack('B', data
[index
:index
+1])[0]
28 for i
in range(data_size
):
29 vals
[start_row
+ i
] = struct
.unpack('d', data
[index
:index
+8])[0]
33 for i
in range(data_size
):
34 str_length
= struct
.unpack('i', data
[index
:index
+4])[0]
36 vals
[start_row
+ i
] = data
[index
:index
+str_length
].decode("utf-8")
41 while read_rows
< data_size
:
42 formula_group_size
= struct
.unpack('Q', data
[index
:index
+8])[0]
44 str_length
= struct
.unpack('i', data
[index
:index
+4])[0]
46 vals
[start_row
+ read_rows
] = (data
[index
:index
+str_length
].decode("utf-8"), "formula group length %i"% formula_group_size
)
47 read_rows
+= formula_group_size
50 return index
, data_size
, vals
53 def parse_column(data
, index
):
54 column_index
= struct
.unpack('Q', data
[index
:index
+8])[0]
56 column_entries
= struct
.unpack('Q', data
[index
:index
+8])[0]
60 while imported_columns
< column_entries
:
61 index
, block_size
, vals
= parse_block(data
, index
)
62 imported_columns
+= block_size
63 column_values
.update(vals
)
64 return index
, column_values
66 def parse_columns(data
, index
):
67 column_count
= struct
.unpack('Q', data
[index
:index
+8])[0]
70 for i
in range(column_count
):
71 index
, column_values
= parse_column(data
, index
)
72 columns
[i
] = column_values
77 filename
= sys
.argv
[1]
78 with
open(filename
, "rb") as f
:
81 columns
= parse_columns(content
, index
)
84 if __name__
== "__main__":
87 # vim:set shiftwidth=4 softtabstop=4 expandtab: */