xlwings-utils 25.0.6__tar.gz → 25.0.6.post1__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.

Potentially problematic release.


This version of xlwings-utils might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xlwings_utils
3
- Version: 25.0.6
3
+ Version: 25.0.6.post1
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
@@ -62,7 +62,7 @@ python -c "exec(__import__('requests').get('https://salabim.org/dropbox setup.py
62
62
  Then, it is possible to list all files in a specified folder using the list_dropbox function.
63
63
  It is also possible to get the folders and to access all underlying folders.
64
64
 
65
- The `read_dropbox` function can be used to read the contents (bytes) of a Dropbox file. As reading from Dropbox under pyodide is very unreliable, xlwings_utils automatically retries several times (by default 100 times). The actual number of retries can be found with `read_dropbox.retries`.
65
+ The `read_dropbox` function can be used to read the contents (bytes) of a Dropbox file. As reading from Dropbox under pyodide is rather unreliable, xlwings_utils automatically retries several times (by default 100 times). The actual number of retries can be found with `read_dropbox.retries`.
66
66
 
67
67
  The function `write_dropbox` can be used to write contents (bytes) to a Dropbox file.
68
68
 
@@ -269,11 +269,11 @@ Currently, *xlwings Lite* does not provide access to the local file system. Ther
269
269
  Files can be encoded into a block, like:
270
270
 
271
271
  ```
272
- bl = xwu.block.encode_files("film1.mp4", "settings.txt")
273
- book.sheets["VBA"].range((10,2)).value=bl.value
272
+ bl = xwu.block.encode_file("film1.mp4")
273
+ book.sheets["VBA"].range((10,1)).value=bl.value
274
274
  ```
275
275
 
276
- With this code, column B will be filled with encoded copies of the files *film1.mp4* and *settings.txt* . This can then be used with a suitable VBA macro to decode to the real file system. A VBA macro can be triggered with `xwu.trigger_macro()`. This requires an Excel worksheet where cell A1 is reserved for communication with xlwings lite. This worksheet needs to contain a macro, like
276
+ With this code, column A will be filled with an encoded copy of the files *film1.mp4* . This can then be used with a suitable VBA macro to decode to the real file system. A VBA macro can be triggered with `xwu.trigger_macro()`. This requires an Excel worksheet where cell A1 is reserved for communication with xlwings lite. This worksheet needs to contain a macro, like
277
277
 
278
278
  ```
279
279
  Private Sub Worksheet_Calculate()
@@ -284,66 +284,34 @@ Private Sub Worksheet_Calculate()
284
284
  End Sub
285
285
  ```
286
286
 
287
- , where `MacroToExecute` should contain the user code, most likely code to decode files encoded with something like
287
+ , where `MacroToExecute` should contain the user code, most likely code to decode file(s) encoded.
288
+
289
+ The repo contains a VBA module called xlwings_utils.bas with code to decode encoded files.
290
+ Just add the .bas file to a worksheet and call like
288
291
 
289
292
  ```
290
- bl.decode_to_files()
293
+ Sub MacroToExecute()
294
+ DecodeFile(Me, 10, 1)
291
295
  ```
296
+
297
+ In this example, the file *film1.mp4* will be downloaded into the current directory.
292
298
 
293
- The VBA code below can be used to decode encoded file(s ) on a worksheet.
299
+ The module xlwings_utils also contains code to encode a local file to a sheet:
294
300
 
295
301
  ```
296
- Sub DecodeFiles()
297
-
298
- Dim vArr() As Byte
299
- Dim S As String
300
- Dim Column As Integer
301
- Dim Row As Integer
302
- Dim ws As Worksheet
303
- Dim Count As Integer
304
- Dim FileNames As String
305
-
306
- Column = 2
307
- Row = 1
308
-
309
- ThisDir = ThisWorkbook.Path
310
- Set ws = Me
311
- Count = 0
312
- While Row < 30000
313
- Line = ws.Cells(Row, Column)
314
- If InStr(Line, "<file=") = 1 And Right(Line, 1) = ">" Then
315
- If Count <> 0 Then
316
- FileNames = FileNames & ", "
317
- End If
318
- Count = Count + 1
319
- FileNameOnly = Mid(Line, 7, Len(Line) - 7)
320
- Filename = ThisDir & "/" & FileNameOnly
321
- FileNames = FileNames & FileNameOnly
322
-
323
- Row = Row + 1
324
- S = ""
325
- While ws.Cells(Row, Column) <> "</file>"
326
- S = S & ws.Cells(Row, Column)
327
- Row = Row + 1
328
- Wend
329
-
330
- vArr = Base64ToArray(S)
331
-
332
- Open Filename For Binary Access Write As #1
333
- WritePos = 1
334
- Put #1, WritePos, vArr
335
- Close #1
336
- End If
337
-
338
- Row = Row + 1
339
-
340
- Wend
341
-
342
- If Count = 0 Then
343
- MsgBox "No files to decode"
344
- Else
345
- MsgBox "Successfully decoded and written " & Str(Count) & " file(s): " & FileNames
346
- End If
302
+ Sub MacroToExecute()
303
+ EncodeFile(Me, "data.json", 10, 1)
304
+ ```
305
+
306
+ This will place an encoded version of *data.json* on the sheet.
307
+
308
+ Then, the file can be copied to the pyodide file system with
309
+
310
+ ```
311
+ bl = block(xw.range((10,1),(50000,1)).decode_to_files())
312
+ ```
313
+ ```
314
+
347
315
  ```
