On Thu, Jan 5, 2012 at 12:41 PM, David Mullet <david.mullet / gmail.com> wrote: > cristian cristian wrote in post #1039540: >> Now Im trying to save the workbook as an excel workbook but it saves the >> file as an CSV. I want a .xlsx >> >> So I did this: >> >> ..... >> ensure >> # Save the workbook and close >> # filename is 'C:\Ruby\Lab\test.csv' >> >> excel.activeworkbook.SaveAs(filename.split(".").first+".xlsx") >> excel.activeworkbook.close(false) >> >> # Quit Excel >> excel.quit >> end >> >> This saves the file without problem but I cant open it because the file >> format or the file extension is not valid. How should I save it?? >> >> Any suggestions? >> >> Br >> cristian > > The SaveAs() method accepts a second argument to specify the file > format. > > The value for xlOpenXMLWorkbook (Excel 2007+ .xlsx) is 51. > > So simply change your SaveAs code to the following: > > excel.activeworkbook.SaveAs(filename.split(".").first+".xlsx", 51) It's a good idea to strip the extension of the file with File.basename(filename, File.extname(filename)), in case there is a period in it that doesn't immediately precede the extension.