I have group of excel files in a folder. excel file name will be like
ABC 2014-09-13.xlsx
ABC 2014-09-14.xlsx
ABC 2014-09-15.xlsx
I need to get the data from latest excel file and load it into the table using ssis package.
I have group of excel files in a folder. excel file name will be like
ABC 2014-09-13.xlsx
ABC 2014-09-14.xlsx
ABC 2014-09-15.xlsx
I need to get the data from latest excel file and load it into the table using ssis package.
This may not be the shortest answer, but will help you.
Steps:
For-each loop, to fetch all the excel sheets. Insert all the excel sheet names to a table.MAX() among Excel dates.Fore-each loop. Just like the 1st loop, pick all the excel sheets 1 by 1, compare each file name with Variable value. Load the excel which matches it.As this is duplicate question, I will put answer anyway with some changes or additional info.
ReadOnlyVariables = User::MainDir and ReadWriteVariables = User::ExcelFileinto Main
 string fileMask = "*.xlsx";
 string mostRecentFile = string.Empty;
 string rootFolder = string.Empty;
 rootFolder = Dts.Variables["User::MainDir"].Value.ToString();     
 System.IO.DirectoryInfo directoryInfo = new System.IO.DirectoryInfo(rootFolder);     
 System.IO.FileInfo mostRecent = null;
 System.IO.FileInfo[] legacyArray = directoryInfo.GetFiles(fileMask, System.IO.SearchOption.TopDirectoryOnly);    
 Array.Sort(legacyArray, (f2, f1) => f2.Name.CompareTo(f1.Name));
 mostRecent = legacyArray[legacyArray.Length - 1];
 if (mostRecent != null)
 {
      mostRecentFile = mostRecent.FullName;
 }
 Dts.Variables["User::ExcelFile"].Value = mostRecentFile;
 Dts.TaskResult = (int)ScriptResults.Success;`
@[User::ExcelFile] Excel Connection Manager you created before, Data access mode change to SQL command and add this line (make sure, that excel file sheet name is Sheet1): SELECT * FROM [Sheet1$]. Also check if all necessary columns selected in Columns tab.That's all you need to do to insert excel...