CSDN博客

img tdl982324

在存储过程中调用外部对象进行简繁互换

发表于2004/9/29 16:07:00  997人阅读

/*
  Description:
  Need Office 2000
 
 参数说明:
-------------------------------------------------------
 @TransType  转换类型
     0 -- GB->Big5
     1 -- Big5->GB 
 @sInText  文本
 @sOutText   返回文本
-------------------------------------------------------
*/


ALTER  Proc spConverter @TransType tinyint,@sInText Nvarchar(4000),@sOutText Nvarchar(4000)OUTPUT
AS

 DECLARE @WordApplication int
 DECLARE @ErrHandler int
 DECLARE @Document int
 DECLARE @Selection int
 DECLARE @Message NVARCHAR(4000)
 DECLARE @src varchar(255), @desc varchar(255)
 --Create Word instance
 EXEC @ErrHandler = sp_OACreate 'Word.Application', @WordApplication OUT
 IF @ErrHandler != 0
 BEGIN
    EXEC sp_OAGetErrorInfo @WordApplication, @src OUT, @desc OUT
    SELECT hr=convert(varbinary(4),@ErrHandler), Source=@src, Description=@desc
     RETURN
 END
 ---// create instance end
 --Create a word document instance
 EXEC @ErrHandler = sp_OACreate 'Word.Document', @Document OUT
 IF @ErrHandler != 0
 BEGIN
    EXEC sp_OAGetErrorInfo @Document, @src OUT, @desc OUT
    SELECT hr=convert(varbinary(4),@ErrHandler), Source=@src, Description=@desc
     RETURN
 END
 --//
 ---
 EXEC @ErrHandler = sp_OAGetProperty @Document, 'Application.Selection', @Selection OUT
 IF @ErrHandler != 0
 BEGIN
    EXEC sp_OAGetErrorInfo @Document
     RETURN
 END
 
 EXEC @ErrHandler = sp_OASetProperty @Selection, 'Text', @sInText
 IF @ErrHandler != 0
 BEGIN
    EXEC sp_OAGetErrorInfo @Selection
     RETURN
 END
 
 EXEC @ErrHandler = sp_OAMethod @Selection, 'Range.TCSCConverter',NULL,@TransType,1,1
 IF @ErrHandler != 0
 BEGIN
    EXEC sp_OAGetErrorInfo @Selection
     RETURN
 END
 
 EXEC @ErrHandler = sp_OAGetProperty @Selection, 'Text', @sOutText OUT
 IF @ErrHandler != 0
 BEGIN
    EXEC sp_OAGetErrorInfo @Selection
     RETURN
 END
 ---
 EXEC @ErrHandler = sp_OADestroy @WordApplication
 IF @Errhandler != 0
 BEGIN
    EXEC sp_OAGetErrorInfo @WordApplication
     RETURN
 END
 ---
 EXEC @ErrHandler = sp_OADestroy @Document
 IF @Errhandler != 0
 BEGIN
    EXEC sp_OAGetErrorInfo @Document
     RETURN
 END
 EXEC sp_OAStop
 RETURN

阅读全文
0 0

相关文章推荐

img
取 消
img