Created
December 25, 2015 09:24
-
-
Save nasitra/ba04f7dab060fd0e6a55 to your computer and use it in GitHub Desktop.
Convert a Excel file to a CSV file in Windows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function error(message) { | |
| excel.Quit(); | |
| excel = null; | |
| WScript.Echo(message); | |
| WScript.Quit(1); | |
| } | |
| var argc = WScript.Arguments.Count(); | |
| if (argc !== 2) { | |
| WScript.Echo('xls2csv.js [source file] [target file]'); | |
| WScript.Quit(1); | |
| } | |
| var filename = WScript.Arguments(0); | |
| var saveFileName = WScript.Arguments(1); | |
| var objFileSys = new ActiveXObject("Scripting.FileSystemObject"); | |
| filename = objFileSys.GetAbsolutePathName(filename); | |
| saveFileName = objFileSys.GetAbsolutePathName(saveFileName); | |
| objFileSys = null; | |
| var excel = new ActiveXObject('Excel.Application'); | |
| excel.Visible = false; | |
| excel.DisplayAlerts = false; | |
| try { | |
| WScript.Echo('open: ' + filename); | |
| excel.Workbooks.Open(filename); | |
| } catch (e) { | |
| error('open error'); | |
| } | |
| try { | |
| WScript.Echo('save: ' + saveFileName); | |
| var book = excel.Workbooks(excel.Workbooks.Count); | |
| book.SaveAs(saveFileName, 6); | |
| } catch (e) { | |
| error('save error'); | |
| } | |
| excel.Quit(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment