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字段数量一致

  • 相关阅读:
    C++易错处总结
    Dev-C++debug使用方法
    IDEA使用心得
    记录零碎ACM小知识
    Div3 C good number easy version
    cin,scanf后使用getline() 函数的易错点
    while中同时使用scanf和break的易错点
    聚集表索引优化
    .net中不能在DropDownList中选中多个项的解决方法
    MVC3 带查询的分页Helper
  • 原文地址:https://www.cnblogs.com/jhf57101/p/6007598.html
Copyright © 2011-2022 走看看