Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
与Excel相比,Python在VB.Net中的使用_Python_Vb.net_Vba - Fatal编程技术网

与Excel相比,Python在VB.Net中的使用

与Excel相比,Python在VB.Net中的使用,python,vb.net,vba,Python,Vb.net,Vba,我遇到了一个有趣的问题,我可以在excel实例中轻松地从VB获取python代码,如下所述: 但是,当我在visual studio中以一种形式模拟完全相同的代码结构时,pyscript.language=“python”行失败。有人知道MSScriptControl.ScriptControl是否可以在VB.Net中像在excel中一样控制python吗?这将比为python脚本设置com对象容易得多 示例代码(需要添加microsoft脚本控件1.0和excel对象库): 根据这一点),sc

我遇到了一个有趣的问题,我可以在excel实例中轻松地从VB获取python代码,如下所述:

但是,当我在visual studio中以一种形式模拟完全相同的代码结构时,pyscript.language=“python”行失败。有人知道MSScriptControl.ScriptControl是否可以在VB.Net中像在excel中一样控制python吗?这将比为python脚本设置com对象容易得多

示例代码(需要添加microsoft脚本控件1.0和excel对象库):

根据这一点),scriptcontrol是一个VS6项,这意味着它可能与更高版本不完全兼容。还有一个上下文问题,因为这两个环境(Windows窗体和Excel)在根本上是不同的,所以在一个环境中可能发生的事情在另一个环境中并不总是可能发生的


另外,仔细检查给定示例中的前四个步骤并确保您可以从Excel执行此操作也是非常值得的。

您收到的错误消息的确切措辞是什么?下面是代码报告:OK。错误消息是“无法创建指定语言的脚本引擎”。此分析有任何更新吗?
Imports Microsoft.Office.Interop

Public Class Form1
    Dim WithEvents PyScript As MSScriptControl.ScriptControl
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim xlApp As New Excel.Application
        xlApp.Visible = True
        Dim xlwbook As Excel.Workbook = xlApp.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet)
        Dim xlSheet As Excel.Worksheet = CType(xlwbook.Worksheets(1), Excel.Worksheet)

        If PyScript Is Nothing Then
            PyScript = New MSScriptControl.ScriptControl
            PyScript.Language = "python"
            PyScript.AddObject("Sheet", xlSheet)
            PyScript.AllowUI = True
        End If
        PyScript.ExecuteStatement("Sheet.cells(1,1).value='Hello'")


    End Sub
End Class