vb.net - Copy information from a Excel file to another Excel file using SSIS VB2010, What wrong with these code -


i making ssis will:

  1. copy data sql server sql excel file
  2. then excel file preexisting excel file formulas

i did first part --copy sql excel1-- works fine. tried copy excel1 file other using script task in visual basic 2010.

i want check program , tell me wrong in trying copy information excel1 excel2. when executed error dts scrip task runtime error , nothing.

public sub main()     dim oexcel microsoft.office.interop.excel.application,         oexel2 microsoft.office.interop.excel.application      dim obook microsoft.office.interop.excel.workbook,         obook2 microsoft.office.interop.excel.workbook,         osheet microsoft.office.interop.excel.worksheet,         osheet2 microsoft.office.interop.excel.worksheet      'programing      'from  excel spreadsheet      oexcel = new microsoft.office.interop.excel.application()     oexcel.visible = false     obook = new microsoft.office.interop.excel.workbook("c:\documents\at1.xls")     osheet = directcast(obook.sheets("sheet1"), microsoft.office.interop.excel.worksheet)       'to excel spreadsheet      oexel2 = new microsoft.office.interop.excel.application()     oexel2.visible = false     obook2 = new microsoft.office.interop.excel.workbook("c:\documents\a2.xls")     osheet2 = directcast(obook2.sheets("january"), microsoft.office.interop.excel.worksheet)      osheet2.range("b11", "r16").value = osheet.range("a3", "q8").value      'close       osheet = nothing     obook.close(false)     oexcel.quit()      osheet2 = nothing     obook.close(false)     oexel2.quit()      dts.taskresult = scriptresults.success   end sub 

you should not use excel interop in ssis implies must install excel on server , not recommended. trick...

public sub main()      dim oexcel microsoft.office.interop.excel.application      dim obook microsoft.office.interop.excel.workbook, _         obook2 microsoft.office.interop.excel.workbook, _         osheet microsoft.office.interop.excel.worksheet, _         osheet2 microsoft.office.interop.excel.worksheet      oexcel = new microsoft.office.interop.excel.application()     oexcel.sheetsinnewworkbook = 1     oexcel.displayalerts = false     oexcel.visible = false      obook = oexcel.workbooks.open("c:\documents\at1.xls")     osheet = obook.sheets("sheet1")      obook2 = oexcel.workbooks.add()     osheet2 = obook2.worksheets.item(1)     osheet2.name = "january"      osheet2.range("b11", "r16").value = osheet.range("a3", "q8").value      obook2.saveas("c:\documents\a2.xls", microsoft.office.interop.excel.xlfileformat.xlworkbooknormal)      obook.close()     obook2.close()     oexcel.quit()  end sub 

it not choice, i'd use oledb instead.

to overwrite existing workbook then...

public sub main(byval arguments() string)      dim oexcel microsoft.office.interop.excel.application      dim obook microsoft.office.interop.excel.workbook, _         obook2 microsoft.office.interop.excel.workbook, _         osheet microsoft.office.interop.excel.worksheet, _         osheet2 microsoft.office.interop.excel.worksheet      oexcel = new microsoft.office.interop.excel.application()     oexcel.sheetsinnewworkbook = 1     oexcel.displayalerts = false     oexcel.visible = false      obook = oexcel.workbooks.open("c:\documents\at1.xls")     osheet = obook.sheets("sheet1")      obook2 = oexcel.workbooks.open("c:\documents\a2.xls")     osheet2 = obook2.sheets("january")      osheet2.range("b11", "r16").value = osheet.range("a3", "q8").value      obook2.save()      obook.close()     obook2.close()      oexcel.quit()  end sub 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -