将多个.xls文件转换为ssis中的.xlsx
问题描述:
我有一个文件夹可以接收到.xls format
中的多个excel文件。我需要将格式类型更改为.xlsx
以便将Excel数据加载到SQLvia SSIS中。我知道如何使用“文件系统任务”重命名该文件,但适用于特定文件。但我的文件包含一个文件#和日期以及需要保持与源文件相同,我只想要更改文件类型和文件移动到处理文件夹。谁能帮我?将多个.xls文件转换为ssis中的.xlsx
Source Path: C:\Documents\TestFolder
Source File: TestSegRpt_0001_2017_02_22.xls
Destination Path: C:\Documents\TestFolderProcessed
Destination File: TestSegRpt_0001_2017_02_22.xlsx
答
您必须添加一个Script Task
,遍历文件,并使用功能类似下面创建进动目录和转换文件(在Vb.net代码):
Public Sub ConvertXlsToXlsx(ByVal strpath as string)
Dim strDirectory as string = System.IO.Path.GetDirectoryName(strpath) & "Processed"
If Not System.IO.Directory.Exists(strDirectory) Then System.IO.Directory.CreateDirectory(strDirectory)
Dim xl As New Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
xlWorkBook = xl.Workbooks.Open(strpath)
xlBook.SaveAs(strDirectory & "\" & System.IO.Path.GetFilename(strpath) & "x")
xl.Application.Workbooks.Close()
xl.Application.Quit()
End Sub
你的代码如下:
Public Sub Main
Dim strFolder as string = Dts.Variables.Item("FolderPath").Value
Dim strXlsFiles() as string = IO.Directory.GetFiles(strFolder,"*.xlsx",SearchOption.TopDirectoryOnly)
For each strFile as String in strXlsFiles
If strFile.EndsWith("xlsx") The Continue For
ConvertXlsToXlsx(strFile)
Next
End Sub
参考:
+0
@SyedJafri我更新了我的答案看一看 – Hadi
是一个VB脚本?对不起,我刚接触脚本 –
@Syed Jafri如果您不熟悉脚本或创建宏,我认为您可以使用某种软件。只需在Google http://ccm.net/download/download-18703-convert-xls-to-xlsx上找到此链接即可。请检查这是否可以帮助。 – Tajinder