热门文章
 
Transact_SQL索引
应用程序中的高级SQL注入
sql server数据转换
子查询
使用约束
case 的用法
生成测试数据 T-SQL系列
经典查询排序案例
获取排队顺序 T-SQL教案
查找不同时间段间的差异 T-
 推荐文章
 
join 方式
SQL Server中保存和
SELECT TOP N 问
SQL Server中的全文
sql server 由于登
SQL Server2005
怎样将Varbinary数据
MS SQL SERVER
数据分组
distinct id的取法
SQL Server安全防范
MD5算法的T-SQL实现
改变自增字段的初始值
sql server 数据恢
使用派生表
几个SQL日志有关的概念
 
你现在的位置:您现在的位置是: 中国ASP>>数据库>>sql server
mssql转移到word

ExportToWord
Version: SQL Server 7.0/2000
Created by: Alexander Chigrik
(SQL Server Articles, FAQ, Scripts, Tips and Test Exams).

This stored procedure can be used to export the text string into
Microsoft Word. You can pass the text string and the file name
(if the file name was not specified, the c:\ImportToWord.doc
will be used) into this stored procedure, as in the example below:

EXEC ExportToWord @Text = 'Test example',
@filename = 'c:\ImportToWord.doc'


This stored procedure can be used to export the text string into
Microsoft Word. You can pass the text string and the file name
(if the file name was not specified, the c:\ImportToWord.doc
will be used) into this stored procedure, as in the example below:

EXEC ExportToWord @Text = 'Test example',
@filename = 'c:\ImportToWord.doc'
*/

IF OBJECT_ID('ExportToWord') IS NOT NULL DROP PROC ExportToWord
GO

CREATE PROCEDURE ExportToWord (
@Text varchar(200) = null,
@filename varchar(200) = 'c:\ImportToWord.doc'
)
AS
DECLARE @object int,
@Range int,
@Documents int,
@Document int,
@hr int,
@result_str varchar(255)

IF @Text IS NULL
BEGIN
PRINT 'You should write text'
RETURN
END

SET NOCOUNT ON

EXEC @hr = sp_OACreate 'Word.Application', @object OUT
IF @hr <> 0
BEGIN
PRINT 'error create Word.Application'
RETURN
END

EXEC @hr = sp_OAGetProperty @object, 'Documents', @Documents OUT
IF @hr <> 0
BEGIN
PRINT 'error create Documents'
RETURN
END

EXEC @hr = sp_OAMethod @Documents, 'Add', @Document OUT
IF @hr <> 0
BEGIN
PRINT 'error with method Add'
RETURN
END

EXEC @hr = sp_OAGetProperty @Document, 'Range', @Range OUT
IF @hr <> 0
BEGIN
PRINT 'error create Range'
RETURN
END

EXEC @hr = sp_OASetProperty @Range, 'Text', @Text
IF @hr <> 0
BEGIN
PRINT 'error set Text'
RETURN
END

SELECT @result_str = 'SaveAs("' + @filename + '")'
EXEC @hr = sp_OAMethod @Document, @result_str
IF @hr <> 0
BEGIN
PRINT 'error with method SaveAs'
RETURN
END

EXEC @hr = sp_OAMethod @Documents, 'Close'
IF @hr <> 0
BEGIN
PRINT 'error with method Close'
RETURN
END

EXEC @hr = sp_OADestroy @object
IF @hr <> 0
BEGIN
PRINT 'error destroy Word.Application'
RETURN
END
GO


相关信息:

.Net下调用SqlServer2k存储过程
SQLServer分页查询通用存储过程
access升级到SQLServer如何调整字段类型及函数:JET SQL 和T-SQL中的同义词
Transact_SQL索引
应用程序中的高级SQL注入
sql server数据转换
子查询
使用约束
case 的用法

 

中国ASP技术 ASP.ORG.CN 版权所有 2004-2008