码迷,mamicode.com
首页 > 其他好文 > 详细

根据模板自动生成数据

时间:2015-05-08 19:48:27      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

#首先需将系统时间设置为每个月的第一个周一,然后运行此脚本
$wbs = 0..3
$sheets = 1..5
$rows = 4..6   #142
$definition = 1..40 | ForEach-Object {"rev. " + $_.ToString().PadLeft(3,"0")}
$date = Get-Date
$mins = 1..23
$secs = 1..59
$time = foreach($min in $mins) {
            foreach($sec in $secs) {
                $min.ToString() + ":" +  $sec.ToString()
        }}

$xl = New-Object -ComObject "Excel.Application"
$cmdbwb = $xl.Workbooks.Open("C:\Users\Administrator\Desktop\template.xlsx")
foreach($wb in $wbs) {
    foreach($sheet in $sheets) {
        $cmdbws = $cmdbwb.Worksheets.Item("SEPM Day $sheet")
        $cmdbws.Range("D2").Value2 = "Date: " + $date.AddDays($sheet - 1 + 7 * $wb).ToShortDateString()
        foreach($row in $rows) {
            $cmdbws.Range("D$row").Value2 = $date.AddDays($sheet - 1 + 7 * $wb).ToShortDateString() + " " + (Get-Random $time)   #Last Time Staus Changed
            $cmdbws.Range("E$row").value2 = $date.AddDays($sheet - 2 + 7 * $wb).ToShortDateString() + " " + (Get-Random $definition)   #Virus Definition
            $cmdbws.Range("F$row").value2 = $date.AddDays($sheet - 1 + 7 * $wb).ToShortDateString() + " " + (Get-Random $time)   #Last Scan
        }
    }
$cmdbws.SaveAs("C:\Users\Administrator\Desktop\Week " + (1 + $wb) + ".xlsx")
}

$xl.Quit()
$cmdbws = $null
$cmdbwb = $null
$cmdbws = $null
$cmdbwb = $null
$xl = $null

 

 

根据模板自动生成数据

标签:

原文地址:http://www.cnblogs.com/IvanChen/p/4488559.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!