Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $Patch_Source=""
- $Patch_Dist="\\REPORT-F\Reports\EMAIL\Test\"
- $Server = "MyServ"
- $BaseName = "MyBase"
- $BaseLogin = "MyUser"
- $BasePassw = "MyPass"
- $connection = New-Object -com "ADODB.Connection"
- $ConnectionString = "Provider=SQLOLEDB.1;
- Data Source=$Server;
- Initial Catalog=$BaseName;
- Integrated Security=SSPI
- "
- $connection.Open($ConnectionString)
- $recordSet = $connection.Execute("SELECT * from table")
- While (-not $recordSet.EOF) {
- $Коллекция = $recordSet.Fields.Item("Коллекция").Value
- $Excel = New-Object -ComObject Excel.Application
- # Создаём Excel
- #$filePath = "\\report-f\Reports\EMAIL\Test\Test.xlsm"
- $xlExcel8 = 56
- $Excel = New-Object -Com Excel.Application
- # Делаем Excel видимым
- $Excel.Visible = $true
- # ExcelRGR Excel видимым
- $Excel.DisplayAlerts = $false;
- # Добавляем рабочую книгу
- #$WorkBook = $Excell.Workbooks.Add()
- #Open the workbook
- $WorkBook = $Excel.Workbooks.Open($filePath)
- # Цепляемся к первому листу
- $WorkSheet = $Excel.WorkSheets.Item(1)
- #Обновляем
- $Excel.ActiveWorkbook.RefreshAll();
- #Выравниваем колонки
- #$WorkBook = $WorkSheet.UsedRange
- #$WorkBook.EntireColumn.AutoFit()
- #Сохраняем
- $Workbook.SaveAs($Patch_Dist+$Коллекция + $recordSet.Fields.Item("Дата").Value +".xls",56)
- #$Workbook.SaveAs($Patch_Dist+$Коллекция+"_ТоварИстекающегоСрокаГодности.OK")
- #$Workbook.SaveAs("\\REPORT-F\Reports\EMAIL\Test\" + $Коллекция+".xls")
- $WorkSheet = $null
- $WorkBook.Close($false)
- $Excel.Quit()
- $Excel = $null
- [GC]::Collect()
- [GC]::WaitForPendingFinalizers()
- [GC]::Collect()
- [GC]::WaitForPendingFinalizers()
- $recordSet.MoveNext()
- }
- $connection.Close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement