将国家/地区呼叫代码加入国家/地区表

问题描述 投票:1回答:1

我正在创建一个需要国家/地区表的Rails项目。我还想将国家/地区的呼叫代码纳入其中。我找到了从GitHub创建国家/地区表的帮助,它看起来像这样:

class CreateCountries < ActiveRecord::Migration
  def change
    create_table :countries do |t|
      t.string :name
      t.string :printable_name
      t.string :iso2, :size => 2
      t.string :iso3, :size => 3
      t.integer :numcode

      t.timestamps
    end
  end

  Country.reset_column_information

  Country.create(:iso2 => 'AF', :name => 'AFGHANISTAN', :printable_name => 'Afghanistan', :iso3 => 'AFG', :numcode => '004')
  Country.create(:iso2 => 'AL', :name => 'ALBANIA', :printable_name => 'Albania', :iso3 => 'ALB', :numcode => '008')
  Country.create(:iso2 => 'DZ', :name => 'ALGERIA', :printable_name => 'Algeria', :iso3 => 'DZA', :numcode => '012')

然后我还找到了国家/地区呼叫代码列表,并设法将它们放入电子表格中:

Afghanistan 93
Albania 355
Algeria 213

我想快速将调用代码加入上面的列表,所以它看起来像这样:

Country.create(:iso2 => 'AF', :name => 'AFGHANISTAN', :printable_name => 'Afghanistan', :iso3 => 'AFG', :numcode => '004' :call_code => 93)

使用Excel或OpenOffice电子表格或MySQL实现此目的的任何快速解决方案?

只要我不必手动键入它。

ruby-on-rails excel join formula openoffice-calc
1个回答
0
投票
  1. 将您的Country.create代码行复制到Excel中,例如从A1开始。
  2. 将您的代码列表复制到Excel中,如有必要,将其分为两列(例如,使用Text to Columns)。
  3. 命名结果(比如说CArray)。
  4. 在B1放:=FIND("printable_name => '",A1)+19
  5. 在C1放: =SUBSTITUTE(A1,")"," :call_code => "&VLOOKUP(MID(A1,B1,FIND("'",A1,B1)-B1),cArray,2,0)&")")
  6. 将B1:C1复制到适合的位置。
  7. 尽可能多地将ColumnC复制到您的代码中。

cArray不必在同一张纸上。

© www.soinside.com 2019 - 2024. All rights reserved.