348
316
 
349
317
  ## Contact info
@@ -49,7 +49,7 @@ python -c "exec(__import__('requests').get('https://salabim.org/dropbox setup.py
49
49
  Then, it is possible to list all files in a specified folder using the list_dropbox function.
50
50
  It is also possible to get the folders and to access all underlying folders.
51
51
 
52
- The `read_dropbox` function can be used to read the contents (bytes) of a Dropbox file. As reading from Dropbox under pyodide is very unreliable, xlwings_utils automatically retries several times (by default 100 times). The actual number of retries can be found with `read_dropbox.retries`.
52
+ The `read_dropbox` function can be used to read the contents (bytes) of a Dropbox file. As reading from Dropbox under pyodide is rather unreliable, xlwings_utils automatically retries several times (by default 100 times). The actual number of retries can be found with `read_dropbox.retries`.
53
53
 
54
54
  The function `write_dropbox` can be used to write contents (bytes) to a Dropbox file.
55
55
 
@@ -256,11 +256,11 @@ Currently, *xlwings Lite* does not provide access to the local file system. Ther
256
256
  Files can be encoded into a block, like:
257
257
 
258
258
  ```
259
- bl = xwu.block.encode_files("film1.mp4", "settings.txt")
260
- book.sheets["VBA"].range((10,2)).value=bl.value
259
+ bl = xwu.block.encode_file("film1.mp4")
260
+ book.sheets["VBA"].range((10,1)).value=bl.value
261
261
  ```
262
262
 
263
- With this code, column B will be filled with encoded copies of the files *film1.mp4* and *settings.txt* . This can then be used with a suitable VBA macro to decode to the real file system. A VBA macro can be triggered with `xwu.trigger_macro()`. This requires an Excel worksheet where cell A1 is reserved for communication with xlwings lite. This worksheet needs to contain a macro, like
263
+ With this code, column A will be filled with an encoded copy of the files *film1.mp4* . This can then be used with a suitable VBA macro to decode to the real file system. A VBA macro can be triggered with `xwu.trigger_macro()`. This requires an Excel worksheet where cell A1 is reserved for communication with xlwings lite. This worksheet needs to contain a macro, like
264
264
 
265
265
  ```
266
266
  Private Sub Worksheet_Calculate()
@@ -271,66 +271,34 @@ Private Sub Worksheet_Calculate()
271
271
  End Sub
272
272
  ```
273
273
 
274
- , where `MacroToExecute` should contain the user code, most likely code to decode files encoded with something like
274
+ , where `MacroToExecute` should contain the user code, most likely code to decode file(s) encoded.
275
+
276
+ The repo contains a VBA module called xlwings_utils.bas with code to decode encoded files.
277
+ Just add the .bas file to a worksheet and call like
275
278
 
276
279
  ```
277
- bl.decode_to_files()
280
+ Sub MacroToExecute()
281
+ DecodeFile(Me, 10, 1)
278
282
  ```
283
+
284
+ In this example, the file *film1.mp4* will be downloaded into the current directory.
279
285
 
280
- The VBA code below can be used to decode encoded file(s ) on a worksheet.
286
+ The module xlwings_utils also contains code to encode a local file to a sheet:
281
287
 
