在没安装OFFICE的服务器SSIS中进行EXCEL的ETL操作!

时间:2022-09-11 21:47:14

由于OFFICE 2010的安装包比较庞大,如果仅仅为了在服务器中实现操作EXCEL,完全没有必要安装整个OFFICE,是否可以不装OFFICE也实现与OFFICE文件的互相操作呢?答案是肯定的,在SSIS中只要安装Microsoft Access 2010 数据库引擎可再发行程序包即可实现2010 Microsoft Office System 文件与非 Microsoft Office 应用程序之间传输数据,支持现有的 Microsoft Office 文件(例如 Microsoft Office Access 2010(*.mdb 和 *.accdb)文件和 Microsoft Office Excel 2010(*.xls、*.xlsx 和 *.xlsb)文件)与其他数据源(例如 Microsoft SQL Server)之间传输数据。还支持与现有文本文件建立连接。 此外,还会安装 ODBC 和 OLEDB 驱动程序,供应用程序开发人员在开发与 Office 文件格式连接的应用程序时使用。该安装包下载地址:http://www.microsoft.com/zh-cn/download/details.aspx?id=13255 。

本人负责年初已上线的BI项目,一部分数据是需要自动采集在Sharepoint 2010上的Excel文档库数据,但SSIS服务器并没有安装OFFICE,就是通过此组件实现互操作!对于简单的EXCEL直接通过数据流的方式实现,对于负责的EXCEL则通过脚本实现,具体如下:

1.简单的EXCEL,数据流的实现方式。

在没安装OFFICE的服务器SSIS中进行EXCEL的ETL操作!

在没安装OFFICE的服务器SSIS中进行EXCEL的ETL操作!

在没安装OFFICE的服务器SSIS中进行EXCEL的ETL操作!

在没安装OFFICE的服务器SSIS中进行EXCEL的ETL操作!

2.负责的EXCEL,主要通过脚本实现。

连接Excel并返回所有SHEET脚本示例如下:

string strConn, ls_pjname = string.Empty,strsqlconn=string.Empty;

            strConn = @"Provider=Microsoft.Ace.OleDb.12.0;Data Source="+@as_xlspath+";Extended Properties='Excel 12.0; HDR=NO;IMEX=1'";

            OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataTable sheetNames = conn.GetOleDbSchemaTable
