1 Star 0 Fork 0

霍啸林 / ExcelPowerShell

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
04-Invoke03.linq 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
霍啸林 提交于 2020-03-15 21:19 . Invoke PS by VB
<Query Kind="VBStatements">
<Reference>&lt;ProgramFilesX86&gt;\Reference Assemblies\Microsoft\WindowsPowerShell\3.0\System.Management.Automation.dll</Reference>
<Namespace>System.Collections.ObjectModel</Namespace>
<Namespace>System.Management.Automation</Namespace>
</Query>
Dim PowerShellInstance As PowerShell = PowerShell.Create
Dim scriptBuilder As New System.Text.StringBuilder
scriptBuilder.AppendLine("param($WorkbookFullPath)")
scriptBuilder.AppendLine("$ExcelApp = New-Object -ComObject Excel.Application")
scriptBuilder.AppendLine("$ExcelApp.DisplayAlerts = $false")
scriptBuilder.AppendLine("$ExcelWorkbook = $ExcelApp.Workbooks.Open($WorkbookFullPath)")
scriptBuilder.AppendLine("$ExcelWorksheet = $ExcelWorkbook.Worksheets.Item('PivotResult')")
scriptBuilder.AppendLine("$ExcelWorksheet.Activate()")
scriptBuilder.AppendLine("$PivotTable = $ExcelWorksheet.PivotTables('ncov')")
scriptBuilder.AppendLine("$PivotTable.ClearTable()")
scriptBuilder.AppendLine("Remove-Variable -Name PivotTable,ExcelWorksheet")
scriptBuilder.AppendLine("$ExcelWorkbook.Save()")
scriptBuilder.AppendLine("$ExcelWorkbook.Close($false)")
scriptBuilder.AppendLine("Remove-Variable -Name ExcelWorkbook")
scriptBuilder.AppendLine("$ExcelApp.Quit()")
scriptBuilder.AppendLine("Remove-Variable -Name ExcelApp")
scriptBuilder.AppendLine("Stop-Process -Name EXCEL")
PowerShellInstance.AddScript(scriptBuilder.ToString)
PowerShellInstance.AddParameter("WorkbookFullPath", "E:\Gitee\TestData03.xlsx")
Dim PSOutput As Collection(Of PSObject) = PowerShellInstance.Invoke
Dim DataStreams As PSDataStreams = PowerShellInstance.Streams
PSOutput.Dump
DataStreams.Dump
PowerShellInstance.Dispose
PowerShell
1
https://gitee.com/pxp/ExcelPowerShell.git
git@gitee.com:pxp/ExcelPowerShell.git
pxp
ExcelPowerShell
ExcelPowerShell
master

搜索帮助