282
288
  ```
283
- Sub DecodeFiles()
284
-
285
- Dim vArr() As Byte
286
- Dim S As String
287
- Dim Column As Integer
288
- Dim Row As Integer
289
- Dim ws As Worksheet
290
- Dim Count As Integer
291
- Dim FileNames As String
292
-
293
- Column = 2
294
- Row = 1
295
-
296
- ThisDir = ThisWorkbook.Path
297
- Set ws = Me
298
- Count = 0
299
- While Row < 30000
300
- Line = ws.Cells(Row, Column)
301
- If InStr(Line, "<file=") = 1 And Right(Line, 1) = ">" Then
302
- If Count <> 0 Then
303
- FileNames = FileNames & ", "
304
- End If
305
- Count = Count + 1
306
- FileNameOnly = Mid(Line, 7, Len(Line) - 7)
307
- Filename = ThisDir & "/" & FileNameOnly
308
- FileNames = FileNames & FileNameOnly
309
-
310
- Row = Row + 1
311
- S = ""
312
- While ws.Cells(Row, Column) <> "</file>"
313
- S = S & ws.Cells(Row, Column)
314
- Row = Row + 1
315
- Wend
316
-
317
- vArr = Base64ToArray(S)
318
-
319
- Open Filename For Binary Access Write As #1
320
- WritePos = 1
321
- Put #1, WritePos, vArr
322
- Close #1
323
- End If
324
-
325
- Row = Row + 1
326
-
327
- Wend
328
-
329
- If Count = 0 Then
330
- MsgBox "No files to decode"
331
- Else
332
- MsgBox "Successfully decoded and written " & Str(Count) & " file(s): " & FileNames
333
- End If
289
+ Sub MacroToExecute()
290
+ EncodeFile(Me, "data.json", 10, 1)
291
+ ```
292
+
293
+ This will place an encoded version of *data.json* on the sheet.
294
+
295
+ Then, the file can be copied to the pyodide file system with
296
+
297
+ ```
298
+ bl = block(xw.range((10,1),(50000,1)).decode_to_files())
299
+ ```
300
+ ```
301
+
334
302
  ```
335
303
 
336
304
  ## Contact info
@@ -10,7 +10,7 @@ authors = [
10
10
  { name = "Ruud van der Ham", email = "rt.van.der.ham@gmail.com" },
11
11
  ]
12
12
  description = "xlwings_utils"
13
- version = "25.0.6"
13
+ version = "25.0.6.post1"
14
14
  readme = "README.md"
15
15
  requires-python = ">=3.9"