(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
conn.Close();

对于表内的数据可以通过SQL语句进行,脚本示例如下:

 /// <summary>
/// 獲取Excel文件中指定Sheet的內容到DataSet,以Sheet名做DataTable名
/// </summary>
/// <param name="FileFullPath">Excel物理路径</param>
/// <param name="no_HDR">第一行不是標題:true;第一行是標題:false;</param>
/// <param name="SheetName">第一行不是標題:true;第一行是標題:false;</param>
/// <returns>DataSet</returns>
public static DataSet GetExcelToDataSet(string FileFullPath, bool no_HDR, string SheetName)
{
try
{
string strConn = GetExcelConnectionString(FileFullPath, no_HDR);
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataSet ds = new DataSet();
OleDbDataAdapter odda = new OleDbDataAdapter(string.Format("SELECT * FROM [{0}]", SheetName), conn); //("select * from [Sheet1$]", conn);
odda.Fill(ds, SheetName);
conn.Close();
return ds;
}
catch (Exception ee)
{
throw new Exception(ee.Message);
}
}

通过SSIS可以实现很强大的ETL操作,但前提是根据需求,可能还需要安装一些额外的安装包或组件。

本博客为软件人生原创,欢迎转载,转载请标明出处:http://www.cnblogs.com/nbpowerboy/p/3387268.html 。演绎或用于商业目的,但是必须保留本文的署名软件人生(包含链接)。如您有任何疑问或者授权方面的协商,请给我留言。

http://www.amnxy.com/
http://www.amnxy.com/a/amanidongtai/
http://www.amnxy.com/a/changjianwenti/
http://www.amnxy.com/a/chenggonganli/
http://www.amnxy.com/a/fazhanzhanlue/
http://www.amnxy.com/a/fuwuzhichia/
http://www.amnxy.com/a/fuzhushebei/
http://www.amnxy.com/a/ganxishebei/
http://www.amnxy.com/a/gongsijiagou/
http://www.amnxy.com/a/hezuohuigu/
http://www.amnxy.com/a/hongganjishebei/
http://www.amnxy.com/a/jiamengliucheng/
http://www.amnxy.com/a/jiamengtiaojian/
http://www.amnxy.com/a/kaidianyihuo/
http://www.amnxy.com/a/kaidianzhidao/
http://www.amnxy.com/a/lianxiwomen/
http://www.amnxy.com/a/lirunfenxi/
http://www.amnxy.com/a/mendianfenbu/
http://www.amnxy.com/a/mendianyingxiao/
http://www.amnxy.com/a/mendianzhanshi/
http://www.amnxy.com/a/pinpaijianjie/
http://www.amnxy.com/a/pinpaiyoushi/
http://www.amnxy.com/a/sanxingdiananli/
http://www.amnxy.com/a/shenqingjiameng/
http://www.amnxy.com/a/shuixishebei/
http://www.amnxy.com/a/sixingdiananli/
http://www.amnxy.com/a/touzifangan/
http://www.amnxy.com/a/xiangmuyoushi/
http://www.amnxy.com/a/xingyedongtai/
http://www.amnxy.com/a/xinwenzixun/
http://www.amnxy.com/a/yinglimoshi/
http://www.amnxy.com/a/youhuizhengce/
http://www.amnxy.com/a/zhuanyepeixun/
http://www.amnxy.com/a/ziliaoxiazai/
http://www.amnxy.com/a/amanidongtai/20151109/10.html
http://www.amnxy.com/a/amanidongtai/20151109/11.html
http://www.amnxy.com/a/amanidongtai/20151109/12.html
http://www.amnxy.com/a/amanidongtai/20151109/13.html
http://www.amnxy.com/a/amanidongtai/20151109/14.html
http://www.amnxy.com/a/amanidongtai/20151109/6.html
http://www.amnxy.com/a/amanidongtai/20151109/7.html
http://www.amnxy.com/a/amanidongtai/20151109/8.html
http://www.amnxy.com/a/amanidongtai/20151109/9.html
http://www.amnxy.com/a/amanidongtai/20151115/105.html
http://www.amnxy.com/a/changjianwenti/20151208/161.html
http://www.amnxy.com/a/changjianwenti/20151208/162.html
http://www.amnxy.com/a/changjianwenti/20151208/163.html
http://www.amnxy.com/a/changjianwenti/20151208/164.html
http://www.amnxy.com/a/changjianwenti/20151208/165.html
http://www.amnxy.com/a/changjianwenti/20151208/166.html
http://www.amnxy.com/a/changjianwenti/20151208/167.html
http://www.amnxy.com/a/changjianwenti/20151208/168.html
http://www.amnxy.com/a/changjianwenti/20151208/169.html
http://www.amnxy.com/a/changjianwenti/20151210/199.html
http://www.amnxy.com/a/fuzhushebei/20151116/135.html
http://www.amnxy.com/a/fuzhushebei/20151116/141.html
http://www.amnxy.com/a/fuzhushebei/20151209/176.html
http://www.amnxy.com/a/ganxishebei/20151116/133.html
http://www.amnxy.com/a/ganxishebei/20151116/134.html
http://www.amnxy.com/a/ganxishebei/20151116/136.html
http://www.amnxy.com/a/ganxishebei/20151209/170.html
http://www.amnxy.com/a/ganxishebei/20151209/171.html
http://www.amnxy.com/a/hongganjishebei/20151209/172.html
http://www.amnxy.com/a/hongganjishebei/20151209/173.html
http://www.amnxy.com/a/hongganjishebei/20151209/174.html
http://www.amnxy.com/a/hongganjishebei/20151209/175.html
http://www.amnxy.com/a/kaidianyihuo/20151109/33.html
http://www.amnxy.com/a/kaidianyihuo/20151109/34.html
http://www.amnxy.com/a/kaidianyihuo/20151109/35.html
http://www.amnxy.com/a/kaidianyihuo/20151109/36.html
http://www.amnxy.com/a/kaidianyihuo/20151109/37.html
http://www.amnxy.com/a/kaidianyihuo/20151109/38.html
http://www.amnxy.com/a/kaidianyihuo/20151109/39.html
http://www.amnxy.com/a/kaidianyihuo/20151207/159.html
http://www.amnxy.com/a/kaidianyihuo/20151207/160.html
http://www.amnxy.com/a/kaidianyihuo/20151210/198.html
http://www.amnxy.com/a/kaidianyihuo/20151210/200.html
http://www.amnxy.com/a/lirunfenxi/20151109/21.html
http://www.amnxy.com/a/lirunfenxi/20151109/22.html
http://www.amnxy.com/a/lirunfenxi/20151109/23.html
http://www.amnxy.com/a/lirunfenxi/20151109/24.html
http://www.amnxy.com/a/lirunfenxi/20151109/25.html
http://www.amnxy.com/a/lirunfenxi/20151109/26.html
http://www.amnxy.com/a/lirunfenxi/20151205/150.html
http://www.amnxy.com/a/lirunfenxi/20151205/151.html
http://www.amnxy.com/a/lirunfenxi/20151205/152.html
http://www.amnxy.com/a/lirunfenxi/20151210/196.html
http://www.amnxy.com/a/mendianyingxiao/20151125/142.html
http://www.amnxy.com/a/mendianyingxiao/20151125/143.html
http://www.amnxy.com/a/mendianyingxiao/20151125/144.html
http://www.amnxy.com/a/mendianyingxiao/20151125/145.html
http://www.amnxy.com/a/mendianyingxiao/20151125/146.html
http://www.amnxy.com/a/mendianyingxiao/20151125/147.html
http://www.amnxy.com/a/mendianyingxiao/20151125/148.html
http://www.amnxy.com/a/mendianyingxiao/20151207/157.html
http://www.amnxy.com/a/mendianyingxiao/20151207/158.html
http://www.amnxy.com/a/mendianyingxiao/20151210/195.html
http://www.amnxy.com/a/mendianyingxiao/20151210/197.html
http://www.amnxy.com/a/mendianzhanshi/yizhanshixihu/
http://www.amnxy.com/a/qita/liansuozhongguo/
http://www.amnxy.com/a/sanxingdiananli/20151116/107.html
http://www.amnxy.com/a/sanxingdiananli/20151116/108.html
http://www.amnxy.com/a/sanxingdiananli/20151116/109.html
http://www.amnxy.com/a/sanxingdiananli/20151116/113.html
http://www.amnxy.com/a/sanxingdiananli/20151209/177.html
http://www.amnxy.com/a/shuixishebei/20151116/137.html
http://www.amnxy.com/a/sixingdiananli/20151109/27.html
http://www.amnxy.com/a/sixingdiananli/20151109/28.html
http://www.amnxy.com/a/sixingdiananli/20151109/29.html
http://www.amnxy.com/a/sixingdiananli/20151209/178.html
http://www.amnxy.com/a/sixingdiananli/20151210/179.html
http://www.amnxy.com/a/sixingdiananli/20151210/180.html
http://www.amnxy.com/a/sixingdiananli/20151210/181.html
http://www.amnxy.com/a/sixingdiananli/20151210/182.html
http://www.amnxy.com/a/sixingdiananli/20151210/183.html
http://www.amnxy.com/a/sixingdiananli/20151210/184.html
http://www.amnxy.com/a/sixingdiananli/20151210/185.html
http://www.amnxy.com/a/sixingdiananli/20151210/186.html
http://www.amnxy.com/a/sixingdiananli/20151210/187.html
http://www.amnxy.com/a/sixingdiananli/20151210/188.html
http://www.amnxy.com/a/sixingdiananli/20151210/189.html
http://www.amnxy.com/a/sixingdiananli/20151210/190.html
http://www.amnxy.com/a/sixingdiananli/20151210/191.html
http://www.amnxy.com/a/sixingdiananli/20151210/192.html
http://www.amnxy.com/a/sixingdiananli/20151210/193.html
http://www.amnxy.com/a/sixingdiananli/20151210/194.html
http://www.amnxy.com/a/touzifangan/20151115/80.html
http://www.amnxy.com/a/touzifangan/20151115/81.html
http://www.amnxy.com/a/touzifangan/20151115/82.html
http://www.amnxy.com/a/touzifangan/20151207/153.html
http://www.amnxy.com/a/touzifangan/20151207/154.html
http://www.amnxy.com/a/touzifangan/20151207/155.html
http://www.amnxy.com/a/touzifangan/20151207/156.html
http://www.amnxy.com/a/woyaojiameng/jiamengzhichi/
http://www.amnxy.com/a/xingyedongtai/20151115/106.html
http://www.amnxy.com/a/xingyedongtai/20151205/149.html
http://www.amnxy.com/a/amanirongyu/2015/1109/49.html
http://www.amnxy.com/a/amanirongyu/2015/1109/50.html
http://www.amnxy.com/a/amanirongyu/2015/1109/51.html
http://www.amnxy.com/a/amanirongyu/2015/1109/52.html
http://www.amnxy.com/a/amanirongyu/2015/1109/53.html