xlwings-utils 0.0.6__py3-none-any.whl → 0.0.7__py3-none-any.whl
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.
Potentially problematic release.
This version of xlwings-utils might be problematic. Click here for more details.
- xlwings_utils/xlwings_utils.py +48 -56
- xlwings_utils-0.0.7.dist-info/METADATA +132 -0
- xlwings_utils-0.0.7.dist-info/RECORD +6 -0
- xlwings_utils-0.0.6.dist-info/METADATA +0 -52
- xlwings_utils-0.0.6.dist-info/RECORD +0 -6
- {xlwings_utils-0.0.6.dist-info → xlwings_utils-0.0.7.dist-info}/WHEEL +0 -0
- {xlwings_utils-0.0.6.dist-info → xlwings_utils-0.0.7.dist-info}/top_level.txt +0 -0
xlwings_utils/xlwings_utils.py
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# /_/\_\|_| \_/\_/ |_||_| |_| \__, ||___/ _____ \__,_| \__||_||_||___/
|
|
6
6
|
# |___/ |_____|
|
|
7
7
|
|
|
8
|
-
__version__ = "0.0.
|
|
8
|
+
__version__ = "0.0.7"
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
import dropbox
|
|
@@ -268,55 +268,51 @@ class block:
|
|
|
268
268
|
block
|
|
269
269
|
"""
|
|
270
270
|
|
|
271
|
-
def __init__(self, number_of_rows, number_of_columns):
|
|
271
|
+
def __init__(self, value=None, *, number_of_rows=None, number_of_columns=None,column_like=False):
|
|
272
272
|
self.dict = {}
|
|
273
|
-
self.
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if not isinstance(list_of_lists[0], list):
|
|
304
|
-
if column_like:
|
|
305
|
-
list_of_lists = [[value] for value in list_of_lists]
|
|
273
|
+
self.column_like=column_like
|
|
274
|
+
if value is None:
|
|
275
|
+
if number_of_rows is None:
|
|
276
|
+
number_of_rows=1
|
|
277
|
+
if number_of_columns is None:
|
|
278
|
+
number_of_columns=1
|
|
279
|
+
self.number_of_rows=number_of_rows
|
|
280
|
+
self.number_of_columns=number_of_columns
|
|
281
|
+
|
|
282
|
+
else:
|
|
283
|
+
if isinstance(value,block):
|
|
284
|
+
value=value.value
|
|
285
|
+
self.value=value
|
|
286
|
+
if number_of_rows is not None:
|
|
287
|
+
self.number_of_rows=number_of_rows
|
|
288
|
+
if number_of_columns is not None:
|
|
289
|
+
self.number_of_columns=number_of_columns
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
@property
|
|
293
|
+
def value(self):
|
|
294
|
+
return [[self.dict.get((row, column)) for column in range(1, self.number_of_columns + 1)] for row in range(1, self.number_of_rows + 1)]
|
|
295
|
+
|
|
296
|
+
@value.setter
|
|
297
|
+
def value(self,value):
|
|
298
|
+
if not isinstance(value, list):
|
|
299
|
+
value = [[value]]
|
|
300
|
+
if not isinstance(value[0], list):
|
|
301
|
+
if self.column_like:
|
|
302
|
+
value = [[item] for item in value]
|
|
306
303
|
else:
|
|
307
|
-
|
|
304
|
+
value = [value]
|
|
308
305
|
|
|
309
|
-
self = cls(1, 1)
|
|
310
306
|
|
|
311
|
-
self.number_of_rows = len(
|
|
307
|
+
self.number_of_rows = len(value)
|
|
312
308
|
self._number_of_columns = 0
|
|
313
309
|
|
|
314
|
-
for row, row_contents in enumerate(
|
|
315
|
-
for column,
|
|
316
|
-
if
|
|
317
|
-
self.dict[row, column] =
|
|
318
|
-
self._number_of_columns = max(self.number_of_columns, column)
|
|
319
|
-
|
|
310
|
+
for row, row_contents in enumerate(value, 1):
|
|
311
|
+
for column, item in enumerate(row_contents, 1):
|
|
312
|
+
if item is not None:
|
|
313
|
+
self.dict[row, column] = item
|
|
314
|
+
self._number_of_columns = max(self.number_of_columns, column)
|
|
315
|
+
|
|
320
316
|
|
|
321
317
|
def __setitem__(self, row_column, value):
|
|
322
318
|
row, column = row_column
|
|
@@ -333,14 +329,9 @@ class block:
|
|
|
333
329
|
if column < 1 or column > self.number_of_columns:
|
|
334
330
|
raise IndexError(f"column must be between 1 and {self.number_of_columns} not {column}")
|
|
335
331
|
return self.dict.get((row, column))
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
return [[self.dict.get((row, column)) for column in range(1, self.number_of_columns + 1)] for row in range(1, self.number_of_rows + 1)]
|
|
340
|
-
|
|
341
|
-
@property
|
|
342
|
-
def as_minimal_list_of_lists(self):
|
|
343
|
-
return [[self.dict.get((row, column)) for column in range(1, self.maximum_column + 1)] for row in range(1, self.maximum_row + 1)]
|
|
332
|
+
|
|
333
|
+
def minimized(self):
|
|
334
|
+
return block(self, number_of_rows=self.highest_used_row_number, number_of_columns=self.highest_used_column_number)
|
|
344
335
|
|
|
345
336
|
@property
|
|
346
337
|
def number_of_rows(self):
|
|
@@ -367,23 +358,24 @@ class block:
|
|
|
367
358
|
for row, column in list(self.dict):
|
|
368
359
|
if column > self._number_of_columns:
|
|
369
360
|
del self.dict[row, column]
|
|
361
|
+
|
|
370
362
|
|
|
371
363
|
@property
|
|
372
|
-
def
|
|
364
|
+
def highest_used_row_number(self):
|
|
373
365
|
if self.dict:
|
|
374
366
|
return max(row for (row, column) in self.dict)
|
|
375
367
|
else:
|
|
376
368
|
return 1
|
|
377
369
|
|
|
378
370
|
@property
|
|
379
|
-
def
|
|
371
|
+
def highest_used_column_number(self):
|
|
380
372
|
if self.dict:
|
|
381
373
|
return max(column for (row, column) in self.dict)
|
|
382
374
|
else:
|
|
383
375
|
return 1
|
|
384
376
|
|
|
385
377
|
def __repr__(self):
|
|
386
|
-
return f"block
|
|
378
|
+
return f"block({self.value})"
|
|
387
379
|
|
|
388
380
|
|
|
389
381
|
def clear_captured_stdout():
|
|
@@ -406,7 +398,7 @@ def captured_stdout_as_str():
|
|
|
406
398
|
return "".join(_captured_stdout)
|
|
407
399
|
|
|
408
400
|
|
|
409
|
-
def
|
|
401
|
+
def captured_stdout_as_value():
|
|
410
402
|
"""
|
|
411
403
|
returns the captured stdout as a list of lists
|
|
412
404
|
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xlwings_utils
|
|
3
|
+
Version: 0.0.7
|
|
4
|
+
Summary: xlwings_utils
|
|
5
|
+
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
|
+
Project-URL: Homepage, https://github.com/salabim/xlwings_utils
|
|
7
|
+
Project-URL: Repository, https://github.com/salabim/xlwings_utils
|
|
8
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
Requires-Dist: dropbox
|
|
13
|
+
Requires-Dist: ssl
|
|
14
|
+
|
|
15
|
+
<img src="https://www.salabim.org/xlwings_utils_logo2.png">
|
|
16
|
+
|
|
17
|
+
## Introduction
|
|
18
|
+
|
|
19
|
+
This module provides some useful functions to be used in xlwings lite.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
Just add xlwings-utils to the *requirement.txt* tab. It might be required to add ssl.
|
|
24
|
+
|
|
25
|
+
In the script, add
|
|
26
|
+
|
|
27
|
+
```ìmport xlwings_utils as xwu```
|
|
28
|
+
|
|
29
|
+
## Dropbox support
|
|
30
|
+
|
|
31
|
+
The xlwings lite system does not provide access to the local file system. With this module, files can be copied between Dropbox and the local pyodide file system, making it possible to indirectly use the local file system.
|
|
32
|
+
|
|
33
|
+
It is only possible, as of now, to use full-access Dropbox apps.
|
|
34
|
+
|
|
35
|
+
The easiest way to use the Dropbox functionality is to add the credentials to the environment variables. Add REFRESH_TOKEN, APP_KEY and APP_SECRET with their corresponding values to the environment variables.
|
|
36
|
+
|
|
37
|
+
Then, it is possible to list all files in a specified folder with the function `list_dropbox`.
|
|
38
|
+
It is also possible to get the folders and to access all underlying folders.
|
|
39
|
+
|
|
40
|
+
The function `read_dropbox` can be used to read a Dropbox file's contents (bytes).
|
|
41
|
+
|
|
42
|
+
The function `write_dropbox` can be used to write contents (bytes) to a Dropbox file.
|
|
43
|
+
|
|
44
|
+
The functions `list_local`, `read_local` and `write_local` offer similar functionality for the local file system (on pyodide).
|
|
45
|
+
|
|
46
|
+
So, a way to access a file on the system's drive (mapped to Dropbox) as a local file is:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
contents = xlwings_utils.read_dropbox('/downloads/file1.xls')
|
|
50
|
+
xlwings_utils.write_local('file1.xlsx')
|
|
51
|
+
df = pandas.read_excel"file1.xlsx")
|
|
52
|
+
...
|
|
53
|
+
```
|
|
54
|
+
And the other direction:
|
|
55
|
+
```
|
|
56
|
+
contents = xlwings_utils.read_local('file1.gif')
|
|
57
|
+
xlwings_utils.write_dropbox('/downloads/file1.gif')
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Block support
|
|
61
|
+
|
|
62
|
+
The module contains a useful 2-dimensional data structure: *block*.
|
|
63
|
+
This can be useful to manipulate a range without accessing the range directly, which is expensive in terms of memory and execution time.
|
|
64
|
+
The advantage over an ordinary list of lists is that a block is index one-based, in line with range and addressing is done with a row, column tuple.
|
|
65
|
+
So, `my_block(lol)[row, col]` is roughly equivalent to `lol[row-1][col-1]`
|
|
66
|
+
|
|
67
|
+
A block stores the values internally as a dictionary and will only convert these to a list of lists when using `block.value`.
|
|
68
|
+
|
|
69
|
+
Converting the value of a range (usually a list of lists, but can also be a list or scalar) to a block can be done with
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
my_block = xwu.block.from_value(range.value)
|
|
73
|
+
```
|
|
74
|
+
The dimensions (number of rows and number of columns) are automatically set.
|
|
75
|
+
|
|
76
|
+
Setting of an individual item (one-based, like range) can be done like
|
|
77
|
+
```
|
|
78
|
+
my_block[row, column] = x
|
|
79
|
+
```
|
|
80
|
+
And, likewise, reading an individual item can be done like
|
|
81
|
+
```
|
|
82
|
+
x = my_block[row, column]
|
|
83
|
+
```
|
|
84
|
+
It is not allowed t,o read or write outside the block dimensions.
|
|
85
|
+
|
|
86
|
+
It is also possible to define an empty block, like
|
|
87
|
+
```
|
|
88
|
+
block = xlwings_utils.block(number_of_rows, number_columns)
|
|
89
|
+
```
|
|
90
|
+
The dimensions can be queried or redefined with `block.number_of_rows` and
|
|
91
|
+
`block.number_of_columns`.
|
|
92
|
+
|
|
93
|
+
To assign a block to range, use
|
|
94
|
+
```
|
|
95
|
+
range.value = block.value
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
The property `block.highest`_used_row_number returns the
|
|
99
|
+
|
|
100
|
+
The method `block.minimized()` returns a block that has the dimensions of (highest_used_row_number, highest_used_column_number).
|
|
101
|
+
|
|
102
|
+
## Capture stdout support
|
|
103
|
+
|
|
104
|
+
The module has support for capturing stdout and -later- using showing the captured output on a sheet.
|
|
105
|
+
|
|
106
|
+
To do that:
|
|
107
|
+
|
|
108
|
+
```makes it possible to capture stdout writes, which
|
|
109
|
+
with xwu.capture_stdout():
|
|
110
|
+
...
|
|
111
|
+
```
|
|
112
|
+
and then the captured output can be copied to the screen, like
|
|
113
|
+
|
|
114
|
+
```can then be copied to a worksheet in a later stage.
|
|
115
|
+
sheet.range(4,5).value = xwu.captured_stdout_as_value()
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Clearing the captured stdout buffer can be done with `xwu.clear_captured_std_out`.
|
|
119
|
+
|
|
120
|
+
Normally, stdout will be also sent to the xlwings lite UI panel. This can be suppressed with
|
|
121
|
+
|
|
122
|
+
```
|
|
123
|
+
with xwu.capture_stdout(include_print=False):
|
|
124
|
+
...
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## Badges
|
|
128
|
+
|
|
129
|
+
  
