Last active
August 29, 2015 14:18
-
-
Save iamdionysus/9857fd6a25ec5ae6ddbb to your computer and use it in GitHub Desktop.
ruby win32ole copy and paste last row in 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
excel = WIN32OLE.new 'Excel.Application' | |
excel.visible = true | |
workbook = excel.Workbooks.open "path/to/file" | |
sheet = workbook.Worksheets 1 | |
def excel_copy_and_paste_last_row excel, workbook, sheet | |
last_row = sheet.UsedRange.Rows.Count | |
sheet.Rows(last_row).copy | |
sheet.Cells(last_row + 1, 1).Select | |
workbook.ActiveSheet.Paste | |
excel.CutCopyMode = false | |
end | |
def excel_save_and_close excel, workbook | |
# save xlsx | |
workbook.Saved = true | |
workbook.Save | |
# close excel | |
excel.activeworkbook.close 0 | |
excel.quit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment