Добрый день коллеги!
Не получается решить одну задачу:
MS SQL SERVER создает документ MS Word
Вставляет строки
Потом необходимо сделать замену вставленных строк <<Find&Replace>>
Пишу следующий код:
Exec @RetCode = sp_OAMethod @WordObject, 'Documents.Add', @Document OUTPUT
--EXEC @RetCode = sp_OAMethod @WordObject, 'Documents.open', @Document OUT, 'C:\Temp\SQLServer1.docx'
select @RetCode
Exec @RetCode = sp_OAMethod @WordObject,'Selection.TypeText("GGGGGGGGG TTTTTTTTTTTTTTTTTTTTTTT1 ")'
Exec @RetCode = sp_OAMethod @WordObject,'Selection.TypeText("BBBBBBBBBBBBBBBBBBBBBBBBBBBB JJJJJJJJJJJJJJ ")'
Exec @RetCode = sp_OAMethod @WordObject,'Selection.TypeText(" XCVBVCXVBNVC ")'
Exec @RetCode = sp_OASetProperty @WordObject,'Selection.Find.Text','G'
if @RetCode <> 0 select @RetCode as point1
Exec @RetCode = sp_OASetProperty @WordObject,'Selection.Find.Replacement.Text','QWERTY'
if @RetCode <> 0 select @RetCode as point2
Exec @RetCode = sp_OASetProperty @WordObject,'Selection.Find.Forward','True'
if @RetCode <> 0 select @RetCode as point3
Exec @RetCode = sp_OASetProperty @WordObject,'Selection.Find.Format','False'
if @RetCode <> 0 select @RetCode as point4
exec @RetCode = sp_OAMethod @WordObject,'Selection.Find.Execute',@Document OUTPUT,'wdReplaceAll'
if @RetCode <> 0 select @RetCode as point5
Exec @RetCode = sp_OAMethod @WordObject, 'ActiveDocument.SaveAs("C:\Temp\SQLServer2.docx")'
Exec @RetCode = sp_OAMethod @WordObject, 'Quit'
Exec sp_OADestroy @WordObject
Exec sp_OAStop
Документ на диске создается, но поиск и замена не была сделана:
GGGGGGGGG TTTTTTTTTTTTTTTTTTTTTTT1 BBBBBBBBBBBBBBBBBBBBBBBBBBBB JJJJJJJJJJJJJJ XCVBVCXVBNVC
Скажите пожалуйста кто знает как решить проблему