|
|
130
|
+
 
|
|
131
|
+

|
|
132
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
xlwings_utils/__init__.py,sha256=FdaRztevSu5akGL7KBUBRzqwLMRTdvVUuS2Kfp2f1Uc,68
|
|
2
|
+
xlwings_utils/xlwings_utils.py,sha256=gCAgs3x6BjHaCX8I3HVw-s84EIS4pkrYQzCK38yG5T4,12656
|
|
3
|
+
xlwings_utils-0.0.7.dist-info/METADATA,sha256=js1Qw-rZuxDke_i-AjBl8P7mXZ7aMocqlJYj9Gfgyjg,4962
|
|
4
|
+
xlwings_utils-0.0.7.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
|
5
|
+
xlwings_utils-0.0.7.dist-info/top_level.txt,sha256=kf5SEv0gZiRObPhUoYcc1O_iX_wwTOPeUIYvzyYeAM4,14
|
|
6
|
+
xlwings_utils-0.0.7.dist-info/RECORD,,
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: xlwings_utils
|
|
3
|
-
Version: 0.0.6
|
|
4
|
-
Summary: xlwings_utils
|
|
5
|
-
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
|
-
Project-URL: Homepage, https://github.com/salabim/xlwings_utils
|
|
7
|
-
Project-URL: Repository, https://github.com/salabim/xlwings_utils
|
|
8
|
-
Classifier: Development Status :: 5 - Production/Stable
|
|
9
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
-
Requires-Python: >=3.9
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
Requires-Dist: dropbox
|
|
13
|
-
Requires-Dist: ssl
|
|
14
|
-
|
|
15
|
-
<img src="https://www.salabim.org/xlwings_utils_logo1.png">
|
|
16
|
-
|
|
17
|
-
## Introduction
|
|
18
|
-
|
|
19
|
-
This module provides some useful functions to be used in xlwings lite.
|
|
20
|
-
|
|
21
|
-
The xlwings lite system does not provide access to the local file system. With this
|
|
22
|
-
module, files can be copied between dropbox and the local pyodide file systen. And
|
|
23
|
-
therefore, it is possible to indirectly use the local file system.
|
|
24
|
-
|
|
25
|
-
The module contains support for a useful 2 dimensional data structure: block.
|
|
26
|
-
Thjs can be useful to manipulate a range without accessing the range directly,
|
|
27
|
-
which is expensive in terms of memory and execution time.
|
|
28
|
-
|
|
29
|
-
On top of that, this module makes it possible to capture stdout writes, which
|
|
30
|
-
can then be copied to a worksheet in a later stage.
|
|
31
|
-
|
|
32
|
-
## Installation
|
|
33
|
-
|
|
34
|
-
Just add xlwings-utils to the requirement tab. It might be required to add ssl.
|
|
35
|
-
|
|
36
|
-
## Dropbox support
|
|
37
|
-
|
|
38
|
-
xlwings_lite only works with full access dropbox apps.
|
|
39
|
-
|
|
40
|
-
In order to use dropbox functionality, is is necessary to initialize the module with credentials.
|
|
41
|
-
|
|
42
|
-
```xwu.dropbox_init()```
|
|
43
|
-
If called without parameters, the refresh_token is
|
|
44
|
-
|
|
45
|
-
## Capture stdout support
|
|
46
|
-
|
|
47
|
-
Badges
|
|
48
|
-
|
|
49
|
-
  
|
|
50
|
-
 
|
|
51
|
-

|
|
52
|
-
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
xlwings_utils/__init__.py,sha256=FdaRztevSu5akGL7KBUBRzqwLMRTdvVUuS2Kfp2f1Uc,68
|
|
2
|
-
xlwings_utils/xlwings_utils.py,sha256=yvWW2yRjkHvF5814ptlbGxT5tpRRg-wH1yCDO-5qIe8,12866
|
|
3
|
-
xlwings_utils-0.0.6.dist-info/METADATA,sha256=0fJEsPdOJ1uoHQnAeGzB5dPm-qKD9F_1CGfP9h1Oc4s,2083
|
|
4
|
-
xlwings_utils-0.0.6.dist-info/WHEEL,sha256=0CuiUZ_p9E4cD6NyLD6UG80LBXYyiSYZOKDm5lp32xk,91
|
|
5
|
-
xlwings_utils-0.0.6.dist-info/top_level.txt,sha256=kf5SEv0gZiRObPhUoYcc1O_iX_wwTOPeUIYvzyYeAM4,14
|
|
6
|
-
xlwings_utils-0.0.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|