function split_doc() { #read-host "111" for ($i=0; $i -lt $iarr_split.Length-1; $i++) { $part1=$word.Documents.Add() #write-host ($iarr_split[$i],$iarr_split[$i+1]) $rang= $doc.Range([ref] $iarr_split[$i],[ref] $iarr_split[$i+1]) $rang.Copy() #read-host $rang $p=$part1.Range() $p.Paste() $spart=$path+"\part_"+($i+1)+$resol $part1.SaveAs([ref]$spart) if ($i -eq 200) { $MsgBos = new-object -comobject wscript.shell $MsgBos.popup("More files",0,"Error",64) break} } } #-------------------------------------- function table_use() { $tabl|%{$t=$_; $it=$content.IndexOf($t.Range.Text) [int]$rows=$t.Rows.Count [int]$columns=$t.Columns.Count $lent=$rows*$columns #read-host $tlen for ($i=0; $i -lt $iarr_split.Length-1; $i++) { if ($iarr_split[$i] -lt $it -and $it -lt $iarr_split[$i+1]) {for ($j=$i+1; $j -lt $iarr_split.Length-1; $j++) {$iarr_split[$j]-=$lent+2} } } } } #Input data #*************************************************** $app = New-Object -COM Shell.Application $directory = $app.BrowseForFolder( 0, "Select Directory for save",0) #--------- function Get-OpenFile { [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |Out-Null $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog #$OpenFileDialog.initialDirectory = $initialDirectory $OpenFileDialog.ShowHelp = $true $OpenFileDialog.ShowDialog()|Out-Null return $OpenFileDialog.filename } $InputFile = Get-OpenFile #************************** <#$browse=new-object -com UserAccounts.CommonDialog $browse.ShowOpen()#> #-------------------- <#$Input = new-object -comobject MSScriptControl.ScriptControl $Input.language = "vbscript" $Input.addcode("function getInput() getInput = inputbox(`"Input split-words`",`"Enter string`") end function" ) $Inp = $Input.eval("getInput")#> #***************************** function Read-InputBoxDialog([string]$Message, [string]$WindowTitle, [string]$DefaultText) { Add-Type -AssemblyName Microsoft.VisualBasic return [Microsoft.VisualBasic.Interaction]::InputBox($Message, $WindowTitle, $DefaultText) } $Inp = Read-InputBoxDialog -Message "Please enter the words-split" -WindowTitle "Input words" #***************************** #Initialization $file=$InputFile#"J:\1\test.docx"#$args[0] #read-host $file $global:resol=$file.Substring($file.IndexOf('.')) $global:path=$directory.Self.Path# $args[1] "J:\1\\3\"# $split_string=$Inp#"выбираем|папку"#$args[2] #"Bьярни"# if (!$file -or !$path -or !$split_string) {Exit} $spls=$split_string.Split('|') #write-host path_$path #************************************************ #-------------------------------------- $word=New-Object -ComObject Word.Application #$word.Visible=$true $doc=$word.Documents.Open($file) $content=$doc.Content.Text $tabl=$doc.Tables #index_split [int32[]]$global:iarr_split+=0 $spls|%{$i=0; while ($i -gt -1) {$i=$content.IndexOf($_,$i+1); if ($i -gt -1) {$iarr_split+=$i} } } $iarr_split+=$doc.Range().end #-------------------------------- $iarr_split=$iarr_split|Sort-Object #write-host iarr_split_1_$iarr_split table_use($tabl) #read-host $iarr_split #write-host iarr_split_2_$iarr_split if ($iarr_split.Length -gt 2) {#read-host "111" split_doc($doc, $iarr_split, $path ) <#for ($i=0; $i -lt $iarr_split.Length-1; $i++) { $part1=$word.Documents.Add() #write-host ($iarr_split[$i],$iarr_split[$i+1]) read-host $iarr_split[$i] $rang= $doc.Range([ref] $iarr_split[$i],[ref] $iarr_split[$i+1]) $rang.Copy() $p=$part1.Range() $p.Paste() $spart=$path+"\part_"+($i+1)+".docx" $part1.SaveAs([ref]$spart) if ($i -eq 200) { $MsgBos = new-object -comobject wscript.shell $MsgBos.popup("More files",0,"Error",64) break} }#> } else {$MsgBos = new-object -comobject wscript.shell $MsgBos.popup("Only one file",0,"Warning",64)} #////////// $word.Quit() read-host "END"