python - 如何定义文件 .exe 读取的多个参数?
问题描述
我想在 Excel 中添加几个参数以供 .exe 文件(python 脚本)读取。我在 VBA 中使用了这两个主要功能。有谁知道我可以如何更改它们以允许合并多个参数?我只能在“module_type”中插入一个参数。
非常感谢你的帮助!
Public Sub Import_data(ByVal title As String, ByVal python_script As String, ByVal table_name As String, ByVal procedure_name As String, Optional update_log As Boolean = False, Optional module_type As String, Optional get_file As Boolean = True)
Dim mypath As String
MsgBox ("Starting to import " & title & " data")
'mypath = Application.GetOpenFilename(, , "Import executable file")
If get_file Then
MyFile = Application.GetOpenFilename(, , "Import " & title & " file")
If MyFile = "False" Then Exit Sub
End If
mypath = ThisWorkbook.Path
schemaName = get_schema()
If get_file Then
Call RunPythonScript(mypath, python_script, """" & module_type & """ """ & get_database() & """ """ & connection_string("python") & """ """ & schemaName & """ --file_path """ & MyFile & """ --table """ & table_name & """")
Else
Call RunPythonScript(mypath, python_script, """" & module_type & """ """ & get_database() & """ """ & connection_string("python") & """ """ & schemaName)
End If
Dim cnn As New ADODB.Connection
Dim ConnectionString As String
Dim str As String
Dim rst As New ADODB.Recordset
ConnectionString = connection_string()
cnn.Open ConnectionString
'Change myFile to include to exclude '
MyFile = Replace(MyFile, "'", "")
If procedure_name <> "" Then
If update_log Then
Call correrQuery("exec " & procedure_name & " '" & MyFile & "'")
Else
Call correrQuery("exec " & procedure_name)
End If
End If
MsgBox ("Imported " & title & " data successfully.")
结束子
Public Sub RunPythonScript(ByVal exe_path As String, ByVal exe_name As String, Optional ByVal params As String = "")
fullCmd = exe_name
If params <> "" Then
fullCmd = fullCmd & " " & params
End If
Debug.Print fullCmd
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1
wsh.CurrentDirectory = exe_path
wsh.Run fullCmd, windowStyle, waitOnReturn
结束子
解决方案
推荐阅读
- javascript - 使用 javascript 在 html 中添加 SVG 的最佳方法是什么?
- apollo-server - 如何使用 apollo-server(gRPC,而不是 REST)实现部分查询缓存
- unit-testing - 有没有办法构建包含测试文档字符串的 Rust 文档?
- git - Git子模块哈希不断引起冲突
- python - 密码/访问密钥过期时如何通知 IAM 用户?
- sql - SQLQuery 不返回查询的文档
- python - 按键盘上的 Q 键无法完成游戏
- javascript - 出于 SEO 原因,Django 模板 + Vue 模板用于相同的内容
- excel - 如何修改代码以粘贴到下一个空白行而不是列?
- java - android studio中的私有字段