Powershell Create DataTable(创建数据表)

$In_dtInOak = [System.Data.DataTable]::new();

$ret = $In_dtInOak.Columns.Add("C_KEY");

$ret = $In_dtInOak.Columns.Add("CONTENT");

$ret = $In_dtInOak.Columns.Add("LEVEL");

$xlApp = New-Object -ComObject Excel.Application;

$xlBook = $xlApp.Workbooks.Open("C:\Users\abc\Desktop\result.xlsx");

$xlSheet = $xlBook.Worksheets.Item(1);

$rMax = $xlSheet.UsedRange.Rows.Count;

for($rTemp = 2;$rTemp -le $rMax;$rTemp++){

    $arr = @($xlSheet.Cells.Item($rTemp,1).Value2,$xlSheet.Cells.Item($rTemp,2).Value2,$xlSheet.Cells.Item($rTemp,3).Value2);

    $ret = $In_dtInOak.Rows.Add($arr);

}

$xlSheet = $null;

$xlBook.Close($false);

$xlBook = $null;

$xlApp.Quit();

$xlApp = $null;

[System.GC]::Collect();

你可能感兴趣的:(Powershell)