Skip to content

Instantly share code, notes, and snippets.

@msakai
Created August 11, 2011 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msakai/1139508 to your computer and use it in GitHub Desktop.
Save msakai/1139508 to your computer and use it in GitHub Desktop.
Excelの各シートをCSVファイルに書き出すWSH
var fso = new ActiveXObject("Scripting.FileSystemObject")
var file = fso.GetFile(WScript.Arguments.Item(0))
var dirname = file.ParentFolder.Path
var basename = file.Name
var name = basename.replace(/\.xlsx?$/i, "")
var Excel = {
xlCSV : 6
}
var excel = new ActiveXObject("Excel.Application")
try {
// excel.Visible = true
excel.DisplayAlerts = false
update_links = null
readonly = true
book = excel.Workbooks.Open(file.Path, update_links, readonly)
sheets = book.Sheets
for (var i = 1; i <= sheets.Count; i++) {
sheet = sheets.Item(i)
sheet.Select()
book.SaveAs(dirname + "\\" + name + "-" + i + ".csv", Excel.xlCSV)
}
} finally {
excel.Quit()
}
require 'win32ole'
module Excel
end
excel = WIN32OLE.new("Excel.Application")
WIN32OLE.const_load(excel, Excel)
fname = ARGV[0]
dirname = File.dirname(fname)
basename = File.basename(fname)
name = basename.sub(/\.xlsx?$/i, "")
begin
excel.Visible = true
excel.DisplayAlerts = false
update_links = nil
readonly = true
book = excel.Workbooks.Open(fname, update_links, readonly)
sheets = book.Sheets
for i in (1 .. sheets.Count)
sheet = sheets.Item(i)
sheet.Select()
book.SaveAs("#{dirname}\\#{name}-#{i}.csv", Excel::XlCSV)
end
ensure
excel.Quit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment