2017-02-27 86 views
2

我有一個文件夾可以接收到.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 

回答

0
+0

是一個VB腳本?對不起,我剛接觸腳本 –

+0

@Syed Jafri如果您不熟悉腳本或創建宏,我認爲您可以使用某種軟件。只需在Google http://ccm.net/download/download-18703-convert-xls-to-xlsx上找到此鏈接即可。請檢查這是否可以幫助。 – Tajinder

0

您必須添加一個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

相關問題