Jump to content

Module to import a xls or csv file into a xls


 Share

Recommended Posts

Hello,

I search a module which can import data of a xls or csv file into an other xls file

 

ex :

 

i have data in a xls file named data.xls (my data located in tab Sheet1)

 

i want to import all into an other xls file name suivi.xls (in tab Import), before delete all data of this tab

 

anyone can help me please?

 

Thank you for all

sorry for my english

 

Link to comment
Share on other sites

Function _Excel_RangeCopyPaste is what you are looking for. Check example 2 in the help file.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Ok thank you it's running

can we delete line with conditions before the copy ?

 

ex : delete lines where columm A:A = "0"

 

thank you

 

a part of my code

 

Case $GUI_EVENT_CLOSE
            Fin()


         Case $ButtonEXPORT

            GLOBAL $source = FileOpenDialog("", "C:\Users\", "(*.xls)", 1 + 4 )
            GUICtrlSetState($ButtonEXPORT, $GUI_DISABLE)
            GUICtrlSetState($ButtonSUIVI, $GUI_ENABLE)
            ;msgbox(0, "", $source)

         Case $ButtonSUIVI

            GLOBAL $destination = FileOpenDialog("", "C:\Users\", "(*.xlsx)", 1 + 4 )
            GUICtrlSetState($ButtonSUIVI, $GUI_DISABLE)
            GUICtrlSetState($ButtonImport, $GUI_ENABLE)
            ;msgbox(0, "", $destination)
         Case $ButtonImport

            Import()

EndSwitch
Wend
endfunc





Func Import()

; Crée un objet application et ouvre un classeur exemple
Local $oAppl = _Excel_Open()
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)


; Ouvre le classeur de destination
Local $oWorkbook2 = _Excel_BookOpen($oAppl, $destination, False)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example", "Error opening workbook '" & @ScriptDir & "\Extras\_Excel3.xls'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oAppl)
    Exit
 EndIf



; Ouvre le classeur source
Local $oWorkbook1 = _Excel_BookOpen($oAppl, $source, True)
If @error Then
    MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example", "Error opening workbook '" & @ScriptDir & "\Extras\_Excel1.xls'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
    _Excel_Close($oAppl)
    Exit
EndIf

sleep(500)

; ************************************************** ***************************

;définition de la source de la copie
Local $oRange1 = $oWorkbook1.Worksheets("export_optimus_PIC_J2013_JRecol").Range("A:G")
Local $oRange2 = $oWorkbook1.Worksheets("export_optimus_PIC_J2013_JRecol").Range("I:GG")

;définition de la destination de la copie
_Excel_RangeCopyPaste($oWorkbook2.Worksheets("Export OPTIMUS"), $oRange1, "A:G")
_Excel_RangeCopyPaste($oWorkbook2.Worksheets("Export OPTIMUS"), $oRange2, "I:GG")
If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example 2", "Error copying cells." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeCopy Example 2", "L'import est terminé avec succès.")

sleep(500)
Fin()
EndFunc

 

Edited by stormlolz
Link to comment
Share on other sites

How to filter and delete rows can be found here:

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...