| 网站首页 | JAVA文章 | AppServers | Web开发 | 应用开发 | 资源下载 |
    想学好编程,外语很重要,最新的编程技术还是在国外  [enadd  2006年12月25日]        
设为首页 加入收藏 联系站长
您现在的位置: 编程笔记网 >> 数据库 >> sqlserver >> sqlserver入门 >> 文章正文
SQL Server 与 Excel          【字体:
SQL Server 与 Excel
作者:-    文章来源:-    点击数:    更新时间:2006-4-20

--The ExecuteWithResults method executes a Transact-SQL command batch
--returning batch result sets in a QueryResults object
SELECT @result_str = 'ExecuteWithResults("' + @QueryText + '")'
EXEC @hr = sp_OAMethod @SQLServer, @result_str, @QueryResults OUT
IF @hr <> 0
BEGIN
    PRINT 'error with method ExecuteWithResults'
    RETURN
END

--The CurrentResultSet property controls access to the result sets of a QueryResults object
EXEC @hr = sp_OAMethod @QueryResults, 'CurrentResultSet', @CurrentResultSet OUT
IF @hr <> 0
BEGIN
   PRINT 'error get CurrentResultSet'
   RETURN
END

--The Columns property exposes the number of columns contained
--in the current result set of a QueryResults object
EXEC @hr = sp_OAMethod @QueryResults, 'Columns', @Columns OUT
IF @hr <> 0
BEGIN
   PRINT 'error get Columns'
   RETURN
END

--The Rows property returns the number of rows in a referenced
--query result set or the number of rows existing in a table
EXEC @hr = sp_OAMethod @QueryResults, 'Rows', @Rows OUT
IF @hr <> 0
BEGIN
   PRINT 'error get Rows'
   RETURN
END

--创建Excel.Application对象
EXEC @hr = sp_OACreate 'Excel.Application', @object OUT
IF @hr <> 0
BEGIN
   PRINT 'error create Excel.Application'
   RETURN
END

--获得Excel工作簿对象
EXEC @hr = sp_OAGetProperty @object, 'WorkBooks', @WorkBooks OUT
IF @hr <> 0
BEGIN
   PRINT 'error create WorkBooks'
   RETURN
END

--在工作簿对象中加入一工作表
EXEC @hr = sp_OAGetProperty @WorkBooks, 'Add', @WorkBook OUT
IF @hr <> 0
BEGIN
   PRINT 'error with method Add'
   RETURN
END

--Range对象(A1单元格)
EXEC @hr = sp_OAGetProperty @object, 'Range("A1")', @Range OUT
IF @hr <> 0
BEGIN
   PRINT 'error create Range'
   RETURN
END

SELECT @indRow = 1
SELECT @off_Row = 0
SELECT @off_Column = 1

WHILE (@indRow <= @Rows)
BEGIN
   SELECT @indColumn = 1
   WHILE (@indColumn <= @Columns)
   BEGIN
      --The GetColumnString method returns a QueryResults object result set member converted to a String value
      EXEC @hr = sp_OAMethod @QueryResults, 'GetColumnString', @result_str OUT, @indRow, @indColumn
      IF @hr <> 0
      BEGIN
         PRINT 'error get GetColumnString'
         RETURN
      END

上一页  [1] [2] [3] 下一页  

文章录入:enadd    责任编辑:enadd 
  • 上一篇文章:

  • 下一篇文章:
  • 发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
    最新热点 最新推荐 相关文章
  • SQL Server 2000 XML之七种兵…

  • 如何使用SQL Server 2000全文…

  • 使用SQL Server发送邮件

  • (MS SQL Server)SQL语句导入…

  • SQL INJECTION的SQL SERVER安…

  • 在SQL Server 中使用SQLDMO

  • SQL Server补丁版本的检查和…

  • SQL Server联机丛书:删除存…

  • SQL Server:创建索引视图

  • SQL Server基础

  •   网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明 | 管理登录 |