Import data from Excel using SSIS without knowing sheet name

后端 未结 6 1640
情话喂你
情话喂你 2021-01-04 22:39

I have a spreadsheet that is updated by another server (out of my control) and I need to automate bringing that data into SQL 2005. The data is always the first page of the

6条回答
  •  星月不相逢
    2021-01-04 23:12

    I would script out the Worksheet name to a SSIS User Variable. If you are not opposed to inserting a script task into your SSIS package try this: (Based on link text )

    Excel.Application xlApp = new Excel.ApplicationClass();
    Excel.Workbook xlWorkBook = xlApp.Workbooks.Open(".xls", 0, xlWorkBook true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
    // Look up worksheet by index
    Excel.Worksheet xlWorkSheet =(Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
    
    user::worksheetname = xlWorkSheet.Name;
    
    /* Do clean up.  Working with COM object */
    

提交回复
热议问题