在导入SQL Server之前自动删除Excel中的行

[英]Auto Delete rows in Excel before import to SQL Server


I am trying to import an excel file to an SQL Server Database.

我正在尝试将excel文件导入SQL Server数据库。

Concern is SQL Server does not recognize the excel file because the first row contains a title and not the table column headers. The table headers are in row 3.

关注是SQL Server不识别excel文件,因为第一行包含标题,而不是表格列标题。表标题在第3行。

enter image description here

The excel file (.xlsx) is a report extraction from the ITSM tool (generates every 30 minutes) saved on a folder path.

excel文件(.xlsx)是从ITSM工具(每30分钟生成一次)中提取的报告,保存在文件夹路径中。

From what I've read from the forums, macros can be implemented however the file needs to be opened manually in order for this to take effect.

从我在论坛上看到的内容来看,宏可以实现,但是需要手动打开文件才能实现。

Is there a way to remove the 2 rows in excel without any manual interaction? I have the general idea on how to automate the import but I would like the Excel file to be in the correct format.

是否有一种方法可以删除excel中的2行,而不需要任何手工交互?我对如何自动导入有一个大致的想法,但是我希望Excel文件的格式是正确的。

PS. I am using SQL Server 2012 Express

我正在使用SQL Server 2012 Express

Thanks!

谢谢!

Other Sources:

其他来源:

https://www.mrexcel.com/forum/excel-questions/511902-delete-rows-without-open-files.html

https://www.mrexcel.com/forum/excel-questions/511902-delete-rows-without-open-files.html

2 个解决方案

#1


1  

Create a procedure and schedule its execution according to your ITSM tool jobs, to automate this. Use OPENROWSET to read excel as follows:

创建一个过程,并根据您的ITSM工具作业安排它的执行,从而实现自动化。使用OPENROWSET读取excel如下:

SELECT *
FROM OPENROWSET(
    'Microsoft.ACE.OLEDB.12.0',
    'Excel 12.0;HDR=YES;Database=c:\kunal\test.xlsx',
    'SELECT * FROM [sheet1$A3:Z]'
);

Something like this should help you. In the above code, I am skipping first two rows, starting reading from cell A3 of the excel and HDR=YES represents that my data has titles.

像这样的东西应该对你有帮助。在上面的代码中,我跳过了前两行,从excel的cell A3开始读取,而HDR=YES表示我的数据有标题。

#2


0  

I have found this article online. Moving Data from Excel to SQL Server, and eliminates the 2 undesired rows on the excel.

我在网上找到了这篇文章。将数据从Excel移动到SQL Server,并消除Excel上的两个不需要的行。

https://www.simple-talk.com/sql/ssis/moving-data-from-excel-to-sql-server-10-steps-to-follow/

https://www.simple-talk.com/sql/ssis/moving-data-from-excel-to-sql-server-10-steps-to-follow/


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2017/01/19/534ffeb4831f76b393e22c5437d517a6.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号