16
16
  dependencies = [
@@ -179,24 +179,24 @@ def read_dropbox(dropbox_path, max_retries=100):
179
179
  it is not necessary to call dropbox_init() prior to any dropbox function.
180
180
 
181
181
  As reading from dropbox is very unreliable under pyodide, reading will have to be retried (by default maximum 100 times).
182
- The number of retries can be found with read_dropbox.retries
182
+ The number of retries can be found with read_dropbox.retries.
183
183
  """
184
184
 
185
185
  _login_dbx()
186
- for read_dropbox.retries in range(max_retries+1):
186
+ for read_dropbox.retries in range(max_retries + 1):
187
187
  metadata, response = dbx.files_download(dropbox_path)
188
188
  file_content = response.content
189
189
  if len(file_content) == metadata.size:
190
190
  return file_content
191
191
  raise OSError(f"after {max_retries} still no valid response")
192
192
 
193
+
193
194
  def write_dropbox(dropbox_path, contents):
194
- _login_dbx()
195
195
  """
196
196
  write_dropbox
197
-
197
+
198
198
  write from dopbox at given path
199
-
199
+
200
200
  Parameters
201
201
  ----------
202
202
  dropbox_path : str or Pathlib.Path
@@ -204,12 +204,13 @@ def write_dropbox(dropbox_path, contents):
204
204
 
205
205
  contents : bytes
206
206
  contents to be written
207
-
207
+
208
208
  Note
209
209
  ----
210
210
  If REFRESH_TOKEN, APP_KEY and APP_SECRET environment variables are specified,
211
211
  it is not necessary to call dropbox_init() prior to any dropbox function.
212
212
  """
213
+ _login_dbx()
213
214
  dbx.files_upload(contents, dropbox_path, mode=dropbox.files.WriteMode.overwrite)
214
215
 
215
216
 
@@ -433,6 +434,19 @@ class block:
433
434
  if column > self.number_of_columns:
434
435
  raise ValueError(f"{name}={column} > number_of_columns={self.number_of_columns}")
435
436
 
437
+ def transpose(self):
438
+ """
439
+ transpose block
440
+
441
+ Returns
442
+ -------
443
+ transposed block : block
444
+ """
445
+ bl = block(number_of_rows=self.number_of_columns, number_of_columns=self.number_of_rows)
446
+ for (row, column), value in self.dict.items():
447
+ bl[column, row] = value
448
+ return bl
449
+
436
450
  def vlookup(self, s, *, row_from=1, row_to=missing, column1=1, column2=missing, default=missing):
437
451
  """
438
452
  searches in column1 for row between row_from and row_to for s and returns the value found at (that row, column2)
@@ -685,57 +699,57 @@ class block:
685
699
 
686
700
  def decode_to_files(self):
687
701
  """
688
- decode the block with encoded file(s) to individual local files
702
+ decode the block with encoded file(s) to individual pyoidide files
689
703
  """
704
+ count = 0
690
705
  for column in self.number_of_columns:
691
706
  row = 1
707
+ bl = self.mimimized()
692
708
  while row <= self.number_of_rows:
693
709
  if self[row, column] and self[row, column].startswith("<file=") and self[row, column].endswith(">"):
694
710
  filename = self[row, column][6:-1]
695
711
  collect = []
696
712
  row += 1
697
- while self[row, column] != "</file>":
698
- print(f"{self[row,column]=}")
699
-
700
- if self[row, column]:
701
- collect.append(self[row, column])
713
+ while bl[row, column] != "</file>":
714
+ if bl[row, column]:
715
+ collect.append(bl[row, column])
702
716
  row += 1
703
717
  decoded = base64.b64decode("".join(collect))
704
718
  open(filename, "wb").write(decoded)
719
+ count += 1
705
720
  row += 1
721
+ return count
706
722
 
707
723
  @classmethod
708
- def encode_files(cls, *files):
724
+ def encode_file(cls, file):
709
725
  """
710
- make a block with the given files encoded
726
+ make a block with the given pyodide file encoded
711
727
 
712
728
  Parameters
713
729
  ----------
714
- files : file names (str)
715
- files to be encoded
730
+ file : file name (str)
731
+ file to be encoded
716
732
 
717
733
  Returns
718
734
  -------
719
- block with encoded files : block
720
- not minimized!
735
+ block with encoded file : block (minimized)
721
736
  """
722
737
 
723
- bl = cls(number_of_rows=50000, number_of_columns=1)
738
+ bl = cls(number_of_rows=100000, number_of_columns=1)
724
739
 
725
740
  n = 5000 # block size
726
741
  row = 1
727
- for file in files:
728
- bl[row, 1] = f"<file={file}>"
742
+ bl[row, 1] = f"<file={file}>"
743
+ row += 1
744
+ b64 = base64.b64encode(open(file, "rb").read()).decode("utf-8")
745
+ while b64:
746
+ b64_n = b64[:n]
747
+ bl[row, 1] = b64_n
729
748
  row += 1
730
- b64 = base64.b64encode(open(file, "rb").read()).decode("utf-8")
731
- while b64:
732
- b64_n = b64[:n]
733
- bl[row, 1] = b64_n
734
- row += 1
735
- b64 = b64[n:]
736
- bl[row, 1] = f"</file>"
737
- row += 1
738
- return bl
749
+ b64 = b64[n:]
750
+ bl[row, 1] = f"</file>"
751
+ row += 1
752
+ return bl.minimized()
739
753
 
740
754
 
741
755
  class Capture:
@@ -844,6 +858,7 @@ class Capture:
844
858
  def include_print(self, value):
845
859
  self._include_print = value
846
860
 
861
+
847
862
  def trigger_macro(sheet):
848
863
  """
849
864
  triggers the macro on sheet
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: xlwings_utils
3
- Version: 25.0.6
3
+ Version: 25.0.6.post1
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
@@ -62,7 +62,7 @@ python -c "exec(__import__('requests').get('https://salabim.org/dropbox setup.py
62
62
  Then, it is possible to list all files in a specified folder using the list_dropbox function.
63
63
  It is also possible to get the folders and to access all underlying folders.
64
64
 
65
- The `read_dropbox` function can be used to read the contents (bytes) of a Dropbox file. As reading from Dropbox under pyodide is very unreliable, xlwings_utils automatically retries several times (by default 100 times). The actual number of retries can be found with `read_dropbox.retries`.
65
+ The `read_dropbox` function can be used to read the contents (bytes) of a Dropbox file. As reading from Dropbox under pyodide is rather unreliable, xlwings_utils automatically retries several times (by default 100 times). The actual number of retries can be found with `read_dropbox.retries`.
66
66
 
67
67
  The function `write_dropbox` can be used to write contents (bytes) to a Dropbox file.
68
68
 
@@ -269,11 +269,11 @@ Currently, *xlwings Lite* does not provide access to the local file system. Ther
269
269
  Files can be encoded into a block, like:
270
270
 
271
271
  ```
272
- bl = xwu.block.encode_files("film1.mp4", "settings.txt")
273
- book.sheets["VBA"].range((10,2)).value=bl.value
272
+ bl = xwu.block.encode_file("film1.mp4")
273
+ book.sheets["VBA"].range((10,1)).value=bl.value
274
274
  ```
275
275
 
276
- With this code, column B will be filled with encoded copies of the files *film1.mp4* and *settings.txt* . This can then be used with a suitable VBA macro to decode to the real file system. A VBA macro can be triggered with `xwu.trigger_macro()`. This requires an Excel worksheet where cell A1 is reserved for communication with xlwings lite. This worksheet needs to contain a macro, like
276
+ With this code, column A will be filled with an encoded copy of the files *film1.mp4* . This can then be used with a suitable VBA macro to decode to the real file system. A VBA macro can be triggered with `xwu.trigger_macro()`. This requires an Excel worksheet where cell A1 is reserved for communication with xlwings lite. This worksheet needs to contain a macro, like
277
277
 
278
278
  ```
279
279
  Private Sub Worksheet_Calculate()
@@ -284,66 +284,34 @@ Private Sub Worksheet_Calculate()
284
284
  End Sub
285
285
  ```
286
286
 
287
- , where `MacroToExecute` should contain the user code, most likely code to decode files encoded with something like
287
+ , where `MacroToExecute` should contain the user code, most likely code to decode file(s) encoded.
288
+
289
+ The repo contains a VBA module called xlwings_utils.bas with code to decode encoded files.
290
+ Just add the .bas file to a worksheet and call like
288
291
 
289
292
  ```
290
- bl.decode_to_files()
293
+ Sub MacroToExecute()
294
+ DecodeFile(Me, 10, 1)
291
295
  ```
296
+
297
+ In this example, the file *film1.mp4* will be downloaded into the current directory.
292
298
 
293
- The VBA code below can be used to decode encoded file(s ) on a worksheet.
299
+ The module xlwings_utils also contains code to encode a local file to a sheet:
294
300
 
295
301
  ```
296
- Sub DecodeFiles()
297
-
298
- Dim vArr() As Byte
299
- Dim S As String
300
- Dim Column As Integer
301
- Dim Row As Integer
302
- Dim ws As Worksheet
303
- Dim Count As Integer
304
- Dim FileNames As String
305
-
306
- Column = 2
307
- Row = 1
308
-
309
- ThisDir = ThisWorkbook.Path
310
- Set ws = Me
311
- Count = 0
312
- While Row < 30000
313
- Line = ws.Cells(Row, Column)
314
- If InStr(Line, "<file=") = 1 And Right(Line, 1) = ">" Then
315
- If Count <> 0 Then
316
- FileNames = FileNames & ", "
317
- End If
318
- Count = Count + 1
319
- FileNameOnly = Mid(Line, 7, Len(Line) - 7)
320
- Filename = ThisDir & "/" & FileNameOnly
321
- FileNames = FileNames & FileNameOnly
322
-
323
- Row = Row + 1
324
- S = ""
325
- While ws.Cells(Row, Column) <> "</file>"
326
- S = S & ws.Cells(Row, Column)
327
- Row = Row + 1
328
- Wend
329
-
330
- vArr = Base64ToArray(S)
331
-
332
- Open Filename For Binary Access Write As #1
333
- WritePos = 1
334
- Put #1, WritePos, vArr
335
- Close #1
336
- End If
337
-
338
- Row = Row + 1
339
-
340
- Wend
341
-
342
- If Count = 0 Then
343
- MsgBox "No files to decode"
344
- Else
345
- MsgBox "Successfully decoded and written " & Str(Count) & " file(s): " & FileNames
346
- End If
302
+ Sub MacroToExecute()
303
+ EncodeFile(Me, "data.json", 10, 1)
304
+ ```
305
+
306
+ This will place an encoded version of *data.json* on the sheet.
307
+
308
+ Then, the file can be copied to the pyodide file system with
309
+
310
+ ```
311
+ bl = block(xw.range((10,1),(50000,1)).decode_to_files())
312
+ ```
313
+ ```
314
+
347
315
  ```
348
316
 
349
317
  ## Contact info