简体   繁体   English

如何使用SSIS将数据导出到Excel 2007表?

[英]How to export data to an Excel 2007 table using SSIS?

I have an excel file (xlsx) containing a table : 我有一个包含表的Excel文件(xlsx):

Excel表格

Once I launched my ssis task (successfully) to insert data in it, it is actually append after the table : 一旦我成功启动了ssis任务以向其中插入数据,它实际上就会追加到表之后:

SSIS任务后的Excel表

My expected result: 我的预期结果:

预期

So I am looking for a way to insert into the table and expand it with the data. 因此,我正在寻找一种插入表并使用数据进行扩展的方法。 I hope someone could help me. 我希望有人可以帮助我。

I would not use SSIS for this, you may have Excel2007 as linked server , putting data into Excel by regular TSQL, or process data by Excel VBA getting data directly from SQL Server. 我不会为此使用SSIS,您可能将Excel2007作为链接服务器 ,通过常规TSQL将数据放入Excel,或者通过Excel VBA处理数据,直接从SQL Server获取数据。 As a matter of practical sanity, I would not ever use SSIS for anything 出于实际考虑,我永远不会将SSIS用于任何用途

Well, there is not much information how you do it but you should specify somehow that first row should not be used as header names container (HDR=NO), something like, 嗯,您没有太多的信息来做,但是您应该以某种方式指定不应将第一行用作标头名称容器(HDR = NO),例如,

  • insert into OPENROWSET('Microsoft.Jet.OLEDB.4.0', 插入OPENROWSET('Microsoft.Jet.OLEDB.4.0',
    'Excel 8.0;Database=D:\\testing.xls; 'Excel 8.0;数据库= D:\\ testing.xls; ; ; HDR=NO' , HDR =否'
    'SELECT * FROM [Sheet1$]') 'SELECT * FROM [Sheet1 $]')

I finally found an answer. 我终于找到了答案。 So I needed to generate excel reports with a lot of pivot charts linked to a main table. 因此,我需要生成带有链接到主表的许多数据透视图的excel报告。

But using a table was a bad idea. 但是使用桌子不是一个好主意。 Instead, the pivot charts must be linked to a named range. 相反,必须将数据透视图链接到命名范围。

The last thing to know is that the error message "Invalid References" appears if the named range doesn't use the OFFSET function. 最后要知道的是,如果命名范围不使用OFFSET函数,则会出现错误消息“无效引用”。

My named range formula is : 我命名的范围公式是:

=OFFSET(Sheet!$A$1, 0, 0, COUNTA(Sheet!$A:$A), NUMBER_OF_COLUMNS)

Where Sheet is the name of the worksheet and NUMBER_OF_COLUMNS is the number of columns of the data. 其中Sheet是工作表的名称,而NUMBER_OF_COLUMNS是数据的列数。

That's it. 而已。 I can now generate excel report without any line of code, only using SSIS 2005. 现在,仅使用SSIS 2005,我就可以生成没有任何代码行的excel报告。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM