hey, i have costumers who has a huge employee list (prefers excel), and if he wants to use my application he needs to import those employees, i was wondering if it possible to make a sort of import function for the costumer. Like he has a list in csv or some sort based on a template i gave them, then click on link, there is a dialog window to get the file, read the csv or xls and import the data in the database. anyone has any experience in that??? thanks in advance
You have to put this line at the beganig of the u r controller and try to find this file in the ruby folder where u have installed require ''csv'' then u try to under stan the example given belo and if u have doubts mail me back Example def readcsv # CSV READING @parts = Part.find(@params[''id'']) csv_file_path = DUMP_PATH + "/" + @parts.filename Tempcompany.destroy_all CSV.open(csv_file_path, ''r'') do |row| cells = Array.new cells = row.to_a() tempcompany= Tempcompany.new # SETING THE VALUES TO THE OBJECT OF TEMPCOMPANY tempcompany[''company_name''] = cells[0] tempcompany[''company_description''] = cells[1] tempcompany[''company_url''] = cells[2] tempcompany[''company_phone''] = cells[3] tempcompany[''company_fax''] = cells[4] tempcompany[''primary_industry''] = cells[5] tempcompany[''company_revenue''] = cells[6] tempcompany[''revenue_growth''] = cells[7] tempcompany[''num_of_employees''] = cells[8] tempcompany[''company_notes''] = cells[9] tempcompany[''notes_public_private''] = cells[10] tempcompany[''company_ticker''] = cells[11] tempcompany[''last_updated''] = cells[12] tempcompany[''company_street1''] = cells[13] tempcompany[''company_street2''] = cells[14] tempcompany[''company_city''] = cells[15] tempcompany[''company_state''] = cells[16] tempcompany[''company_zip''] = cells[17] tempcompany[''company_country_id''] = cells[18] tempcompany[''email_format''] = cells[19] # SAVING THE TEMPCOMPANY tempcompany.save end -----Original Message----- From: rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org]On Behalf Of Brutyn Nick Sent: Monday, November 07, 2005 3:42 PM To: rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: [Rails] Importing data from excel hey, i have costumers who has a huge employee list (prefers excel), and if he wants to use my application he needs to import those employees, i was wondering if it possible to make a sort of import function for the costumer. Like he has a list in csv or some sort based on a template i gave them, then click on link, there is a dialog window to get the file, read the csv or xls and import the data in the database. anyone has any experience in that??? thanks in advance _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
A couple of thoughts: 1. How well organized are the Excel spreadsheets? It''s possible to read from and write to Excel spreadsheets using ODBC. Perhaps its simply a matter of connecting to them with ODBC and exporting them to one of the three Rails-compatible databases. 2. I''m pretty sure the Windows Ruby library has a way to connect with Excel using the native Windows APIs. You could read the spreadsheets that way, then export them to your Rails database. 3. Don''t use an intermediate CSV file unless you absolutely have to. It''s an extra step, you need a place to put the file, etc. 4. I don''t know where you live, but here in the USA, employee data is *extremely* sensitive. You''ll want to pay *lots* of attention to security, privacy, encryption and other such issues in your design, implementation and deployment. Good luck ... aside from number 4, this looks pretty easy to me. Brutyn Nick wrote:>hey, > >i have costumers who has a huge employee list (prefers excel), and if he wants >to use my application he needs to import those employees, i was wondering if it >possible to make a sort of import function for the costumer. > >Like he has a list in csv or some sort based on a template i gave them, then >click on link, there is a dialog window to get the file, read the csv or xls and >import the data in the database. > >anyone has any experience in that??? > >thanks in advance > >_______________________________________________ >Rails mailing list >Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- M. Edward (Ed) Borasky http://linuxcapacityplanning.com