[RESOLU] convertir XLS en TXT ou CSV

convertir XLS en TXT ou CSV [RESOLU] - Logiciels - Windows & Software

Marsh Posté le 18-07-2006 à 18:52:43    

Bonjour
 
Je suis a la recherche d'un moyen (ou d'un programme) "free" de convertir un fichier XLS vers un fichier TXT ou CSV, le tout en ligne de commande (batch).
 
Vous connaissez quelque chose ?
 
Tout ce que j'ai trouvé c'est payant !
 
Merci a vous


Message édité par orlith le 02-08-2006 à 16:46:39
Reply

Marsh Posté le 18-07-2006 à 18:52:43   

Reply

Marsh Posté le 18-07-2006 à 18:54:40    

Il y a une solution Linux...mais bon faut être sous Linux [:ddr555]
http://wizard.ae.krakow.pl/~jb/xls2txt/

Reply

Marsh Posté le 18-07-2006 à 18:57:33    

Arghhhh !!
 
Moi c'est sous windows Xp !
Pas de chance.
 
Merci

Reply

Marsh Posté le 02-08-2006 à 16:52:16    

Ca y est j'ai trouvé !
 
Avec du vbs c'est possible  !
Voic imon script, y'a surement des améliorations a faire mais bon ca fonctionne bien comme ca !
 
Il lit le contenu d'un répertoire et de ses sous dossiers, transforme tout les fichier xls en txt puis supprime les répertoires.
 

