本帖最后由 yiwuyun 于 2015-3-27 14:51 编辑
- if ($true){}# == ($true){}# goto ___yiwuyun
- <#
- :___yiwuyun
- @echo off
- setlocal
- cls
-
- rem 查找要滑过的行数,行数加2
- rem for /f "tokens=1 delims=:" %%a in ('findstr /N "^::__yiwuyunSigned" "%~f0"') do set /a lineCount=%%a+2
-
- rem 设置执行策略
- powershell -command "&{set-executionPolicy remoteSigned}"
-
- rem 执行powershell脚本
- rem type "%~f0"|more +%lineCount%|powershell -command "-"
- type "%~f0"|powershell -command "-"
-
- rem 恢复执行策略
- powershell -command "&{set-executionPolicy restricted}"
- pause
- exit/b 0
-
- rem 签名表示要滑过的行数
- ::__yiwuyunSigned
- #>
-
- <#PowerShell脚本文件体#>
-
- Function DeleteFileByFileName{
- Param([string]$FileName)
- if(Test-Path $FileName -PathType leaf){Remove-Item $FileName}
- }
-
-
- $strPath=(Resolve-Path ".\").Path;
- DeleteFileByFileName -FileName ($strPath+"\test.xlsx");
-
- $objExcel=New-Object -ComObject "Excel.Application"
- $objExcel.WorkBooks.Add().SaveAs($strPath+"\test.xlsx");
- $objExcel.DisplayAlerts=$false;
- $objExcel.visible=$true;
- $objExcel.SheetsInNewWorkBook=2;
-
- $strArray=New-Object -TypeName System.Collections.ArrayList;
- $strArray.Add("姓名")|Out-Null;
- $strArray.Add("数学")|Out-Null;
- $strArray.Add("外语")|Out-Null;
- $strArray.Add("历史")|Out-Null;
- $strArray.Add("化学")|Out-Null;
- $strArray.Add("生物")|Out-Null;
- for($col=1;$col -lt 7;$col++){
- $objExcel.ActiveSheet.Cells.Item(1,$col)=$strArray[$col-1];
- }
-
- for($row=2;$row -lt 11;$row++){
- $objExcel.ActiveSheet.Cells.Item($row,1)="A$row";
- }
-
- $objExcel.Range("B2:F10").Formula="=40+Int(Rand()*61)";
- $objExcel.Range("A1:F10").Style.HorizontalAlignment=-4108;
-
- $objShape=$objExcel.ActiveSheet.Shapes.AddChart(51);
- $objShape.Chart.SetSourceData($objExcel.Range("A1:F10"),2);
-
- $objExcel.ActiveWorkBook.Save();
- ##$objExcel.Quit();
复制代码
|