tag:blogger.com,1999:blog-284600789737488130.post8203800762063145006..comments2024-02-07T02:22:20.642-05:00Comments on Ruby on Windows: Automating Excel with Ruby: The Worksheet ObjectDavid Mullethttp://www.blogger.com/profile/05597492688893461137noreply@blogger.comBlogger7125tag:blogger.com,1999:blog-284600789737488130.post-2207306652103652412014-12-22T09:53:59.490-05:002014-12-22T09:53:59.490-05:00Hi,
Please find my code below.
new_book = Spread...Hi,<br /><br />Please find my code below.<br /><br />new_book = Spreadsheet.open 'sample.xls'<br /><br />worksheet = new_book.worksheets<br /><br />have 3 sheets(sheet1,sheet2,sheet3)<br />I want to add sheet4 to new_book.<br /><br />How can do can you help me.<br /><br />Thanks in Advance.<br /><br />Thanks<br />Shiva.Ashivareddyhttps://www.blogger.com/profile/13089543442508296295noreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-80816296720642269322011-10-02T14:54:54.815-05:002011-10-02T14:54:54.815-05:00@Anonymous:
To move the worksheet between workboo...@Anonymous:<br /><br />To move the worksheet between workbooks, use the same method, but pass it a worksheet object from the second workbook. Example:<br /><br />require 'win32ole'<br /><br />xl = WIN32OLE.connect('Excel.Application')<br />wb1 = xl.Workbooks('Book1.xls')<br />wb2 = xl.Workbooks('Book2.xls')<br />wb1.Worksheets(1).Move(wb2.Worksheets(1))David Mullethttps://www.blogger.com/profile/05597492688893461137noreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-13391801833373087332011-09-30T12:54:18.552-05:002011-09-30T12:54:18.552-05:00Well, but how to copy/move worksheets between diff...Well, but how to copy/move worksheets between different workbooks?Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-90145895012806890902009-02-23T23:25:00.000-05:002009-02-23T23:25:00.000-05:00To move sheet "foo" to the end:excel.she...To move sheet "foo" to the end:<BR/><BR/>excel.sheets("foo").move({'after' => excel.sheets(excel.sheets.count)})<BR/><BR/>I think it returns true if it's a success.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-56708738149449969112008-12-16T22:11:00.000-05:002008-12-16T22:11:00.000-05:00worksheet1.Copy(nil, $workbook.Worksheets($workboo...worksheet1.Copy(nil, $workbook.Worksheets($workbook.Worksheets.Count))<BR/><BR/>With a nil as the first parameters then it's considered "After"Plummhttps://www.blogger.com/profile/01079833530407761100noreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-80446254516285680132007-04-06T14:09:00.000-05:002007-04-06T14:09:00.000-05:00Good question! As you said, Walker, the Move metho...Good question! As you said, Walker, the Move method defaults to 'Before'...<BR/><BR/>excel.Sheets(3).Move(excel.Sheets(1))<BR/>workbook.Workheets(3).Move(workbook.Worksheets(1))<BR/><BR/>But I am unaware of how to specify the 'After' parameter. You could use the methods above to move a worksheet to any position but the last. In that case, you may have to move a worksheet Before the last worksheet, then move the last worksheet Before the next-to-last worksheet.David Mullethttps://www.blogger.com/profile/05597492688893461137noreply@blogger.comtag:blogger.com,1999:blog-284600789737488130.post-32782106645619838672007-04-02T11:20:00.000-05:002007-04-02T11:20:00.000-05:00In order to learn about scripting Excel, I've been...In order to learn about scripting Excel, I've been recording macros and trying to translate them into methods for ruby - as you recommended. Your post gives an answer to my question, but I would still like to ask it. When moving a worksheet, excel creates this macro: <BR/><BR/>Sheets("Sheet2").Move After:=Sheets(2)<BR/><BR/>How do you translate the parameter after .Move (After:=, or Before:=) into a ruby command?<BR/><BR/>It looks like .Move in ruby defaults to "before".Walkerhttps://www.blogger.com/profile/14152234200831316723noreply@blogger.com