Code :
  1. Option Explicit
  2. Dim a ' WB
  3. Dim n: n = 0 ' WB
  4. Dim Recursivity ' WB
  5. On error resume Next
  6. Main
  7. Sub Main
  8. Dim Path,count
  9. Dim Chaine, longueur, fName
  10. Dim i ,fs
  11. Dim FileName, Filepath
  12. Dim xlApp, xlWB, vPath, FSO, f, fl, fpath,oShell
  13. Set xlApp = CreateObject("excel.application" )
  14. vPath = "Chemins initial des xls\"
  15. fPath = "Chemin de dépose des txt"
  16. Set FSO = CreateObject("scripting.filesystemobject" )
  17. xlApp.DisplayAlerts = False
  18. 'Select Case WScript.Arguments.Count
  19. ' Case 0: Path = "*.*"            ' list current directory
  20. ' Case 1: Path = WScript.Arguments(0) ' WB
  21. ' Case 2: Path = WScript.Arguments(0) : Recursivity = WScript.Arguments(1) ' WB
  22. ' Case Else: WScript.Echo "Invalid number of arguments.": Exit Sub
  23. 'End Select
  24. Select Case Recursivity ' WB
  25.  Case ""  : Recursivity=True ' WB
  26.  Case Else : Recursivity=False ' WB
  27. End Select ' WB
  28. Path ="*.xls"
  29. ReDim a(1,10) ' WB
  30. 'wscript.echo "ubound 1 : "&ubound(a,2)
  31. a = ListDir(vPath & Path)
  32. 'wscript.echo "ubound 2 : "&ubound(a,2)
  33. If UBound(a) = -1 then
  34.  WScript.Echo "No files found."
  35.  Exit Sub
  36. End If
  37. n=1
  38. Do While n+1 <= UBound(a,2)
  39.  'wscript.echo ubound(a)
  40.  'wscript.echo n
  41.  Filepath=a(0,n-1)
  42.  Filename=a(1,n-1)
  43.  'wscript.echo filepath
  44.  'wscript.echo filename
  45.  Longueur=len(filePath)-66
  46.  If Longueur >0 then
  47.   FilePath = Right(FilePath,longueur) 'supprime la chaine d:\temp\ du path
  48.   Chaine = Split(FilePath, "\" ) 'splitte la chaine en morceaux en fonction de \ afin d'avoir les noms de répertoires
  49.   'For i = 0 To UBound(Chaine)
  50.   ' wscript.echo "chaine: " & Chaine(i)
  51.   'Next
  52.   'Put here what you want to be done
  53.   xlApp.DisplayAlerts = False
  54.   Set xlWB = xlApp.Workbooks.Open(vPath&filepath)
  55.   fName = Chaine(1) & "_Daily_" & Left(Filename, len(filename)-4)
  56.   xlWB.SaveAs fPath & fname &".csv", 6 '6=xlcsv
  57.   xlWB.Close False
  58.   fs=FSO.deletefolder(vPath&Chaine(0)&"\"&chaine(1), True)
  59.  End If
  60.  n=n+1
  61. Loop
  62. xlApp.DisplayAlerts = True
  63. Set xlWB = Nothing
  64. xlApp.Quit
  65. Set xlApp = Nothing
  66. Set vPath = Nothing
  67. End Sub
  68. ' Returns an array with the file names that match Path.
  69. ' The Path string may contain the wildcard characters "*"
  70. ' and "?" in the file name component. The same rules apply as with the MSDOS DIR command.
  71. ' If Path is a directory, the contents of this directory is listed.
  72. ' If Path is empty, the current directory is listed.
  73. ' Author: Christian d'Heureuse (www.source-code.biz)
  74. ' Modified by Wilfrid Burel on the 22nd November 2005 in order to be recursive : modification commented and signed
  75. Public Function ListDir (ByVal Path)
  76. Dim fso: Set fso = CreateObject("Scripting.FileSystemObject" )
  77. If Path = "" then Path = "*.*"
  78. Dim Parent, Filter
  79. if fso.FolderExists(Path) then     ' Path is a directory
  80. Parent = Path
  81. Filter = "*"
  82. Else
  83. Parent = fso.GetParentFolderName(Path)
  84. If Parent = "" Then If Right(Path,1) = ":" Then Parent = Path: Else Parent = "."
  85. Filter = fso.GetFileName(Path)
  86. If Filter = "" Then Filter = "*"
  87. End If
  88. 'ReDim a(10)  quote by WB
  89. Dim Folder: Set Folder = fso.GetFolder(Parent)
  90. Dim Files: Set Files = Folder.Files
  91. Dim File
  92. 'Implementation of recursivity WB
  93. If Recursivity then
  94. Dim SubFolder ' WB
  95. If Folder.SubFolders.Count <> 0 Then 'WB
  96.  For Each SubFolder In Folder.SubFolders ' WB
  97.   ListDir(SubFolder&"\" & Filter) ' WB
  98.  Next ' WB
  99. End If ' WB
  100. End If
  101. Set Files = Folder.Files
  102. For Each File In Files
  103. If CompareFileName(File.Name,Filter) Then
  104.  'wscript.echo "ubound : "&ubound(a,2) & "  -  "&n
  105.  If n > UBound(a,2) Then ReDim Preserve a(1,n*2)
  106.  a(0,n) = File.Path
  107.  a(1,n) = File.Name
  108.  n = n + 1
  109. End If
  110. Next
  111. ReDim Preserve a(1,n+2)
  112. ListDir = a
  113. End Function
  114. Private Function CompareFileName (ByVal Name, ByVal Filter) ' (recursive)
  115. CompareFileName = False
  116. Dim np, fp: np = 1: fp = 1
  117. Do
  118.   If fp > Len(Filter) Then CompareFileName = np > len(name): Exit Function
  119.   If Mid(Filter,fp) = ".*" Then       ' special case: ".*" at end of filter
  120.    If np > Len(Name) Then CompareFileName = True: Exit Function
  121.   End If
  122.   Dim fc: fc = Mid(Filter,fp,1): fp = fp + 1
  123.   Select Case fc
  124.    Case "*"
  125.     CompareFileName = CompareFileName2(name,np,filter,fp)
  126.     Exit Function
  127.    Case "?"
  128.     If np <= Len(Name) And Mid(Name,np,1) <> "." Then np = np + 1
  129.    Case Else
  130.     If np > Len(Name) Then Exit Function
  131.     Dim nc: nc = Mid(Name,np,1): np = np + 1
  132.     If Strcomp(fc,nc,vbTextCompare)<>0 Then Exit Function
  133.   End Select
  134. Loop
  135. End Function
  136. Private Function CompareFileName2 (ByVal Name, ByVal np0, ByVal Filter, ByVal fp0)
  137. Dim fp: fp = fp0
  138. Dim fc2
  139. Do
  140.   If fp > Len(Filter) Then CompareFileName2 = True: Exit Function
  141.   If Mid(Filter,fp) = ".*" Then    ' special case: ".*" at end of filter
  142.    CompareFileName2 = True: Exit Function
  143.         End If
  144.   fc2 = Mid(Filter,fp,1): fp = fp + 1
  145.   If fc2 <> "*" And fc2 <> "?" Then Exit Do
  146. Loop
  147. Dim np
  148. For np = np0 To Len(Name)
  149.   Dim nc: nc = Mid(Name,np,1)
  150.   If StrComp(fc2,nc,vbTextCompare)=0 Then
  151.    If CompareFileName(Mid(Name,np+1),Mid(Filter,fp)) Then
  152.     CompareFileName2 = True: Exit Function
  153.    End If
  154.   End If

Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed