本帖最后由 for_flr 于 2022-3-23 15:25 编辑
回复 3# WHY
感谢WHY神指导,借鉴修改,已能实现自动排表,谢谢。- $namelist="老赵,小赵,老钱,小钱,老孙,小孙,老李,小李,老周,小周" #原名字序列
- $namelist -split '(\w+,\w+)'|%{
- $a=$_.split(',',[stringsplitoptions]::removeemptyentries)
- [array]::reverse($a)
- $new+=$a
- }
- $exchange=$new -join "," #交换上下午名字序列
- $lastname="小李,老李" #上一次csv文件最后出现的名字顺序
- if ($namelist -match $lastname){$nameall=$namelist+","+$exchange}
- if ($exchange -match $lastname){$nameall=$exchange+","+$namelist}
- $namenew=($nameall -split "$lastname")[-1] #将两个序列按情况拼接在一起!
- $namenew=$namenew.split(',',[stringsplitoptions]::removeemptyentries)
-
- $csv = @('日期,上午,下午')
- $today=(get-date).dayofweek
- $csv+=for($i=0;$i -le (7-$today);$i++){
- $n=$i*2 #模运算有点烧脑。。添加$n来取名单
- $date=(get-date).adddays($i)
- "{0},{1},{2}" -f ($date.tostring('yyyy/MM/dd')+$date.tostring('ddd')),$namenew[$n],$namenew[$n+1]
- }
- $csvname=$date.tostring('yyyyMMdd')+".csv"
- sc $csvname -value $csv
复制代码
|