Powershell to Excel“旧格式或无效类型库。 (来自HRESULT的异常:0x80028018 TYPE_E_INVDATAREAD))“ [英] Powershell to Excel "Old format or invalid type library. (Exception from HRESULT: 0x80028018 TYPE_E_INVDATAREAD))"

查看:115
本文介绍了Powershell to Excel“旧格式或无效类型库。 (来自HRESULT的异常:0x80028018 TYPE_E_INVDATAREAD))“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我有一个朋友写的脚本&给了我在en-US Windows 7上用法语Office 2013写的。这个脚本对他来说很好,但对我来说英语Windows 7&英语Office 2013,我在特定cmdlet中出现以下错误


"旧格式或无效类型库。 (来自HRESULT的异常:0x80028018 TYPE_E_INVDATAREAD))"


原始代码。

 $ xl = New -Object -ComObject" Excel.Application" 
$ xl.Visible = $ True
$ wb = $ xl.Workbooks.Open(" D:\work\file.xlsx")

我从这个
页面
修改了脚本这样我就可以打开文件,工作正常...

 function Invoke([object] $ m,[string] $ method,$ parameters)
{
$ m.PSBase.GetType()。InvokeMember(
$ method,[Reflection.BindingFlags] :: InvokeMethod,$ null,$ m,$ parameters,$ ciUS)
}

$ ciUS = [System.Globalization.CultureInfo]'en-US'

$ objExcel = New-object -com Excel.Application
$ objExcel。 visible = $ True
$ ci = [System.Globalization.CultureInfo]'en-us'
$ objWorkbook =调用$ objExcel.Workbooks Open(" D:\work\file.xlsx" )

问题在于脚本的其余部分......

 $ ws = $ objWorkbook.Worksheets .Item(3)
$ cells = $ ws.Cells

$ range = $ ws.range(" A2:Z99")
$ null = $ range.Delete()
$ range = $ null

调用 $ range.delete()

时出现以下错误
异常调用"删除"用"0"表示"0"。参数:"旧格式或无效类型库。 (HRESULT异常:0x80028018 TYPE_E_INVDATAREAD))"

行:1 char:22

+ $ null = $ range.Delete<<<< ()

  &NBSP; + CategoryInfo  &NBSP; &NBSP; &NBSP;  :NotSpecified:(:) [],MethodInvocationException

  &NBSP; + FullyQualifiedErrorId:ComMethodTargetInvocation


为什么该函数可以用于打开文件,但不能用于后续的excel命令?


谢谢


Alex


PS,无论如何我可以三重检查我的语言版本的Office? (Windows系统区域设置为def英语(美国)




解决方案

它与语言无关。您有其他问题,无法确定帖子中的内容。


你不需要文化位。你的朋友需要它们。如果你不在法国,你就不要这样做。




Hi everyone,

I have a script a friend wrote & gave me written on en-US Windows 7 with French Office 2013.  The script works fine for him, however for me with English Windows 7 & English Office 2013, I get the following error with specific cmdlets

"Old format or invalid type library. (Exception from HRESULT: 0x80028018 TYPE_E_INVDATAREAD))"

the original code.

$xl=New-Object -ComObject "Excel.Application"
$xl.Visible=$True
$wb = $xl.Workbooks.Open("D:\work\file.xlsx")

I modified the script from this page to this so I could open the file, which works fine...

function Invoke([object]$m, [string]$method, $parameters)
{
$m.PSBase.GetType().InvokeMember(
$method, [Reflection.BindingFlags]::InvokeMethod, $null, $m, $parameters,$ciUS)
} 

$ciUS = [System.Globalization.CultureInfo]'en-US'

$objExcel = New-object -com Excel.Application
$objExcel.visible = $True
$ci = [System.Globalization.CultureInfo]'en-us'
$objWorkbook = Invoke $objExcel.Workbooks Open("D:\work\file.xlsx")

the problem is with the rest of the script...

$ws = $objWorkbook.Worksheets.Item(3)
$cells = $ws.Cells

$range = $ws.range("A2:Z99")
$null = $range.Delete()
$range = $null

I get the following error when calling $range.delete()

Exception calling "Delete" with "0" argument(s): "Old format or invalid type library. (Exception from HRESULT: 0x80028018 TYPE_E_INVDATAREAD))"
At line:1 char:22
+ $null = $range.Delete <<<< ()
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

Why would the function work for opening the file, but not for subsequent excel commands?

Thanks

Alex

P.S, anyway I can triple check my language version of Office? (Windows system locale is def English (United States)


解决方案

It has nothing to do with language.  You have other issues and it is not possible to tell what they are from your post.

You do not need the culture bits. Your friend needed them. YOu don't if you are not in France.


这篇关于Powershell to Excel“旧格式或无效类型库。 (来自HRESULT的异常:0x80028018 TYPE_E_INVDATAREAD))“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