On Thu, Jan 5, 2012 at 12:41 PM, David Mullet <david.mullet / gmail.com> wrot=
e:
> 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
>> =A0 # Save the workbook and close
>> =A0 # filename is 'C:\Ruby\Lab\test.csv'
>>
>> =A0 excel.activeworkbook.SaveAs(filename.split(".").first+".xlsx")
>> =A0 excel.activeworkbook.close(false)
>>
>> =A0 # Quit Excel
>> =A0 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:
>
> =A0 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.