xlwings-utils 25.0.3.post3__py3-none-any.whl → 25.0.5__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 +66 -1
- {xlwings_utils-25.0.3.post3.dist-info → xlwings_utils-25.0.5.dist-info}/METADATA +14 -10
- xlwings_utils-25.0.5.dist-info/RECORD +6 -0
- xlwings_utils-25.0.3.post3.dist-info/RECORD +0 -6
- {xlwings_utils-25.0.3.post3.dist-info → xlwings_utils-25.0.5.dist-info}/WHEEL +0 -0
- {xlwings_utils-25.0.3.post3.dist-info → xlwings_utils-25.0.5.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__ = "25.0.
|
|
8
|
+
__version__ = "25.0.5"
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
import dropbox
|
|
@@ -13,6 +13,7 @@ from pathlib import Path
|
|
|
13
13
|
import os
|
|
14
14
|
import sys
|
|
15
15
|
import math
|
|
16
|
+
import base64
|
|
16
17
|
|
|
17
18
|
dbx = None
|
|
18
19
|
Pythonista = sys.platform == "ios"
|
|
@@ -786,5 +787,69 @@ class Capture:
|
|
|
786
787
|
self._include_print = value
|
|
787
788
|
|
|
788
789
|
|
|
790
|
+
def trigger_VBA(book):
|
|
791
|
+
"""
|
|
792
|
+
triggers the macro on sheet VBA in book
|
|
793
|
+
|
|
794
|
+
Parameters
|
|
795
|
+
----------
|
|
796
|
+
book : xw.Book
|
|
797
|
+
book to use
|
|
798
|
+
"""
|
|
799
|
+
|
|
800
|
+
book.sheets["VBA"]["A1"].value = "=NOW()"
|
|
801
|
+
|
|
802
|
+
|
|
803
|
+
def init_transfer_files(book):
|
|
804
|
+
"""
|
|
805
|
+
initializes the file info on sheet VBA in book
|
|
806
|
+
|
|
807
|
+
should be called prior to calling any transfer_file()
|
|
808
|
+
|
|
809
|
+
Parameters
|
|
810
|
+
----------
|
|
811
|
+
book : xw.Book
|
|
812
|
+
book to use
|
|
813
|
+
"""
|
|
814
|
+
|
|
815
|
+
global row1
|
|
816
|
+
book.sheets["VBA"].range((10, 1), (1000000, 1)).clear()
|
|
817
|
+
row1 = 10
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
def transfer_file(book, file):
|
|
821
|
+
"""
|
|
822
|
+
makes the local file to be encoded on sheet VBA in book
|
|
823
|
+
to be triggered later
|
|
824
|
+
|
|
825
|
+
init_transfer_files should be called prior to any transfer_file()
|
|
826
|
+
|
|
827
|
+
Parameters
|
|
828
|
+
----------
|
|
829
|
+
book : xw.Book
|
|
830
|
+
book to use
|
|
831
|
+
|
|
832
|
+
file : string
|
|
833
|
+
name of file to be encoded
|
|
834
|
+
"""
|
|
835
|
+
|
|
836
|
+
global row1
|
|
837
|
+
ws = book.sheets("VBA")
|
|
838
|
+
ws_block = block(number_of_rows=50000, number_of_columns=1)
|
|
839
|
+
n = 5000 # block size
|
|
840
|
+
row = 1
|
|
841
|
+
ws_block[row, 1] = f"<file={file}>"
|
|
842
|
+
row += 1
|
|
843
|
+
b64 = base64.b64encode(open(file, "rb").read()).decode("utf-8")
|
|
844
|
+
while b64:
|
|
845
|
+
b64_n = b64[:n]
|
|
846
|
+
ws_block[row, 1] = b64_n
|
|
847
|
+
row += 1
|
|
848
|
+
b64 = b64[n:]
|
|
849
|
+
ws_block[row, 1] = f"</file>"
|
|
850
|
+
ws.range((row1, 1)).value = ws_block.minimized().value
|
|
851
|
+
row1 += ws_block.highest_used_row_number
|
|
852
|
+
|
|
853
|
+
|
|
789
854
|
if __name__ == "__main__":
|
|
790
855
|
...
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: xlwings_utils
|
|
3
|
-
Version: 25.0.
|
|
3
|
+
Version: 25.0.5
|
|
4
4
|
Summary: xlwings_utils
|
|
5
5
|
Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/salabim/xlwings_utils
|
|
@@ -19,12 +19,16 @@ This module provides some useful functions to be used in xlwings (lite).
|
|
|
19
19
|
|
|
20
20
|
## Installation
|
|
21
21
|
|
|
22
|
-
Just add xlwings-utils to the *requirements.txt* tab.
|
|
22
|
+
Just add `xlwings-utils` and `ssl` (even if `dropbox` is not used) to the *requirements.txt* tab.
|
|
23
23
|
|
|
24
24
|
In the script, add
|
|
25
25
|
|
|
26
26
|
```ìmport xlwings_utils as xwu```
|
|
27
27
|
|
|
28
|
+
For *regular* installations, use
|
|
29
|
+
|
|
30
|
+
```pip install xlwings_utils```
|
|
31
|
+
|
|
28
32
|
> [!NOTE]
|
|
29
33
|
>
|
|
30
34
|
> The GitHub repository can be found on https://github.com/salabim/xlwings_utils .
|
|
@@ -45,7 +49,7 @@ If an application runs under xlwings, `xwu.xlwings` will be True. False, if not.
|
|
|
45
49
|
|
|
46
50
|
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.
|
|
47
51
|
|
|
48
|
-
|
|
52
|
+
Currently, it is only possible to use full-access Dropbox apps.
|
|
49
53
|
|
|
50
54
|
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. Instructions on how to get these variables can be found here.
|
|
51
55
|
|
|
@@ -82,7 +86,7 @@ xwu.write_dropbox('/downloads/file1.gif')
|
|
|
82
86
|
## Block support
|
|
83
87
|
|
|
84
88
|
The module contains a useful 2-dimensional data structure: *block*.
|
|
85
|
-
This can be useful
|
|
89
|
+
This can be useful for manipulating a range without accessing it directly, which is expensive in terms of memory and execution time.
|
|
86
90
|
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.
|
|
87
91
|
So, `my_block(lol)[row, col]` is roughly equivalent to `lol[row-1][col-1]`
|
|
88
92
|
|
|
@@ -132,7 +136,7 @@ for row in range(1, 10001):
|
|
|
132
136
|
this_block[row,2]= ...
|
|
133
137
|
if ...: # end condition
|
|
134
138
|
break
|
|
135
|
-
sheet.range(10,1).value = this_block.minimized().value
|
|
139
|
+
sheet.range((10,1)).value = this_block.minimized().value
|
|
136
140
|
```
|
|
137
141
|
|
|
138
142
|
In this case, only the really processed rows are copied to the sheet.
|
|
@@ -191,11 +195,11 @@ We then read the following rows (using hlookups) and access the required values.
|
|
|
191
195
|
|
|
192
196
|
### Filling a block from other sources
|
|
193
197
|
|
|
194
|
-
The advantage of using a block instead of accessing these sources is
|
|
198
|
+
The advantage of using a block instead of accessing these sources is that they are one-based, just like in Excel.
|
|
195
199
|
|
|
196
200
|
It is possible to make a block from an xlrd worksheet with `block.from_xlrd_sheet`.
|
|
197
201
|
|
|
198
|
-
It is possible to
|
|
202
|
+
It is possible to create a block from a Pandas DataFrame using `block.from_dataframe`. Ensure that, if the dataframe is created by reading from an Excel sheet, headers=None is specified, e.g., `df = pd.read_excel(filename, header=None)`.
|
|
199
203
|
|
|
200
204
|
It is possible to make a block from an openpyxl worksheet with `block.from_openpyxl_sheet`.
|
|
201
205
|
|
|
@@ -231,9 +235,9 @@ capture = xwu.Capture(include_print=True)
|
|
|
231
235
|
|
|
232
236
|
the stdout output is captured and printed.
|
|
233
237
|
|
|
234
|
-
Capturing
|
|
238
|
+
Capturing can be enabled and disabled at any time with `capture.enabled = True` and `capture.enabled = False`.
|
|
235
239
|
|
|
236
|
-
And
|
|
240
|
+
And include print, likewise, with `capture.include_print`.
|
|
237
241
|
|
|
238
242
|
Alternatively, a context manager is provided:
|
|
239
243
|
|
|
@@ -246,7 +250,7 @@ with capture:
|
|
|
246
250
|
```
|
|
247
251
|
Note that stopping the capture, leaves the captured output in place, so it can be extended later.
|
|
248
252
|
|
|
249
|
-
In either case, the captured output can be
|
|
253
|
+
In either case, the captured output can then be copied to a sheet, like
|
|
250
254
|
|
|
251
255
|
```
|
|
252
256
|
sheet.range(4,5).value = capture.value
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
xlwings_utils/__init__.py,sha256=FdaRztevSu5akGL7KBUBRzqwLMRTdvVUuS2Kfp2f1Uc,68
|
|
2
|
+
xlwings_utils/xlwings_utils.py,sha256=LT2NxlvS0T9wY4Qi9UiINpS1S1nmM2IutoBgkWk3JDo,24760
|
|
3
|
+
xlwings_utils-25.0.5.dist-info/METADATA,sha256=MBHmRPFi-ytcOioOS2oII7pWN9e6SyOXHV_M3CVSJBs,10317
|
|
4
|
+
xlwings_utils-25.0.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
5
|
+
xlwings_utils-25.0.5.dist-info/top_level.txt,sha256=kf5SEv0gZiRObPhUoYcc1O_iX_wwTOPeUIYvzyYeAM4,14
|
|
6
|
+
xlwings_utils-25.0.5.dist-info/RECORD,,
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
xlwings_utils/__init__.py,sha256=FdaRztevSu5akGL7KBUBRzqwLMRTdvVUuS2Kfp2f1Uc,68
|
|
2
|
-
xlwings_utils/xlwings_utils.py,sha256=dAtu5fjRbzgL-Bc5OlGMdb9PLucwZMgOe_knMYZqWS8,23376
|
|
3
|
-
xlwings_utils-25.0.3.post3.dist-info/METADATA,sha256=dPs6Y0w9oRqKxhSAXlJGx7GXl8vjzMrqn3ezXmSrLGM,10209
|
|
4
|
-
xlwings_utils-25.0.3.post3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
5
|
-
xlwings_utils-25.0.3.post3.dist-info/top_level.txt,sha256=kf5SEv0gZiRObPhUoYcc1O_iX_wwTOPeUIYvzyYeAM4,14
|
|
6
|
-
xlwings_utils-25.0.3.post3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|