Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

xls2csv - Convert xls to csv [CMD+GUI]


  • Please log in to reply
4 replies to this topic
BoBo
  • Guests
  • Last active:
  • Joined: --
Kindly provided by an AutoIt geek :D (yep, the optional GUI is made with AutoIt)

xls2csv - Recode a spreadsheet's charset and save as CSV.

usage: xls2csv -x spreadsheet.xls [-w worksheet] [-b charset] [-c csvfile.csv] [
-a charset] [-qshvW]

-x : filename of the source spreadsheet
-b : the character set the source spreadsheet is in (before)
-c : the filename to save the generated csv file as
-a : the character set the csv file should be converted to (after)
-q : quiet mode
-s : print a list of supported character sets
-h : this help message
-v : get version information
-W : list worksheets in the spreadsheet specified by -x
-w : specify the worksheet name to convert (defaults to the first worksheet)

example: xls2csv -x "spreadsheet.xls" -b WINDOWS-1252 -c "csvfile.csv" -a UTF-8

[Download]



PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
catdoc & xls2csv
http://www.45.free.n...oftware/catdoc/
I prefer the original pages, when available...
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

BoBo
  • Guests
  • Last active:
  • Joined: --
VBS code, stolen from [here] ...
option explicit

dim a, arg, oArgs, ArgNum
a = 0

Set oArgs = WSCript.arguments
ArgNum = oArgs.Count

if ArgNum <> 1 then
	WSCript.echo "Syntax: cscript <Script> filename_root"
	WScript.quit(1)
end if

dim filename_root, oldfilename, pos,newname
oldfilename = oArgs(0)

rem Remove .xls file extension if it was provided
dim ext
ext = right( oldfilename, 4 )
if lcase( ext ) = ".xls" then
 oldfilename = left( oldfilename, len( oldfilename ) - 4 )
end if

pos = instr(oldfilename, " ")

if pos > 0 then

 newname = right(oldfilename, len(oldfilename) - instrrev(oldfilename, "\"))
 newname = replace(newname," ","_")
 filename_root = left(oldfilename, instrrev(oldfilename, "\")) & newname

 dim oShell
 set oShell = Wscript.CreateObject("WScript.Shell")
 Wscript.echo "cmd.exe /c ren """ & oldfilename & ".xls"" " & newname & ".xls"
 oShell.run "cmd.exe /c ren """ & oldfilename & ".xls"" " & newname & ".xls"

else
 filename_root = oldfilename
end if

dim app
set app = createobject("Excel.Application")
    
dim wb
set wb = app.workbooks.open( filename_root & ".xls" )

const xlXMLSpreadsheet = 46
const xlCSV = 6

app.DisplayAlerts = false
dim sht
for each sht in wb.worksheets
 sht.activate
 dim output_filename
 output_filename = filename_root & "_" & replace( sht.name, " ", "_" ) & ".csv"
 wb.saveAs output_filename, xlCSV
next
'wb.saveAs filename_root & ".xml", xlXMLSpreadsheet
app.DisplayAlerts = true

wb.close false

'app.close

WScript.quit 
Save that as a VBS (xlstocvs.vbs), then use the following batch script:


Code:
for %%i in (*.xls) do cscript xlstocsv.vbs %%~dpni > nul

Put the batch script in the same directory as the XLS files, and xlstocsv.vbs, then run it from the command line.
... still wishing AHK would provide VBS/JS-Include commands :( .

(AHKCode)
[color=blue]VBSStart[/color]
   (VBSCode)
[color=blue]VBSEnd[/color]
(AHKCode)
Posted Image

BoBo
  • Guests
  • Last active:
  • Joined: --
C++ code [xlstocsv.zip] - 77.0 KB
Excel OLE with C [Download] - 9.7 KB

BoBo
  • Guests
  • Last active:
  • Joined: --
Any idea how to use this [xlsconv.dll] with AHK (the correct answer is DllCall(), I know that one already :wink:)