如何利用OLE自动化实现简繁体在数据库中转换?
2005的话需要现在外围应用配置器中启用ole自动化
/* Description: 需安装office2000以上版本 ------------------------------------------------------- @TransType轉換類型 0 -- 簡體轉繁體 1 -- 繁體轉簡體 @sInText待轉換的字串 @sOutText轉換後的字串 ------------------------------------------------------- */ declare @output nvarchar(400) exec spConverter '0','国',@output output print @outputcreate Proc spConverter @TransType tinyint,@sInText Nvarchar(4000),@sOutText Nvarchar(4000)OUTPUT
ASDECLARE @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 go--测试
declare @output nvarchar(400) exec spConverter '0','国',@output output print @output