且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何自动化Excel 2013工作表中列标题的重命名使用C#

更新时间:2023-02-08 21:29:39

由于包含空格的字段名称不会阻止导入在SSIS包中工作,因此字段名称从工作表列标题可以在以后在表中创建和填充后更新。这可以使用sp_rename通过TSQL来完成。以下代码为数据库中包含一个或多个空格的每个字段生成sp_rename。

Since field names containing spaces will not prevent the import from working in an SSIS package, the field names originating from the worksheet column headers can be updated later after they're created in the tables and populated. This can be done with TSQL using sp_rename. The following code generates the sp_rename for every field in the database containing one or more spaces. Then all that is required is to copy and past from the Results it generates into the query and run them all.

SELECT 'EXEC sp_rename '''+table_name+'.['+column_name+']'','''+replace(column_name,' ','_')+''',''COLUMN''' 
FROM information_schema.columns
WHERE column_name like '% %'

使用C#任务脚本收集工作表列标题。

It would still be nice to know how to gather the worksheet column headers using the C# Task Script.