IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Forms Oracle Discussion :

Importation de données Excel avec webutil


Sujet :

Forms Oracle

  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Administrateur de base de données
    Inscrit en
    Septembre 2016
    Messages
    40
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Madagascar

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Septembre 2016
    Messages : 40
    Points : 29
    Points
    29
    Par défaut Importation de données Excel avec webutil
    Bonjour à tous,
    J'ai un petit problème avec importation données excel avec webutil, il marche très bien mais il faut toujours modifier le ficher excel en question par exemple
    - il faut enlever les en-têtes
    - il ne détecte pas les lignes vides, il continue toujours l'insertion, donc à partir du script il faut saisir le mot 'FIN' à la dernière ligne dans l'excel
    voici le code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
     
    DECLARE 
    	application   Client_OLE2.Obj_Type; 
    	workbooks     Client_OLE2.Obj_Type; 
    	workbook      Client_OLE2.Obj_Type; 
    	worksheets    Client_OLE2.Obj_Type; 
    	worksheet     Client_OLE2.Obj_Type;
    	worksheet2    Client_OLE2.Obj_Type;	
    	cell 					Client_OLE2.OBJ_TYPE;
    	args 					Client_OLE2.OBJ_TYPE;
    	cell_value 		varchar2(100);
    	num_wrkshts		NUMBER;
    	wksht_name		VARCHAR2(250);
    	fin 					boolean:=false;
    	j  						integer:=1; 
    	v_fName 			VARCHAR2(250);
    BEGIN 
    DELETE FROM TITRE_EXCEL ;
    	-- Get the name of the file to open
    	--v_fName := 'D:\MyDevelopment\Forms\Samples\WebUtil\Read_Excel\planets3.xls';
    	v_fName := WebUtil_File.File_Open_Dialog(
    							directory_name => 'C:\EXCEL'
    							--,file_name => Get_Form_Property(:System.Current_form,Form_Name)||'.xls'
    							,File_Filter => null
    							,Title => 'Select Client filename to Open.'
    					);
     
    	IF ( v_fName IS NOT NULL ) THEN 
     
    		-- The following sets up communication with the excel spreadsheet
    		-- --------------------------------------------------------------
    		-- Open the OLE application
    		application := Client_OLE2.create_obj('Excel.Application'); 
    		-- Keep the application hidden
    		Client_OLE2.set_property(application,'Visible','false');
     
    		workbooks := Client_OLE2.Get_Obj_Property(application, 'Workbooks');
    		args := Client_OLE2.CREATE_ARGLIST;
     
    		-- Open the selected File
    		-- ----------------------
    		Client_OLE2.add_arg(args,v_fName); 
    		workbook := Client_OLE2.GET_OBJ_PROPERTY(workbooks,'Open',args);
    		Client_OLE2.destroy_arglist(args);
     
    		worksheets := Client_OLE2.GET_OBJ_PROPERTY(workbook, 'Worksheets');
     
    		-- Get number of worksheets
    		-- ------------------------
    		num_wrkshts := Client_OLE2.GET_NUM_PROPERTY(worksheets, 'Count');
    		worksheet := Client_OLE2.GET_OBJ_PROPERTY(application,'activesheet');
     
    		--Go to the first record
    		go_block('ttr_excel'); 
    		first_record; 
     
    		loop
     
    				If :system.record_status <> 'NEW' then	
    		         create_record;
    		  	end if;
     
    		exit when fin ;
     
    			for k in 1..7 loop  --7 fields per record
    				args:= Client_OLE2.create_arglist;
    				Client_OLE2.add_arg(args, j);
    				Client_OLE2.add_arg(args, k);
    				cell:= Client_OLE2.get_obj_property(worksheet, 'Cells', args);
    				Client_OLE2.destroy_arglist(args);
    				cell_value :=Client_OLE2.get_char_property(cell, 'Value');
     
    			if upper(cell_value) = 'FIN' then
     
    				fin:=true;
    					Message('End of Data');
    					exit;
    			end if;
     
    		--Could be done this way also -> 
     
    		/*if k =1 then
    			:dept.deptno:=cell_value;
    		end if;
     
    		if k =2 then
    			:dept.dname:=cell_value;
    		end if;
     
    		if k =3 then
    			:dept.loc:=cell_value;
    		end if;	
    		*/
     
    				--Less code this way ->
    				copy(cell_value,name_in('system.cursor_item'));
    				next_item;
     
    			end loop; --for
     
    			j:=j+1;
    		end loop;--main loop
     
    		-- Release the Client_OLE2 object handles
    		IF (cell IS NOT NULL) THEN 
    			Client_OLE2.release_obj(cell);
    		END IF;
    		IF (worksheet IS NOT NULL) THEN 
    			Client_OLE2.release_obj(worksheet);
    		END IF;
    		IF (worksheets IS NOT NULL) THEN 
    			Client_OLE2.release_obj(worksheets);
    		END IF;
    		IF (worksheet2 IS NOT NULL) THEN 
    			Client_OLE2.release_obj(worksheet2);
    		END IF;
    		IF (workbook IS NOT NULL) THEN 
    			Client_OLE2.release_obj(workbook);
    		END IF;
    		IF (workbooks IS NOT NULL) THEN 
    			Client_OLE2.release_obj(workbooks);
    		END IF;
    		Client_OLE2.invoke(application,'Quit');
    		Client_OLE2.release_obj(application);
    	ELSE
    		Message('No File selected.');
    		message(' ');
    		RAISE Form_Trigger_Failure;
    	END IF;
    commit_form;
    		END;
    Donc comment eviter la suppression du prèmiere ligne (en-tête)
    Comment faire pour qu'il detecte la derniere ligne vide et stop (sans mettre le mot FIN)
    Merci

  2. #2
    Membre régulier
    Inscrit en
    Décembre 2010
    Messages
    211
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 211
    Points : 102
    Points
    102
    Par défaut
    Salut,

    Alors c'est simple il suffit de ne pas commencer par la première ligne et positionner ta variable j à 2 :
    Lors de tes déclarations pour commencer par la seconde ligne par exemple :

    Sinon pour le mot "FIN", il n'est pas nécessaire et comme pour les lignes, tu peux arrêter ta variable colonnes à 6 au lieu de 7 :

    Voilà.

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Administrateur de base de données
    Inscrit en
    Septembre 2016
    Messages
    40
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Madagascar

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Septembre 2016
    Messages : 40
    Points : 29
    Points
    29
    Par défaut
    Merci de me répondre
    pour ça ne marche pas car j'ai besoin de 7 colonnes

    le le mot FIN c'est pas résolu, il a besoin qu'on saisit le mot FIN à la fin de la ligne, pj le message d'erreur
    Images attachées Images attachées  

  4. #4
    Nouveau membre du Club
    Homme Profil pro
    Administrateur de base de données
    Inscrit en
    Septembre 2016
    Messages
    40
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Madagascar

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Septembre 2016
    Messages : 40
    Points : 29
    Points
    29

  5. #5
    Membre régulier
    Inscrit en
    Décembre 2010
    Messages
    211
    Détails du profil
    Informations forums :
    Inscription : Décembre 2010
    Messages : 211
    Points : 102
    Points
    102
    Par défaut
    salut,

    essaye avec ça en enlevant "FIN" du fichier :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    DECLARE 
    	application   Client_OLE2.Obj_Type; 
    	workbooks     Client_OLE2.Obj_Type; 
    	workbook      Client_OLE2.Obj_Type; 
    	worksheets    Client_OLE2.Obj_Type; 
    	worksheet     Client_OLE2.Obj_Type;
    	worksheet2    Client_OLE2.Obj_Type;	
    	cell 					Client_OLE2.OBJ_TYPE;
    	args 					Client_OLE2.OBJ_TYPE;
    	cell_value 		varchar2(100);
    	num_wrkshts		NUMBER;
    	wksht_name		VARCHAR2(250);
    	fin 					boolean:=false;
    	j  						integer:=1; 
    	v_fName 			VARCHAR2(250);
    BEGIN 
    DELETE FROM TITRE_EXCEL ;
    	-- Get the name of the file to open
    	--v_fName := 'D:\MyDevelopment\Forms\Samples\WebUtil\Read_Excel\planets3.xls';
    	v_fName := WebUtil_File.File_Open_Dialog(
    							directory_name => 'C:\EXCEL'
    							--,file_name => Get_Form_Property(:System.Current_form,Form_Name)||'.xls'
    							,File_Filter => null
    							,Title => 'Select Client filename to Open.'
    					);
     
    	IF ( v_fName IS NOT NULL ) THEN 
     
    		-- The following sets up communication with the excel spreadsheet
    		-- --------------------------------------------------------------
    		-- Open the OLE application
    		application := Client_OLE2.create_obj('Excel.Application'); 
    		-- Keep the application hidden
    		Client_OLE2.set_property(application,'Visible','false');
     
    		workbooks := Client_OLE2.Get_Obj_Property(application, 'Workbooks');
    		args := Client_OLE2.CREATE_ARGLIST;
     
    		-- Open the selected File
    		-- ----------------------
    		Client_OLE2.add_arg(args,v_fName); 
    		workbook := Client_OLE2.GET_OBJ_PROPERTY(workbooks,'Open',args);
    		Client_OLE2.destroy_arglist(args);
     
    		worksheets := Client_OLE2.GET_OBJ_PROPERTY(workbook, 'Worksheets');
     
    		-- Get number of worksheets
    		-- ------------------------
    		num_wrkshts := Client_OLE2.GET_NUM_PROPERTY(worksheets, 'Count');
    		worksheet := Client_OLE2.GET_OBJ_PROPERTY(application,'activesheet');
     
    		--Go to the first record
    		go_block('ttr_excel'); 
    		first_record; 
     
    		loop
     
    				If :system.record_status <> 'NEW' then	
    		         create_record;
    		  	end if;
     
    		exit when fin ;
     
    			for k in 1..7 loop  --7 fields per record
    				args:= Client_OLE2.create_arglist;
    				Client_OLE2.add_arg(args, j);
    				Client_OLE2.add_arg(args, k);
    				cell:= Client_OLE2.get_obj_property(worksheet, 'Cells', args);
    				Client_OLE2.destroy_arglist(args);
    				cell_value :=Client_OLE2.get_char_property(cell, 'Value');
     
     
    				--Less code this way ->
    				copy(cell_value,name_in('system.cursor_item'));
    				next_item;
     
    			end loop; --for
     
    			j:=j+1;
    		end loop;--main loop
     
    		-- Release the Client_OLE2 object handles
    		IF (cell IS NOT NULL) THEN 
    			Client_OLE2.release_obj(cell);
    		END IF;
    		IF (worksheet IS NOT NULL) THEN 
    			Client_OLE2.release_obj(worksheet);
    		END IF;
    		IF (worksheets IS NOT NULL) THEN 
    			Client_OLE2.release_obj(worksheets);
    		END IF;
    		IF (worksheet2 IS NOT NULL) THEN 
    			Client_OLE2.release_obj(worksheet2);
    		END IF;
    		IF (workbook IS NOT NULL) THEN 
    			Client_OLE2.release_obj(workbook);
    		END IF;
    		IF (workbooks IS NOT NULL) THEN 
    			Client_OLE2.release_obj(workbooks);
    		END IF;
    		Client_OLE2.invoke(application,'Quit');
    		Client_OLE2.release_obj(application);
    	ELSE
    		Message('No File selected.');
    		message(' ');
    		RAISE Form_Trigger_Failure;
    	END IF;
    commit_form;
    		END;

  6. #6
    Nouveau membre du Club
    Homme Profil pro
    Administrateur de base de données
    Inscrit en
    Septembre 2016
    Messages
    40
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : Madagascar

    Informations professionnelles :
    Activité : Administrateur de base de données
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Septembre 2016
    Messages : 40
    Points : 29
    Points
    29
    Par défaut
    Bonjour,
    merci de votre réponse mais hélas, il essai toujours d’insérer les champs vide ou null, le curseur n’arrête pas quand il y a une ligne vide
    Images attachées Images attachées  

  7. #7
    Membre chevronné Avatar de Garuda
    Homme Profil pro
    Chef de projet / Urbaniste SI
    Inscrit en
    Juin 2007
    Messages
    1 285
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vaucluse (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Chef de projet / Urbaniste SI
    Secteur : Bâtiment

    Informations forums :
    Inscription : Juin 2007
    Messages : 1 285
    Points : 2 071
    Points
    2 071
    Par défaut
    C'est moi ou la variable "fin" n'est jamais affectée ?
    Garuda गरूड
    Brahmâ la Guerre et Vishnu la Paix

    Oracle 12C R2 - Forms11GR2 - Toad 12 - sharePoint 2010

Discussions similaires

  1. Import de données excel avec LSMW
    Par johan0510 dans le forum SAP
    Réponses: 6
    Dernier message: 10/04/2013, 11h51
  2. Réponses: 1
    Dernier message: 18/08/2011, 15h08
  3. Réponses: 25
    Dernier message: 26/04/2011, 13h58
  4. Importer sous MapInfo données Excel avec valeur manquantes
    Par dashblade dans le forum SIG : Système d'information Géographique
    Réponses: 1
    Dernier message: 12/06/2009, 15h17
  5. exploiter une base de données excel avec delphi
    Par budylove dans le forum Bases de données
    Réponses: 2
    Dernier message: 01/02/2005, 19h37

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo