gpt4 book ai didi

excel - 电源外壳 | Com-object Excel |打开展望?

转载 作者:行者123 更新时间:2023-12-02 11:21:28 26 4
gpt4 key购买 nike

仅在未配置邮件帐户时才会出现问题 - 我仍然希望找到解决方案

我需要一些帮助。我发现这个小脚本有一个非常奇怪的习惯。我完全不知道为什么会发生这种情况。如果我运行下面发布的代码,Microsoft Outlook 就会启动。只要我不终止 Outlook 进程,脚本就会卡住!为什么这段代码会启动 Outlook?我迷路了!

$Path     = "C:\test.xls"
#Excelvar:
$Row = [int] 2
$Excel = New-Object -ComObject Excel.Application
$Excel.Visible = $true
$Excel.DisplayAlerts = $false
#Sheets:
$ADUsers = "Active Directory Users"
$Groups = "Create Groups"
$UsertoGroup = "User to groups"
$DNS = "DNS"
#$Worksheet = $Workbook.Sheets.Add()
$checkxls = test-path -pathtype Any $Path
if ($checkxls -eq $false) {
$wb = $Excel.Workbooks.Add()

$wb.Worksheets.add()

$wb.SaveAs($Path)
$wb.Close()
$Excel.Quit()

提前致谢!

Outlook 终止后 Powershell 输出:

Application                       : Microsoft.Office.Interop.Excel.ApplicationClass
Creator : 1480803660
Parent : System.__ComObject
CodeName :
_CodeName :
Index : 1
Name : Tabelle4
Next : System.__ComObject
OnDoubleClick :
OnSheetActivate :
OnSheetDeactivate :
PageSetup : System.__ComObject
Previous :
ProtectContents : False
ProtectDrawingObjects : False
ProtectionMode : False
ProtectScenarios : False
Visible : -1
Shapes : System.__ComObject
TransitionExpEval : False
AutoFilterMode : False
EnableCalculation : True
Cells : System.__ComObject
CircularReference :
Columns : System.__ComObject
ConsolidationFunction : -4157
ConsolidationOptions : {False, False, False}
ConsolidationSources :
DisplayAutomaticPageBreaks : False
EnableAutoFilter : False
EnableSelection : 0
EnableOutlining : False
EnablePivotTable : False
FilterMode : False
Names : System.__ComObject
OnCalculate :
OnData :
OnEntry :
Outline : System.__ComObject
Rows : System.__ComObject
ScrollArea :
StandardHeight : 15
StandardWidth : 10,71
TransitionFormEntry : False
Type : -4167
UsedRange : System.__ComObject
HPageBreaks : System.__ComObject
VPageBreaks : System.__ComObject
QueryTables : System.__ComObject
DisplayPageBreaks : False
Comments : System.__ComObject
Hyperlinks : System.__ComObject
_DisplayRightToLeft : False
AutoFilter :
DisplayRightToLeft : False
Scripts : System.__ComObject
Tab : System.__ComObject
MailEnvelope :
CustomProperties : System.__ComObject
SmartTags : System.__ComObject
Protection : System.__ComObject
ListObjects : System.__ComObject
EnableFormatConditionsCalculation : True
Sort : System.__ComObject
PrintedCommentPages : 0

最佳答案

这里的问题是,当您运行 $wb.Worksheets.add() 时,它将新工作表返回到管道(这就是当您终止 Outlook 时显示工作表属性的原因)。

我相信工作表的 MailEnvelope 属性是导致 Outlook 打开的原因(如果您存储工作表并返回 MailEnvelope 属性,则会发生相同的行为)。

要解决此问题,您可以存储返回的工作表、使用 Out-Null cmdlet 或将工作表强制转换为 void:$ws = $wb.Worksheets.add() 或$wb.Worksheets.add() | $wb.Worksheets.add() | Out-Null[void] $wb.Worksheets.add()

关于excel - 电源外壳 | Com-object Excel |打开展望?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19703380/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com