SSIS with Excel Source - Generically specify first worksheet?

I have an SSIS package that is reading an Excel source to pipe it to a table in my SQL Server database.
In the Data Flow task, I was able to rename the Name field generically, but with the Custom Properties, I have to specify the rowset name, otherwise the task blows off.
How can I generically specify, hey, do the open row set on the first sheet?

Hi J.D. Walker,
1. You can use the following method to extract data of the first Sheet of the Excel file:
2. Create a string type variable SheetName, and set its default value to the name of the first worksheet followd by $ symbol such as “Sheet1$”. The worksheet name must be valid to obtain the metadata for the OLE DB Source at design-time.
3. Use the ADO.NET Schema Rowset Enumerator of a Foreach Loop Container to get each sheet name of the Excel file, and store the value in variable SheetName by mapping the variable to Index 2.
4. Create an Int type variable Counter, and set its default value to 0.
5. Add a Script Task to the Foreach Loop Container, set the variable Counter as the ReadWriteVariables, and modify the public void Main() function as follows:
public void Main()
// TODO: Add your code here
int cnt = Convert.ToInt32(Dts.Variables["User::Count"].Value.ToString());
cnt++;
Dts.Variables["User::Count"].Value = cnt;
Dts.TaskResult = (int)ScriptResults.Success;
6. Join the Script Task the Data Flow Task, and set the Precedence Constraint as follows:
Evaluation operation: Expression:
Expression: @[User::Count]==1
7. In the Data Flow Task, add an OLE DB Source, create an OLE DB Connection Manager (Native OLE DB\Microsoft Jet 4.0 OLE DB Provider for XLS file, or Native OLE DB\Microsoft Office 12.0 Access Database Engine OLE DB Provider for XLSX file, and set the Extended
Property to Excel 8.0 for XLS file or Excel 12.0 for XLSX file).
8. Set the Data access mode of the OLE DB Source to “Table name or view name variable”, and set the variable to User::SheetName.
In addition, if you want to extract data from the first N worksheets, you can set the expression of the Precedence Constraint above to @[User::Count]<N+1 (replace N with the real number).
Regards,
Mike Yin
TechNet Community Support

