@@ -139,10 +139,20 @@ Sub ImportPythonUDFs(control As IRibbonControl)
139
139
140
140
f.Write ftype + " " + fname + "("
141
141
first = True
142
+ vararg = ""
143
+ nArgs = Py.Len(Py.GetItem(xlfunc, "args" ))
142
144
For Each arg In Py.GetItem(xlfunc, "args" )
143
145
If Not Py.Bool(Py.GetItem(arg, "vba" )) Then
146
+ argname = Py.Str(Py.GetItem(arg, "name" ))
144
147
If Not first Then f.Write ", "
145
- f.Write Py.Str(Py.GetItem(arg, "name" ))
148
+ If Py.Bool(Py.GetItem(arg, "vararg" )) Then
149
+ f.Write "ParamArray "
150
+ vararg = argname
151
+ End If
152
+ f.Write argname
153
+ If Py.Bool(Py.GetItem(arg, "vararg" )) Then
154
+ f.Write "()"
155
+ End If
146
156
first = False
147
157
End If
148
158
Next arg
@@ -151,9 +161,17 @@ Sub ImportPythonUDFs(control As IRibbonControl)
151
161
f.WriteLine sTab + "If TypeOf Application.Caller Is Range Then On Error GoTo failed"
152
162
End If
153
163
164
+ If vararg <> "" Then
165
+ f.WriteLine sTab + "ReDim argsArray(1 to UBound(" + vararg + ") - LBound(" + vararg + ") + " + CStr(nArgs) + ")"
166
+ End If
167
+ j = 1
154
168
For Each arg In Py.GetItem(xlfunc, "args" )
155
169
If Not Py.Bool(Py.GetItem(arg, "vba" )) Then
156
170
argname = Py.Str(Py.GetItem(arg, "name" ))
171
+ If Py.Bool(Py.GetItem(arg, "vararg" )) Then
172
+ f.WriteLine sTab + "For k = lbound(" + vararg + ") to ubound(" + vararg + ")"
173
+ argname = vararg + "(k)"
174
+ End If
157
175
If Not Py.Var(Py.GetItem(arg, "range" )) Then
158
176
f.WriteLine sTab + "If TypeOf " + argname + " Is Range Then " + argname + " = " + argname + ".Value2"
159
177
End If
@@ -176,21 +194,34 @@ Sub ImportPythonUDFs(control As IRibbonControl)
176
194
End If
177
195
f.WriteLine sTab + "End If"
178
196
End If
197
+ If Py.Bool(Py.GetItem(arg, "vararg" )) Then
198
+ f.WriteLine sTab + "argsArray(" + CStr(j) + " + k - LBound(" + vararg + ")) = " + argname
199
+ f.WriteLine sTab + "Next k"
200
+ Else
201
+ If vararg <> "" Then
202
+ f.WriteLine sTab + "argsArray(" + CStr(j) + ") = " + argname
203
+ j = j + 1
204
+ End If
205
+ End If
179
206
End If
180
207
Next arg
181
208
182
- f.Write sTab + "Set args = Py.Tuple("
183
- first = True
184
- For Each arg In Py.GetItem(xlfunc, "args" )
185
- If Not first Then f.Write ", "
186
- If Not Py.Bool(Py.GetItem(arg, "vba" )) Then
187
- f.Write Py.Str(Py.GetItem(arg, "name" ))
188
- Else
189
- f.Write Py.Str(Py.GetItem(arg, "vba" ))
190
- End If
191
- first = False
192
- Next arg
193
- f.WriteLine ")"
209
+ If vararg <> "" Then
210
+ f.WriteLine sTab + "Set args = Py.TupleFromArray(argsArray)"
211
+ Else
212
+ f.Write sTab + "Set args = Py.Tuple("
213
+ first = True
214
+ For Each arg In Py.GetItem(xlfunc, "args" )
215
+ If Not first Then f.Write ", "
216
+ If Not Py.Bool(Py.GetItem(arg, "vba" )) Then
217
+ f.Write Py.Str(Py.GetItem(arg, "name" ))
218
+ Else
219
+ f.Write Py.Str(Py.GetItem(arg, "vba" ))
220
+ End If
221
+ first = False
222
+ Next arg
223
+ f.WriteLine ")"
224
+ End If
194
225
195
226
If Py.Bool(Py.GetItem(xlfunc, "xlwings" )) Then
196
227
f.WriteLine sTab + "Py.SetAttr Py.GetAttr(Py.Module(""xlwings""), ""xlplatform""), ""xl_app_latest"", Application"
@@ -243,18 +274,18 @@ not_present:
243
274
For Each arg In xlargs
244
275
If Not Py.Bool(Py.GetItem(arg, "vba" )) Then nArgs = nArgs + 1
245
276
Next arg
246
- If nArgs > 0 And Application.Version >= 14 Then
277
+ If nArgs > 0 And Val( Application.Version) >= 14 Then
247
278
ReDim argdocs(1 To WorksheetFunction.Max(1 , nArgs)) As String
248
279
nArgs = 0
249
280
For Each arg In xlargs
250
281
If Not Py.Bool(Py.GetItem(arg, "vba" )) Then
251
282
nArgs = nArgs + 1
252
- argdocs(nArgs) = Py.Str(Py.GetItem(arg, "doc" ))
283
+ argdocs(nArgs) = Left$( Py.Str(Py.GetItem(arg, "doc" )), 255 )
253
284
End If
254
285
Next arg
255
- XLPMacroOptions2010 "'" + wb.name + "'!" + fname, fdoc, argdocs
286
+ XLPMacroOptions2010 "'" + wb.name + "'!" + fname, Left$( fdoc, 255 ) , argdocs
256
287
Else
257
- Application.MacroOptions "'" + wb.name + "'!" + fname, Description:=fdoc
288
+ Application.MacroOptions "'" + wb.name + "'!" + fname, Description:=Left$( fdoc, 255 )
258
289
End If
259
290
End If
260
291
Next svar
0 commit comments