45fan.com - 路饭网

搜索: 您的位置主页 > 网络频道 > 阅读资讯:如何利用OLE自动化实现简繁体在数据库中转换?

如何利用OLE自动化实现简繁体在数据库中转换?

2016-08-24 11:45:34 来源:www.45fan.com 【

如何利用OLE自动化实现简繁体在数据库中转换?

2005的话需要现在外围应用配置器中启用ole自动化

/*

Description:

需安装office2000以上版本

-------------------------------------------------------

@TransType轉換類型

0 -- 簡體轉繁體

1 -- 繁體轉簡體

@sInText待轉換的字串

@sOutText轉換後的字串

-------------------------------------------------------

*/

declare @output nvarchar(400)

exec spConverter '0','国',@output output

print @output

create 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

go

--测试

declare @output nvarchar(400)

exec spConverter '0','国',@output output

print @output

本文地址:http://www.45fan.com/a/question/66888.html
Tags: 实现 简繁体 OLE
编辑:路饭网
关于我们 | 联系我们 | 友情链接 | 网站地图 | Sitemap | App | 返回顶部