script task in SSIS to import excel spreadsheet

后端 未结 1 941
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-06 23:24

I have reviewed the questions that may have had my answer and unfortunately they don\'t seem to apply. Here is my situation. I have to import worksheets from my client. I

相关标签:
1条回答
  • 2020-12-06 23:44

    I put together a post describing how I've used a Script task to parse Excel. It's allowe me to import decidedly non-tabular data into a data flow.

    The core concept is that you will use a the JET or ACE provider and simply query the data out of an Excel Worksheet/named range. Once you have that, you have a dataset you can walk through row-by-row and perform whatever logic you need. In your case, you can skip row 1 for the header and then only import columns A, C, D and AA.

    That logic would go in the ExcelParser class. So, the Foreach loop on line 71 would probably be distilled down to something like (code approximate)

    // This gets the value of column A
    current = dr[0].ToString();
    // this assigns the value of current into our output row at column 0
    newRow[0] = current;
    
    // This gets the value of column C
    current = dr[2].ToString();
    // this assigns the value of current into our output row at column 1
    newRow[1] = current;
    
    // This gets the value of column D
    current = dr[3].ToString();
    // this assigns the value of current into our output row at column 2
    newRow[2] = current;
    
    // This gets the value of column AA
    current = dr[26].ToString();
    // this assigns the value of current into our output row at column 3
    newRow[3] = current;
    

    You obviously might need to do type conversions and such here but that's core of the parsing logic.

    0 讨论(0)
提交回复
热议问题