zoukankan      html  css  js  c++  java
  • sql 2012 操作EXCEL 2013

    确认是否有Microsoft.ACE.OLEDB.12.0数据接口

     --进行配置:

    EXEC sp_configure 'show advanced options', 1
    GO
    RECONFIGURE
    GO
    EXEC sp_configure 'Ad Hoc Distributed Queries', 1
    GO
    RECONFIGURE
    GO
    --允许在进程中使用ACE.OLEDB.12
    EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
    --允许动态参数
    EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1

    --读取excel内容

    SELECT *  FROM OpenDataSource('Microsoft.ACE.OLEDB.12.0','Data Source=d:ceshi.xls;Extended properties="Excel 8.0;hdr=no"')...[sheet1$]  WHERE F5 ='订单金额'

    注:最后一个参数为选取的excel工作薄名称;  F5为select结果集字段名

    --  EXCEL 复制副本并更新某单元格内容

    --先启用 XP_CMDSHELL命令

    EXEC sp_configure 'show advanced options', 1
    GO
    RECONFIGURE
    GO
    EXEC sp_configure 'xp_cmdshell', 1
    GO
    RECONFIGURE
    GO

    ---执行复制:

    master.dbo.xp_cmdshell  'xcopy D:excel1.xlsx D:mydoc  /y/s '

    --更新

    update OpenRowSet('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;HDR=Yes;IMEX=0;Database=D:mydoc1.xlsx', 'select * from [sheet1$]') set F6='111' where F5 ='订单金额'

    --插入一行

    INSERT into OpenRowSet('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;HDR=Yes;IMEX=0;Database=D:project1.xls', 'select * from [sheet1$]')
    select 1,1,1,1,1,1,1,1,1,1,1

    注:插入字段数量和select字段数量一致

  • 相关阅读:
    java并发:简单面试问题集锦
    Java:泛型
    Java:注解(元数据)
    Java:反射
    Java:静态代理 and 动态代理
    华为机试题——该警醒了,骚年
    java并发:线程同步机制之Lock
    java并发:中断一个正在运行的线程
    java中String类型变量的赋值问题
    java中的自增问题
  • 原文地址:https://www.cnblogs.com/jhf57101/p/6007598.html
Copyright © 2011-2022 走看看