Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2014-01-14代码游戏 #24

Open
jinkerry opened this issue Jan 13, 2014 · 4 comments
Open

2014-01-14代码游戏 #24

jinkerry opened this issue Jan 13, 2014 · 4 comments

Comments

@jinkerry
Copy link
Collaborator

背景
Excel是某公司喜闻乐见的测试用例工具,前不久,又研发了新的自动化接口测试框架,使用Excel管理测试数据,效率提升不少。
杰哥的Javelin计划新增一个功能,将自动生成的数据直接输出到Excel文件中。
请你帮助杰哥实现这个功能吧。

步骤

  1. 将user.txt文件内容写入到user.xls中。
    user.txt文件内容如下:
    id,name,age
    100,赵天一,22
    101,钱来易,25
    102,郑钱花,23
  2. 将user.xls同步到自己的台式机

其它

  1. 语言不限
  2. 同步方式采用程序代码实现,推荐但不限于(邮件、网盘、FTP)
@chenkan
Copy link
Owner

chenkan commented Jan 13, 2014

Nice
Good Game

@bingohuang
Copy link
Collaborator

期待,搞起!

@bingohuang
Copy link
Collaborator

#encoding: utf-8

#gem install spreadsheet
require 'spreadsheet'

#require 'net/ftp'
#gem install net-sftp
require 'net/sftp'

FileName_DATA = "user.txt"
FileName_LOCAL = "user.xls"
FileName_REMOTE = "user-remote.xls"
#Dir_REMOTE = "/home/bingo/RubymineProjects/user-test"
Dir_REMOTE = "/home/qadev/user-test"

Spreadsheet.client_encoding = 'UTF-8'

#user.txt文件内容如下:
#input = [
#    ["id", "name", "age"],
#    ["100", "赵天一", "22"],
#    ["101", "钱来易", "25"],
#    ["102", "郑钱花", "23"],
#]

#也可以从本地读取user.txt
#http://snippets.aktagon.com/snippets/246-how-to-parse-csv-data-with-ruby
input = []
File.new(FileName_DATA, 'r').each_line("\n") do |row|
  colums = row.to_s.delete("\n").split(",")
  #colums = row
  puts colums
  input << colums
end
puts input.size

#1. 将user.txt文件内容写入到user.xls中
#https://github.com/zdavatz/spreadsheet
#https://github.com/zdavatz/spreadsheet/blob/master/GUIDE.md
book = Spreadsheet::Workbook.new
write_sheet = book.create_worksheet
row_num = 0
input.each do |row|
  puts "row:#{row}"
  write_sheet.row(row_num).replace row
  row_num +=1
end
book.write FileName_LOCAL

#2. 将user.xls同步到自己的台式机

#SFTP
#https://github.com/net-ssh/net-sftp
#http://rubygems.org/gems/net-sftp
Net::SFTP.start('192.168.145.247', 'qadev', :password => 'xxx', :port => "xxx") do |sftp|
  #sftp.dir.foreach(Dir_REMOTE) do |entry|
  #  puts entry.longname
  #end

  #sftp.mkdir! Dir_REMOTE
  sftp.upload!(FileName_LOCAL, "#{Dir_REMOTE}/#{FileName_REMOTE}")
  sftp.download!("#{Dir_REMOTE}/#{FileName_REMOTE}", FileName_REMOTE)

end

@chenkan
Copy link
Owner

chenkan commented Jan 16, 2014

小兵的_coding_技能越发犀利了!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants