Powershell脚本在Excel工作簿中获取日历格式

时间:2019-01-11 10:46:30

标签: excel powershell

我正在寻找一个Powershell脚本,该脚本将获取Excel工作表的格式,如下所示:

tables in excel

我一直在尝试这段代码,但是没有获得预期的正确格式。

function Release-Ref ($ref) { 
    ([System.Runtime.InteropServices.Marshal]::ReleaseComObject( 
        [System.__ComObject]$ref) -gt 0
    ) 
    [System.GC]::Collect() 
    [System.GC]::WaitForPendingFinalizers()  
} 

$xlFillDays = 5 
$objExcel = new-object -comobject excel.application 
$objExcel.Visible = $True 

$objWorkbook = $objExcel.Workbooks.Add() 

$objWorksheet = $objWorkbook.Worksheets.Item(1) 
$objWorksheet.Cells.Item(1, 1).Value() = "1/1/2019" 

$objRange1 = $objExcel.Range("A1") 
$objRange2 = $objExcel.Range("A1:A365") 
$a = $objRange1.AutoFill($objRange2, $xlFillDays) 
$a = $objRange1.EntireColumn.Autofit() 

$a = Release-Ref($objWorksheet) 
$a = Release-Ref($objWorkbook) 
$a = Release-Ref($objExcel) 

0 个答案:

没有答案