Skip to content

Instantly share code, notes, and snippets.

@msakai
Created March 18, 2020 06:41
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/b6ed009d54d2d2505dd393d5d3e081bb to your computer and use it in GitHub Desktop.
Save msakai/b6ed009d54d2d2505dd393d5d3e081bb to your computer and use it in GitHub Desktop.
require 'win32ole'
ex = WIN32OLE.new("Excel.Application")
fso = WIN32OLE.new("Scripting.FileSystemObject")
files = ["Book1.xlsx", "Book2.xlsx"]
book = ex.Workbooks.Add
files.each { |file|
file = fso.GetAbsolutePathName(file)
book1 = ex.Workbooks.Open(file)
book1.Sheets(1).Copy(After: book.Sheets(book.Sheets.Count))
book1.Close
}
book.Sheets(1).Delete
book.SaveAs("C:\\Users\\sakai\\Documents\\test.xlsx")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment