无法将类型为“Word.ApplicationClass”的 COM 对象强制转换为接口类型“Word._Application”

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法将类型为“Word.ApplicationClass”的 COM 对象强制转换为接口类型“Word._Application”相关的知识,希望对你有一定的参考价值。

想用C#操作Word,代码执行到下面第二句时报标题的那个错,
Word.Application WordApp = new Word.ApplicationClass();
Word.Document WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
问题是,我在一台机器上执行明明没有问题,为什么换了另一台机器就会出问题呢?请问问题出在哪?跟本地的OFFICE有关还是什么?两台机器都装了Office,版本也一样。有知道的达人请回答,不知道瞎忽悠的请绕道。
不是路径问题,问题没解决……

机器A和机器B使用的OFFICE安装程序是相同的吗?如果相同,你在考虑一下.Net Framework 的版本。

是不是用了第三方的控件或类库?

试试是不是中文路径问题,或者其他的路径问题。

在本机不要在环境中调试程序,到你Bin文件夹下运行程序,将两台机器上的程序放到相同路径 例如 C:\Pro\ 然后测试。

--

是不是少了支持类库?你看看能运行那台机器上的都有哪些支持类库,应该是没有支持库。
参考技术A 代码到是没错那你有试过 权限 打开方式等哦?

http://cache.baidu.com/c?m=9d78d513d9861cef0efa950e1a16a0711824d63e6d908f4223928448e22106011171e2cb717f4113d3b4393a41f91a1ea8e73702200357a09ab8de178cfccd7f73ce6623716c914165c418df981073d567d004e6f55fa1f8e733e0b3cf958216089b44050dd1b1dd061714bd33a7522ca5bb994a175e13b9ed3578fc5d6a29982140b546f9f732195dc7a983&p=83769a4597934eac5aa482361e5f&user=baidu

TypeError:无法将“4”解释为数据类型

【中文标题】TypeError:无法将“4”解释为数据类型【英文标题】:TypeError: Cannot interpret '4' as a data type 【发布时间】:2021-04-17 04:41:08 【问题描述】:

我正在尝试学习神经网络。以下是代码。我收到错误“TypeError:无法将 '4' 解释为数据类型”,谁能帮我找出错误?

import numpy as np

inputs = [[1, 2 , 3, 2.5],
      [2, 5, 9, 10],
      [5, 1, 2, 7],
      [3, 2, 1, 4],
      [1,1.5, 7, 8]]

class layer_dense:
      def __init__ (self, n_inputs, m_neurons):
        self.weights= np.random.rand(n_inputs, m_neurons)
        self.biases= np.zeros(1, m_neurons)
     def forward (self, inputs):
        self.output= np.dot(inputs, self.weights)+self.biases
    
layer1 = layer_dense(4, 4)
layer2 = layer_dense(5,2)

layer1.forward(inputs)
layer2.forward(layer1.output)
print(layer2.output)

【问题讨论】:

【参考方案1】:

Per function description

numpy.zeros(shape, dtype=float, order='C')

第二个参数应该是数据类型而不是数字

【讨论】:

【参考方案2】:

零的签名如下:

numpy.zeros(shape, dtype=float, order='C')

shape 参数应以整数或多个整数的元组形式提供。您得到的错误是由于 4 被解释为 dtype。

【讨论】:

以上是关于无法将类型为“Word.ApplicationClass”的 COM 对象强制转换为接口类型“Word._Application”的主要内容,如果未能解决你的问题,请参考以下文章

C# 无法将类型为“System.Byte[]”的对象强制转换为类型“System.Data.DataTable

无法将类型“()”的值转换为预期的参数类型“字符串”

无法将 [Struct] 类型的值快速转换为 [string] 类型

无法将类型为“Microsoft.Office.Interop.Word.ApplicationClass”的 COM 对象强制转换为接口类型“Micro

Swift“无法将''类型的值转换为'String'类型

无法将“字符串”类型的值转换为预期的参数类型 [任何]