excel - Convert xls / xlsx files (all sheets) to csv using VBScript (delimited by semicolons) -
excel - Convert xls / xlsx files (all sheets) to csv using VBScript (delimited by semicolons) -
i need convert excel file (*.xls , *.xlsx) including worksheets within csv file split per sheet. output csv file(s) should named sheetname(s) , delimited semi-colons, instead of commas. have done this, bonding several vbs scripts one, still have there bug. code below convertion sheets in xls file delimited semicolons,named sheets - little bug if there more 1 worksheet, contents of next sheets overwritten first sheet. whats wrong there please? im running in cmd with: xls_to_csv.vbs excelfile.xls outputdir
'------------------- set semi-colon delimiter via win registers --------------- strdelimiter = ";" strsystemdelimiter = "" ' used store current sytem value const hkey_current_user = &h80000001 ' current list separator (regional settings) registry strkeypath = "control panel\international" strvaluename = "slist" strcomputer = "." set objregistry = getobject("winmgmts:\\" & strcomputer & "\root\default:stdregprov") objregistry.getstringvalue hkey_current_user, strkeypath, strvaluename, strsystemdelimiter ' set temporarily our custom delimiter objregistry.setstringvalue hkey_current_user, strkeypath, strvaluename, strdelimiter '----------------------------- convert xls csv ------------------------------ dim strexcelfilename dim strcsvfilename dim objfso set objfso = createobject("scripting.filesystemobject") strpath = objfso.getabsolutepathname(wscript.arguments.item(1)) strexcelfilename = wscript.arguments.item(0) 'file name parses rem path script running set fso = createobject ("scripting.filesystemobject") 'use find current path strscript = wscript.scriptfullname strscriptpath = fso.getabsolutepathname(strscript & "\..") rem if input file not qualified path, default current path lposition = instrrev(strexcelfilename, "\") if lposition = 0 'no folder path strexcelfilename = strscriptpath & "\" & strexcelfilename strscriptpath = strscriptpath & "\" else 'there folder path, utilize output folder path strscriptpath = mid(strexcelfilename, 1, lposition) end if rem msgbox lposition & " - " & strexcelfilename & " - " & strscriptpath ' utilize debugging dim objxl dim objworkbook, local set objxl = createobject("excel.application") set objworkbook = objxl.workbooks.open(strexcelfilename) objxl.displayalerts = false rem loop on worksheets each sheet in objworkbook.sheets 'only saveas sheets not empty if objxl.application.worksheetfunction.counta(sheet.cells) <> 0 rem sheet.rows(1).delete ' remove row 1 or header row local = true phone call objworkbook.saveas(strpath & "\" & sheet.name & ".csv", 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, local) end if next rem clean objworkbook.close objxl.quit set objxl = nil set objworkbook = nil set fso = nil '------------------------- homecoming registry changes -------------------- ' reset scheme setting original value objregistry.setstringvalue hkey_current_user, strkeypath, strvaluename, strsystemdelimiter rem end script
my suggestion utilize different language this. editing registry entries sake of changing delimiter "hacky" @ least.
it can perchance done simple python script , using xlrd , csv packages. create usable on multiple platforms. can convert python script .exe using py2exe.
excel csv vbscript xls semicolon
Comments
Post a Comment