#1 Tue 06 November 2012 09:27
- thomas17180
- Participant actif
- Lieu: La Rochelle
- Date d'inscription: 9 May 2011
- Messages: 50
[MapBasic] Fenêtre de dialogue pour export en CSV
Bonjour à tous,
Actuellement en train de programmer en MapBasic, j'aurais besoin d'une petite aide!
J'aimerai finir l'automatisation d'une tâche repetitive à mon travail qui se termine par l'export d'un .tab vers Excel. Pour cela, j'exporte le .tab en .csv. Jusque là tout va bien, j'ai réussi à coder cela. Mais le problème est que j'aimerai pouvoir choisir le répertoire de destination du CSV, et je ne vois pas comment l'introduire dans mon code... (au moins d'un path?)
Voici le code de l'export :
Code:
'---------- Export en .CSV pour importer dans Excel ----------
Export w_nom_table into "C:\Users\mt\Desktop\" & w_nom_table & ".CSV"
Type "ASCII" Overwrite Delimiter "," CharSet "WindowsLatin1" TitlesAinsi, mon .csv prend le nom de la table sélectionnée dans une liste mais va se positionner sur mon bureau (choix pour le test).
Merci d'avance!!!
Petit bonus : Y a t il moyen d'améliorer cette partie de code? (je met à jour 1 colonne en fonction de la première lettre d'un autre champ) :
Code:
Select count(*) "Nb" from w_nom_table where Left$(MI_CQ,1)="N" into resultat
If resultat.Nb <> 0 then
Select * from w_nom_table where Left$(MI_CQ,1)="N" into Selection
Update Selection Set ECH_GEO = "Numero" '=>correspond au champ MI_CQ : remplacer la première lettre par libelle + parlant
End if
Select count(*) "Nb" from w_nom_table where Left$(MI_CQ,1)="C" into resultat
If resultat.Nb <> 0 then
Select * from w_nom_table where Left$(MI_CQ,1)="C" into Selection
Update Selection Set ECH_GEO = "Numero Corrige"
End if
Select count(*) "Nb" from w_nom_table where Left$(MI_CQ,1)="S" into resultat
If resultat.Nb <> 0 then
Select * from w_nom_table where Left$(MI_CQ,1)="S" into Selection
Update Selection Set ECH_GEO = "Rue"
End if
Select count(*) "Nb" from w_nom_table where Left$(MI_CQ,1)="T" into resultat
If resultat.Nb <> 0 then
Select * from w_nom_table where Left$(MI_CQ,1)="T" into Selection
Update Selection Set ECH_GEO = "Commune"
End if
Select count(*) "Nb" from w_nom_table where Left$(MI_CQ,1)="Z" into resultat
If resultat.Nb <> 0 then
Select * from w_nom_table where Left$(MI_CQ,1)="Z" into Selection
Update Selection Set ECH_GEO = "Code Postal"
End if
Select count(*) "Nb" from w_nom_table where Left$(MI_CQ,1)="D" into resultat
If resultat.Nb <> 0 then
Select * from w_nom_table where Left$(MI_CQ,1)="D" into Selection
Update Selection Set ECH_GEO = "Departement"
End ifHors ligne
#2 Tue 06 November 2012 14:12
- thomas17180
- Participant actif
- Lieu: La Rochelle
- Date d'inscription: 9 May 2011
- Messages: 50
Re: [MapBasic] Fenêtre de dialogue pour export en CSV
Le problème concernant la boite de dialogue pour le choix du repertoire vient de trouver sa solution :
Code:
Dim repertoire as String
repertoire = filesaveasdlg ("C:\", w_nom_table, "csv", "Export en CSV")
Export w_nom_table into repertoire
Type "ASCII" Overwrite Delimiter "," CharSet "WindowsLatin1" TitlesVos idées pour alleger le code des mise à jour sont toujours les bienvenues ![]()
Hors ligne
#3 Tue 06 November 2012 15:06
- Damien BEAUSEIGNEUR
- Participant assidu
- Lieu: meyzieu
- Date d'inscription: 5 Sep 2005
- Messages: 425
Re: [MapBasic] Fenêtre de dialogue pour export en CSV
Bonjour,
je me disais bien que la première partie n'était pas si compliqué.
Pour la seconde.
ça implique un peu de travail préparatoire.
il faut créer une table contenant la traduction ma_trad avec un index sur Code bien sur
Code, traduction
N , Numero
C , Numero corrige
...
Voilà c'est plus court :
Code:
Select * from w_nom_table, ma_trad where Left$(w_nom_table.MI_CQ,1)= ma_trad.code into selection if SelectionInfo(SEL_INFO_NROWS) <> 0 then update selection set ECH_GEO = traduction end if
Hors ligne


