Created
September 9, 2014 07:02
-
-
Save carrotsword/cf4af590ab4a6b70921e to your computer and use it in GitHub Desktop.
WSH(JS) からExcelのセル読み取ったりなんだりする
This file contains 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 err(message){ | |
WScript.Echo(message); | |
} | |
function isSuffix(target, suffix){ | |
return target.indexOf(suffix, target.length - suffix.length) !== -1; | |
} | |
function main(){ | |
if ( WScript.Arguments.length !== 1 ){ | |
err("引数1つにしろ"); | |
return 1; | |
} | |
var fname = WScript.Arguments(0); | |
if( (!isSuffix(fname, 'xls')) && (!isSuffix(fname, 'xlsx')) ){ | |
err("Excelじゃないんじゃない"); | |
return 1; | |
} | |
var outfname = WScript.ScriptFullName.substring(0,WScript.ScriptFullName.length - WScript.ScriptName.length) + "\\test.txt"; | |
var excel = new ActiveXObject("Excel.Application"); | |
excel.visible = true; | |
excel.Workbooks.Open(fname); | |
var sheetsCount = excel.ActiveWorkbook.Sheets.Count | |
var fs = new ActiveXObject("Scripting.FileSystemObject"); | |
var outstream = fs.CreateTextFile(outfname); | |
for(var i=0;i<sheetsCount; i++ ){ | |
var sheet = excel.ActiveWorkbook.Sheets.Item(i+1); | |
outstream.WriteLine("#################" + sheet.Name + "#################"); | |
var line = 5; | |
while(line < 30){ | |
WScript.Echo(sheet.Range("B" + line).Value); | |
line++; | |
} | |
} | |
outstream.Close() | |
excel.Quit(); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment