Hello, I am trying to use Spreadsheet gem to import some data in the db. I open a xls as member_file=Spreadsheet.open("#{RAILS_ROOT}/public/data/FAMILY-MEMBER.xls") but after that when I try to open the file using Excel I get an error that file is locked by another user for editing. Only way to release the lock is to kill the rails server. And there is no method to close the file in the gem. How do I solve this problem? ''Roo'' also had the same issue. Is there any gem which I can use to import/export the data from excel which does not have these issues? Thanks. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Sep 2, 2012, at 4:16 PM, renu mehta wrote:> Hello, > > I am trying to use Spreadsheet gem to import some data in the db. I open > a xls as > > member_file=Spreadsheet.open("#{RAILS_ROOT}/public/data/FAMILY-MEMBER.xls") > > but after that when I try to open the file using Excel I get an error > that file is locked by another user for editing. Only way to release the > lock is to kill the rails server. And there is no method to close the > file in the gem. How do I solve this problem? ''Roo'' also had the same > issue. Is there any gem which I can use to import/export the data from > excel which does not have these issues?You won''t have this issue in production, since the XLS file will never be opened by the server, I''m betting. You could simply duplicate the file before you open it, or you could look into the gem source and see if there''s a missing your_file.close method somewhere. Walter> > Thanks. > > -- > Posted via http://www.ruby-forum.com/. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Walter Davis wrote in post #1074366:> On Sep 2, 2012, at 4:16 PM, renu mehta wrote: > >> file in the gem. How do I solve this problem? ''Roo'' also had the same >> issue. Is there any gem which I can use to import/export the data from >> excel which does not have these issues? > > You won''t have this issue in production, since the XLS file will never > be opened by the server, I''m betting. You could simply duplicate the > file before you open it, or you could look into the gem source and see > if there''s a missing your_file.close method somewhere. > > WalterBut won''t it cause a problem next time I want to upload the updated xls to the server and then try to import it. Every week a user will upload a xls with the same name and app has to update the db based on new data. How will I be able to upload and try to read it again with the same name on server if file is not released for editing? I am using the ''Spreadsheet'' gem for import of data. Is there any other gem available which may be better option for this functionality? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Sep 2, 2012, at 9:01 PM, renu mehta wrote:> Walter Davis wrote in post #1074366: >> On Sep 2, 2012, at 4:16 PM, renu mehta wrote: >> >>> file in the gem. How do I solve this problem? ''Roo'' also had the same >>> issue. Is there any gem which I can use to import/export the data from >>> excel which does not have these issues? >> >> You won''t have this issue in production, since the XLS file will never >> be opened by the server, I''m betting. You could simply duplicate the >> file before you open it, or you could look into the gem source and see >> if there''s a missing your_file.close method somewhere. >> >> Walter > > But won''t it cause a problem next time I want to upload the updated xls > to the server and then try to import it. Every week a user will upload a > xls with the same name and app has to update the db based on new data. > How will I be able to upload and try to read it again with the same name > on server if file is not released for editing? I am using the > ''Spreadsheet'' gem for import of data. Is there any other gem available > which may be better option for this functionality?I don''t believe that any application outside of Excel is going to behave this way. Try it on a real server and see what happens. I think you can replace the file right out from under the process, then tell it to re-import, and you should be good. But test it out to be sure. Just don''t take anything Excel has to say about this as meaningful in the context of your production server. If this does prove to be a problem, then just rename the file on the server as you save it. Append the current time in milliseconds or something similar to cause it to have an unique name on disk. Or delete the file on your server after you have read it into your database. You won''t need it after you''ve parsed it into database records, after all. Walter -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Hi>> Is there any other gem availablemight be worth a look at this ... https://github.com/autotelik/datashift .. imports active record models, including associations started life as an Excel import tool for Spree but is now a generic active record import/export tool from Excel or CSV. One caveat, Excel access is currently only via Jruby, but if that is not available export from Excel to CSV and the csv import works identically. You can also use it to generate excel/csv templates of your models, making it easier to map data back to your db schema Cheers tom -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/TYXE_e8HlBMJ. For more options, visit https://groups.google.com/groups/opt_out.
On Sunday, September 2, 2012 9:16:41 PM UTC+1, Ruby-Forum.com User wrote:> > Hello, > > I am trying to use Spreadsheet gem to import some data in the db. I open > a xls as > > member_file=Spreadsheet.open("#{RAILS_ROOT}/public/data/FAMILY-MEMBER.xls") > > > but after that when I try to open the file using Excel I get an error > that file is locked by another user for editing. Only way to release the > lock is to kill the rails server. And there is no method to close the > file in the gem. How do I solve this problem? ''Roo'' also had the same > issue. Is there any gem which I can use to import/export the data from > excel which does not have these issues? >Have you tried using the block form? Spreadsheet.open(path) do |workbook| ... end Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/SPgCZBZj2qYJ. For more options, visit https://groups.google.com/groups/opt_out.