Similar Messages

  • Dynamic columns with Excel Source?

    I have Excel file number 1 with columns A ja B.
    I have database table with columns A,B,C,D,E,F,G,H etc. (there are 100 columns)
    I know how to import normally data with Excel Source and OLE DB Destination with Excel file 1.
    Now I have new need.
    I should be able to import dynamically Excel files with any combination of columns.
    It should be automatic import with For Each Container.
    When new files like below is imported, I should not be make any changes to SSIS.
    Excel 2) Columns A, G, X (so column A data must be added to column A in database etc)
    Excel 3) Columns B, C, G, Y (so column B data must be added to column B in database etc)
    Excel 4) Columns D, X
    IS THIS POSSIBLE WITH SSIS? HOW?
    CUSTOM CODE IS NEEDED? ANY POINTERS TO SOLUTION?
    Kenny_I

    How you are going to deal with the rows here?
    For example, 
    Excel 2) Columns A, G, X (so column A data must be added to column A in database etc)
    when Excel 3 files are processing are you going to update the record that you added in Excel
    2.
    Excel 3) Columns B, C, G, Y (so column B data must be added to column B in database etc)
    Excel 4) Columns D, X
    when Excel 4 files are processing what is your scenario for column X which you just added in
    Excel 2. Are you going to update it or add new rows here.
    As Arthur has suggested generating your package in code seems the way to go for but before that you need
    to think about all the scenarios.
    Vikash Kumar Singh || www.singhvikash.in

  • Repair Problem with Excel Removing All But First External SQL Query Tables

    We have an Excel 2007 XLSX workbook that we created for doing some business analysis from the SQL database that contains data from our MRP system. It started as a single sheet with one data connection running a SQL query. The data comes into
    the spreadsheet as a table and there are some basic row and column sums being done.
    After getting the first version up and running without problems, we decided to add some additional sheets to the same workbook. Since each of these additional sheets had only slight variations to the SQL query and the formatting was all to be the same, we
    simply copied the first sheet and modified the data connection for each successive sheet (each copy automatically created a copy of the data connection as well). Everything seemed to be up and running properly, so we saved and closed the workbook.
    A little bit later, the same workbook was re-opened and Excel reported that "Excel found unreadable content in '<file name>'. Do you want to recover the contents of this workbook? If you trust the source of this workbook, click Yes." If Yes
    is clicked, then Excel indicates the repairs that were made. Only one was made for each sheet beyond the first and that was "Removed Part: /xl/queryTables/queryTable2.xml part. (External data range)". The result was that the data connection
    was deleted from every sheet other than the first and only static data left in place.
    We thought it might have actual been some corruption, so we deleted the static sheets and recreated them the same way. After saving and closing, re-opening the file resulted in the same problem. It seems that Excel is somehow saving data that it can't read
    when it opens. I would think it could be something in the SQL query, but all sheets have essentially the same SQL query, so I'm not sure why the first sheet survives. As a result, I think it must be something that it does in copying the sheet and the corresponding
    data connections, but I'm not sure.
    I think this might be some kind of bug, but would like to know if anyone else has encountered a similar problem and found a solution. A few internet searches didn't give me much to check out.
    Thanks in advance,
    indyvql

    KR,
    Thanks for your response. I don't think it applies in this case since the file was created brand new in Excel 2007 and used in the same. There was no 3rd-party program involved. I'm also not migrating from 2003 to 2010 as the stellarinfo.com article
    suggests. Some of the other suggestions there also don't make any difference as all the data links are lost on opening the worksheet, so copying and pasting doesn't do any good.
    I tried to create a simple example by creating a new workbook with a sheet with a very simple SQL query ("select * from X where a > b"), but in that example it worked fine. I'm guessing there is something key about the much more complex SQL query
    in my original file with the problem, but I'm not sure why it would only affect copies of the data connection and not the original data connection itself.
    Thanks,
    indyvql

  • Excel Source cannot find sheet when using Foreach Loop Container

    I have SQL Server 2012 SSIS. I need help with Foreach Loop container.
    1) I have C:\\Excel\ folder and multiple Excel.xlsx files are stored there to be imported
    2) I have Foreach Loop Container
    -Foreach File Enumerator is selected
    -Expressions are empty
    -Folder is set as  C:\\Excel\
    -Files is *.*
    -Variable is created. User::Filename, 0
    2) I have created variable FileName, String,0
    3) I have Excel Connection Manager
    -ExcelFilePath = @[User::FileName]
    4) I have data flow task with Excel Source and OLE DB Destination
    Error occured with Execute:
    [Excel Source [2]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E37.
    [Excel Source [2]] Error: Opening a rowset for "SheetName$" failed. Check that the object exists in the database.
    Kenny_I

    Hi Kenny_I,
    The issue occurs because you have not specified a valid value for the variable @FileName. The error persists even if we set the “DelayValidation” property of the Excel Connection Manager to True. After you assign a value like “C:\Excel\Test1.xlsx” (without
    quotes) to the variable, the package should work fine.
    Reference:
    http://www.bidn.com/blogs/mikedavis/ssis/625/loop-through-excel-file-in-ssis
    Regards,
    Mike Yin
    If you have any feedback on our support, please click
    here
    Mike Yin
    TechNet Community Support

  • Matrix with excel output?

    Hi
    I was wondering if creating a matrix report with excel output is possible?
    _*                                                                                                                                                                           

    Hi
    Are you referring to creating matrix report with excel output by specifying
    destype=localfile desformat=DELIMITED delimited_hdr=yes?
    Also, I am aware that we can create well formatted excel output with jsp reports. Has anyone given that a try with matrix reports or only rdf would work?
    Thx!

  • Regarding ssis - skip first 10 rows in excel source

    Hi,
       I have received an Excel Source file, but the first 10 rows have only company information; actual data starts from Row 11.  How will you skip the first 10 rows and start reading from row 11

    Hi Koteswararao,
    If the first row includes the column names, and the first 10 rows you said don’t include the first row. That means you want to skip the rows from 2 row to 10 row, then we can union two Excel sources to work around this issue. For more details, please refer
    to the following steps:
    Set the FirstRowHasColumnName property of the Excel Connection Manager to False, so the first row stores the column names in the sheet.
    Drag two Excel Sources to the Data Flow Task.
    In the Excel Source, use the SQL command below to replace the former(supposing there are three columns in the Excel sheet: col1, col2 and col3):
    SELECT F1 AS col1,F2 AS col2, F3 AS col3  FROM
    [sheet$A1:C1]
    In the Excel Source 1, please type the SQL command below (note that the ‘n’ means the number of rows in the sheet):
    SELECT F1 AS col1,F2 AS col2, F3 AS col3  FROM
    [sheet$A11:Cn]
    Drag a Union All component to the same task, then union those two Excel Sources.
    If there are any other questions, please feel free to ask.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • Error when trying to use excel source editor in SSIS 2012

    I am using SQL Server 2012. This error occurs when I try o select the name of excel sheet in excel source editor in SSIS 2012.  I am on win 7 64 Bit machine. I have office 2010. 
    Could not retrieve the table information for the connection manager 'Excel Connection Manager'. Failed to connect to the source using the connection manager 'Excel Connection Manager'. 
    Thanks in advance

    Hi Satya, I even tried installing 32-bit ACE OLE DB providers even before posting this and I do not have permissions
    to install it on my machine. I will work with IT Dept and update the status on how it goes. 
    Thanks

  • Failed to acquire DAS with data sources that match the specified OCE

    Please help, Thank you all.
    We are migrating Oracle databases from Windows to Linux servers. Currently, I have no problem to use my desktop Hyperion Intelligence Designer 8.5 with new oce file to connect to Linux. However, I published the same oce file to Hyperion Performance Suite 8.5 then I got “Sever Error [2018]: Failed to acquire Data Access Service with data sources that match the specified OCE”.
    I launched Service Configurator, in the “Local Service Configurator - DAS1_host”, the “Database JDBC URL is point to Linux server. Also, I added ODBC connection to Oracle database on Linux in the “Properties of Data Access Service: DAS1_host’s Data Source”. Database of JDBC URL in BI1_host, AZ1_host, PUB1_host, SM1_host, LS1_host, UT1_host, BPS1_host, AN1_host are also point to Linux server.
    The “Remote Service Configurator” has ES1_host’s” Storage” with JDBC URL point to Linux server. The same for RM1_host’s and NS1_host’s “Storage” with JDBC URL point to Linux server.
    Is there some missing configuration on the server? Thank you in advance.

    You should login to my oracle support to look into this ID.
    This is the solution mentioned
    Solution
    1) In the .profile file, you will find the definition of the LD_LIBRARY_PATH variable. However, the path to 64 bit libraries is probably appended before the path to the 32 bit libraries(%ORACLE_HOME%/lib32). Therefore, please reverse the order in the definition so that the 32 bit libraries get loaded before the 64 bit libraries.
    Then, restart all services.
    2) Oracle 9.2 was the first Oracle release which defaults to using the 64 bit libraries in the 'lib' directory and the 32-bit libraries that we need are in the 'lib32' directory.
    Therefore, please have the%ORACLE_HOME%/lib32 placed in front of the LD_LIBRARY_PATH environment variable definition.Then, restart all services.
    3) Please check that users have read and write access to the files located in the %ORACLE_HOME%/lib32 folder.
    4) Check the permissions of the libclntsh.a file(located in the %ORACLE_HOME%/lib32 folder) are set to rwxr-xr-x
    5) Recreate the OCE connection in DAS and restart DAS in CMC.
    6) Restart all the BIPlus Services and process the query.

  • Excel source multiple column values to oledb destination single column in ssis 2012

    Excel sheet has 4 columns which is filled with data till 500 rows on each column. I want to insert those excel data into single column(PolicyIds) and am using oledb destination. In excel souce i dont hav any column header. Can anyone suggest me how can i do
    this effectively. (May be i can use script task to get range of data and use it as SQL variable). Is there any best approaches.
    Sample excel
    A          B             C             D
    1001     1005       1009        1013
    1002     1006       1010        1014
    1003     1007       1011        1015
    1004     1008       1012        1016

    Inside Excel Source, use Data Access Mode - SQL Command as below:
    select F1 from [Sheet1$] where F1 is not null
    union all
    select F2 from [Sheet1$] where F2 is not null
    union all
    select F3 from [Sheet1$] where F3 is not null
    union all
    select F4 from [Sheet1$] where F4 is not null
    -Vaibhav Chaudhari

  • Problem with transformations involving excel source or destination

    I am using SQL server 2008 R2.None of the transformations involving excel source or destination is working fine.What can be done?

    Hi Sapna,
    According to your description, you are
    experiencing the issue that transformations involving excel source or destination is working fine, right?
    It's hard to give you the exactly reason that cause this issue based on the limited information. Here are some articles that use Excel as the source or destination, please refer to the link below.
    http://www.mssqltips.com/sqlservertutorial/211/sql-server-integration-services-ssis-data-flow/
    http://www.sqlshack.com/using-ssis-packages-import-ms-excel-data-database/
    If the issue persists, please provide us more information about your issue, so that we can make further analysis.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Why does the Excel source think my query has parameters?

    Part of my current project involves converting an Excel spreadsheet having a number of tabs into an equal number of pipe-delimited flat files using an SSIS package. I've got one data flow task that opens up the excel file and selects the names of all the
    tabs into and object variable. A second data flow task inside a for each loop attempts to read the first 32 columns from each tab. The excel source in the second data flow task is set up to use a sql command from a variable, and the variable is an expression
    that substitutes the tab name into an otherwise-constant sql statement like this:
    SELECT F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15, F16, F17, F18, F19, F20, F21, F22,
    F23, F24, F25, F26, F27, F28, F29, F30, F31, F32 FROM [Securities Portfolio$]
    The "First row has column names" box in the excel connection manager is not marked.
    Here's the thing: this works for most of the tabs. The one above works. However, three of them are causing the following error:
    The SQL command requires 2 parameters, but the parameter mapping only has 0 parameters.
    I've modified the package to print all of the SQL statements used in the log file. The only difference is in the tab name. None have any question marks, which is what I thought SSIS used to mark parameters. I can't figure out what causes this, or even how
    thw failing SQL queries are different than the ones that work:
    SELECT F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15, F16, F17, F18, F19, F20, F21, F22,
    F23, F24, F25, F26, F27, F28, F29, F30, F31, F32 FROM [Capital - Part1$]SELECT F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15, F16, F17, F18, F19, F20, F21, F22,
    F23, F24, F25, F26, F27, F28, F29, F30, F31, F32 FROM [Capital - Part2$]SELECT F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15, F16, F17, F18, F19, F20, F21, F22,
    F23, F24, F25, F26, F27, F28, F29, F30, F31, F32 FROM [Securities Sources$]
    Any help would be appreciated.

    OK, I figured it out, and will write it here in case someone else has a similar issue, because I spent several hours on Google trying to figure out what was going on.
    It turns out that not all of the worksheets actually HAVE 32 columns. It did not occur to me at first that this could be an issue, because when you open an Excel file in Excel, there are always more columns if you just scroll over more. However, the way
    Microsoft Jet reads Excel files, each worksheet has a fixed number of columns.
    The worksheets that were causing the issue were the ones that have fewer than 32 columns. If there are only 30 columns and I try to select F32, Microsoft Jet assumes that F32 is supposed to be the name of a parameter. As far as I can tell, SSIS 2008 does
    not allow you to set up parameter values for use with Jet, but Jet will nevertheless parse your query and determine that there are parameters needed if it can't find some of the column names.
    To get around this, I changed the step that gets the worksheet names to also return the number of columns in each worksheet, and then changed the query to return NULL for any columns that don't exist. So, for a worksheet having only 30 columns, I now run
    this:
    SELECT F1, F2, F3, F4, F5, F6, F7, F8, F9, F10, F11, F12, F13, F14, F15, F16, F17, F18, F19, F20, F21, F22,
    F23, F24, F25, F26, F27, F28, F29, F30, NULL AS F31, NULL AS F32 FROM [Capital - Part1$]
    And that fixes it.

  • DI: Unable to read Excel source

    Hi,
    We use BusinessObjects Data Services XI 3.1, version 12.1.1 on UNIX Server.We have created BoExcelAdapter to read Excel source and we were not facing any issues in reading the Excel files so far.
    Yesterday when we ran the job to read a new excel file, we received the error message 'Could not find worksheet ... in file ..'.
    But the excel file has the specified worksheet.
    Could you please guide me as to what has caused such an error and how to resolve this.
    Thanks,
    RaajMahee

    Hi RaajMahee
    Cause
    On Unix, the excel adapter uses the apache poi browser to read the spreadsheet.
    When the adapter tries to open the spreadsheet with the poi api, the poi api chokes and gets an exception of ArrayIndexOutofBound.
    POI library does not support a feature found in the workbook
    Resolution
    This problem had already been addressed in the latest poi patch release, poi-3.2-FINAL-20081019.jar.
    1. Download the attached file poi-3.7-20101029 and rename it to poi-FINAL-3.7-20101029.jar
    2. Copy the poi-FINAL-3.7-20101029.jar file to your $LINK_DIR/lib directory of your Unix/Linux server.
    3. Through the Data Services Management Console, stop the excel adapter.
    4. Using the Data Services Management console, modify the Excel Adapter's class path and replace the reference to poi-         2.5.1-final-20040804.jar with its full path with poi-FINAL-3.7-20101029.jar with its full path.
    5. Save and restart the adapter.
    6. Try again processing the Excel file with formulas.
    if you want to download the  poi-3.7-20101029 file just follow the link
    [https://websmp130.sap-ag.de/sap(bD1lbiZjPTAwMQ==)/bc/bsp/sno/ui_entry/entry.htm?param=69765F6D6F64653D3030312669765F7361706E6F7465735F6E756D6265723D3132393634353426]
    if you are unable to access this link(Why because it ask login credentials) just put your e-mail and i will send the zip file.
    Thanks
    Prasad

  • Excel source Plus

    HI all,
    Can anyone explain me how to use excel source plus, if possible please explain with the sreenshots.
    i'm confussed of using Named range,Raw value,Formula!!!!
    Thanks in advance, appreciate your help!!!!!

    Hi Vandana,
    According to your description, when you select Named Range to specify a named range within the Source Excel file, the preview page displays nothing no matter which Output selected in Excel Source Plus component.
    After testing a similar issue in my environment, I can reproduce it. Since this component is a SSIS Third-Party Component, I’m not familiar with it. As to this issue, please post it to this forum:
    https://groups.google.com/forum/#!forum/cozyroc
    Besides, if possible, please provide us more information about your requirement? I think we can directly use built-in Excel Source component to achieve your requirement.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • SSIS 2012 EXCEL Connection manager error

    Hello all,
    When i try to make any excel connection manager in ssis 2012 its show below error.
    "Could not retrieve the table information for the connection manager 'Excel Connection Manager'. Failed to connect to the source using the connection manager 'Excel Connection Manager' in ssis 2012 error"
    I try for it EXCEL source and EXCEL destination. Both time same error happen. 
    Before i m use ssis 2008 then its work well bt after install 2012 its start this problem. I m also change debug 64 bit in false from true.
    Thanks for help

    Hi is there any way to install 32 ACE OLE DB in 64 bit system without uninstall my other software .
    I tried yesterday to instal 32 bit ACE but its told me u need to uninstall 64 bit software first :(
    thanks
    When using the command line, you can force the installation of the 32-bit version while the 64-bit version has already been installed.
    http://blogs.lessthandot.com/index.php/datamgmt/dbprogramming/mssqlserver/force-ace-installation/
    MCSE SQL Server 2012 - Please mark posts as answered where appropriate.

  • SSIS XML Data Source - worked in BIDS, can't read XML in SSDT

    I have an SSIS 2008 package built in BIDS (2008) that uses a series of XML locations (similar to
    http://corpslocks.usace.army.mil/lpwb/xml.tonnage?in_river=AG&in_lock=42&in_mon_yr=092013) to get tonnage information and load it into a SQL Server 2008 R2 database. This has been running daily without error for over 60 days. I am now migrating
    this to SSIS 2012 using SQL Server Data Tools and I am having difficulty reading the XML into the database.
    The package does the following (it is pretty simple):
    1. read the URLs (there are 200) from a database view into a variable object
    2. a for each loop container that loops through the variable object, gets the data from each URL (the XML URL is stored as a variable) and loads it into the database
    The BIDS package still works great. I first used the converter to migrate to 2012. I then recreated a package with exactly the same settings as BIDS. No dice either way. I also tried using a local xsd file, then using one inline. SSDT will recognize all
    of the columns correctly when I use inline, but neither method is capable of reading the data into a table.
    I know the package is going to the addresses, all of the URLs show up in the error logs. The error messages are as follows: "[Load data from tonnage url [47]] Error: The file "http://corpslocks.usace.army.mil/lpwb/xml.tonnage?in_river=AG&in_lock=42&in_mon_yr=092013"
    was not found. Please verify the file path and try again."
    Has anyone run into this and solved it? I think I have tried every possible setting available, with no luck. Any ideas or suggestions are appreciated. Thanks!

    I have an update on this issue. I believe it is a connectivity issue or possibly a setting in SSDT. 
    I can access the remote XML file location through my browser. I have downloaded the XML from the remote location and my package runs using the local XML file perfectly. I have BIDS 2008 installed on the same machine and it works without a problem (using
    the remote XML location). This last piece makes me think there is a network setting or something in SSDT.
    Does anyone have any additional troubleshooting advice or other suggestions? My error output is included below. 
    Thanks!
    Information: 0x40043006 at Data Flow Task, SSIS.Pipeline: Prepare for Execute phase is beginning.
    Error: 0xC020F440 at Data Flow Task, XML Source [31]: The file "http://corpslocks.usace.army.mil/lpwb/xml.lockqueue?in_river=GI&in_lock=01" was not found. Please verify the file path and try again.
    Error: 0xC02090D0 at Data Flow Task, XML Source [31]: The XML Source was unable to read the XML data.
    Error: 0xC0047019 at Data Flow Task, SSIS.Pipeline: XML Source failed the prepare phase and returned error code 0xC02090D0.
    Information: 0x4004300B at Data Flow Task, SSIS.Pipeline: "ADO NET Destination" wrote 0 rows.
    Information: 0x40043009 at Data Flow Task, SSIS.Pipeline: Cleanup phase is beginning.
    Task failed: Data Flow Task

Maybe you are looking for

  • Can't send mail with WiFi on-ok with only 3G running

    Using AT&T 3G network, Time Warner RoadRunner via Airport Express. I can download ok with both wifi and 3G running. But when I try to send, the msg just sits in th Outbox. IPhone 4 with latest OS. I'm using MS Entourage on my iMac as POP server.  I c

  • LMS 3.2.1 Backup error

    Hi We have recently installed a new version of LMS 3.2, and everything is working fine. but till now the backup process hasn't started correctly to a directory on our drive D, and once I start a backup process, I recieved the following error ERROR (1

  • MR02 exemption to certain Document Types

    Hi all, Greetings of the Day Iam having a typical problem, I have an Invoice for which TDS has been deducted & TDS Document is generated. Both the Invoice & TDS Documents are Flagged with Payment Block "R". When I released the Invoice Document and tr

  • Is Maverick affecting why I can't open any of my protected excel files?

    I have various protected excel files which until yesterday (11/12/2013) I could ope. Today I can't. First I thought because I was typing it incorrectly so I tried other excel files that have different passwords and the result. was the same "The passw

  • Sales order with refernce to contracts in different sales area

    Hi Gurus, I am creating a sales order with reference to a contract.I am making sales order sold-to-party as release order. so my Contract sold-to-party and the sales order sold-to-party are different but both belong to same sales area. In the above c