xlwings-utils 25.0.5__tar.gz → 25.0.6__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.5
3
+ Version: 25.0.6
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,8 +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. If the file is not read correctly, which seems
66
- to happen rather frequently, an OSError exception is raised.
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`.
67
66
 
68
67
  The function `write_dropbox` can be used to write contents (bytes) to a Dropbox file.
69
68
 
@@ -263,10 +262,93 @@ The capture buffer can also be retrieved as a string with `capture.str` and `cap
263
262
 
264
263
  Clearing the captured stdout buffer can be done at any time with `capture.clear()`.
265
264
 
265
+ ## Functionality for accessing local files via VBA
266
+
267
+ Currently, *xlwings Lite* does not provide access to the local file system. Therefore, xlwings_utils offers some functionality to trigger a VBA script as well as functionality to encode a file in the pyodide file system to a VBA sheet and to trigger writing the encoded file(s) to the local file system.
268
+
269
+ Files can be encoded into a block, like:
270
+
271
+ ```
272
+ bl = xwu.block.encode_files("film1.mp4", "settings.txt")
273
+ book.sheets["VBA"].range((10,2)).value=bl.value
274
+ ```
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
277
+
278
+ ```
279
+ Private Sub Worksheet_Calculate()
280
+ If Me.Range("A1").Formula = "=NOW()" Then
281
+ Me.Range("A1").Value = Null
282
+ Call MacroToExecute
283
+ End If
284
+ End Sub
285
+ ```
286
+
287
+ , where `MacroToExecute` should contain the user code, most likely code to decode files encoded with something like
288
+
289
+ ```
290
+ bl.decode_to_files()
291
+ ```
292
+
293
+ The VBA code below can be used to decode encoded file(s ) on a worksheet.
294
+
295
+ ```
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
347
+ ```
266
348
 
267
349
  ## Contact info
268
350
 
269
- You can contact Ruud van der Ham, the core developer, via ruud@salabim.org .
351
+ You can contact Ruud van der Ham, the core developer, at ruud@salabim.org.
270
352
 
271
353
  ## Badges
272
354