在线等: 如何用ruby获取excel表格中某一列的内容,并生成xml文件

Python038

在线等: 如何用ruby获取excel表格中某一列的内容,并生成xml文件,第1张

执行SQL语句

require "dbi"

dbh = DBI.connect("DBI:ODBC:#{db_name}",@user,@password)

sth = dbh.execute(%%1)

提取单条记录

# @database is array of references to anonymous hashes

@database = (

{ name =>"Wild Ginger",

city =>"Seattle",

cuisine =>"Asian Thai Chinese Korean Japanese",

expense =>4,

music =>"\0",

meals =>"lunch dinner",

view =>"\0",

smoking =>"\0",

parking =>"validated",

rating=>4,

payment =>"MC VISA AMEX",

},

# { ... }, etc.

)

sub findRestaurants {

my ($database, $query) = @_

return grep {

$query->{city} ?

lc($query->{city}) eq lc($_->{city}) : 1

and $query->{cuisine} ?

$_->{cuisine} =~ /$query->{cuisine}/i : 1

and $query->{min_expense} ?

$_->{expense} >= $query->{min_expense} : 1

and $query->{max_expense} ?

$_->{expense} <= $query->{max_expense} : 1

and $query->{music} ? $_->{music} : 1

and $query->{music_type} ?

$_->{music} =~ /$query->{music_type}/i : 1

and $query->{meals} ?

$_->{meals} =~ /$query->{meals}/i : 1

and $query->{view} ? $_->{view} : 1

and $query->{smoking} ? $_->{smoking} : 1

and $query->{parking} ? $_->{parking} : 1

and $query->{min_rating} ?

$_->{rating} >= $query->{min_rating} : 1

and $query->{max_rating} ?

$_->{rating} <= $query->{max_rating} : 1

and $query->{payment} ?

$_->{payment} =~ /$query->{payment}/i : 1

} @$database

}

《Ruby程序员修炼之道第2版》百度网盘pdf最新全集下载:

链接:https://pan.baidu.com/s/1k6hnORSDF2YmcCA6y1OiLA

?pwd=tlco 提取码:tlco

简介:这是一本深受好评的书。它不仅是一本纯Ruby的书,也不仅是一本纯Rails的书,而是一本为Rails程序员“优化”过的Ruby书。

比如:

floatnum=‘126,456’

floatnum = floatnum.gsub(/,/,'')#第一参数是要匹配的字符串或字符,第二个参数是要替换的字符串或字符,这里按你的意思,应该是替换成空的

puts floatnum

123456