ruby xml excel
require 'win32ole'
fns = Dir.glob("*.xls")
application = WIN32OLE.new("excel.application")
application.visible = TRUE
f = File.new('errorCauseEN.xml','w')
f.puts('<?xml version="1.0" encoding="utf-8"?>')
f.puts('<!-- edited with XMLSPY v5 U (http://www.xmlspy.com) by et8 (et8) -->')
f.puts('<Category>')
fns.each do |file|
workbook = application.WorkBooks.Open(Dir.pwd + '/' + file)
sheet = workbook.WorkSheets(2)
sheet.Activate
i = 2
loop do
break if !sheet.Range('A'+ i.to_s).Value
break if !sheet.Range('C'+ i.to_s).Value
errname = sheet.Range('A'+ i.to_s).Value.to_s.hex.to_i.to_s.strip
valuename = sheet.Range('C'+ i.to_s).Value.strip
valuename.gsub!(/\"/,'\'')
f.puts(' '*4 + '<ErrorCode name="' + errname + '" value="' + valuename +'"/>')
i = i + 1
end
puts file.to_s + ' is OK!'
workbook.close(0)
end
f.puts('</Category>')
f.close
application.Quit()
#workbook = application.WorkBooks.Open('D:/ErrorCase/TR_ErrCode.xls')
--------------------------------------------------------------------------
require 'win32ole'
require 'rexml/document'
include REXML
include REXML::
#fns = Dir.glob("*.xls")
#
application = WIN32OLE.new("excel.application")
#
application.visible = TRUE
#
#fns.each do |file|
# workbook = application.WorkBooks.Open(Dir.pwd + '/' + file)
#
#end
#
f = File.new('errorC.xml','w')
doc = Document.new('<Category />')
workbook = application.WorkBooks.Open('D:/ErrorCase/TR_ErrCode.xls')
sheet = workbook.WorkSheets(2)
sheet.Activate
i = 2
loop do
break if !sheet.Range('A'+ i.to_s).Value
ec = Element.new('ErrorCode')
ec.add_attribute('name',sheet.Range('A'+ i.to_s).Value.to_s.hex.to_
相关文档:
Watir 语法(Web Application Testing in Ruby)
# watir的安装
watie的安装请查看 -> Ruby library的安装
# 使用Watir工具,需要在脚本中加上
require 'watir'
# 创建一个IE的实例
ie = Watir::IE.new
或者在创建的同时直接转到页面
ie = Watir::IE.start('http://www.text.com/')
Watir使用start方法 ......
Ruport官方网站:http://www.rubyreports.org/
本例中将介绍Ruby报表的简单开发
开发环境
OS:WindowsXP
Ruby:Ruby1.8.7
Rails:Rails2.3.5
Mysql:Mysql5.0.9
IDE:Rubymine2.0.1
一、安装gem
安装命令
gem install ruport
gem install ruport-util
gem install acts_as_reportable
二、创建数据库
datab ......
Bignum
+ 加
- 减
* 乘
/ 除
** 指数操作2**2 意思是2的平方
<=> 大于, ......
Ruport中pdf_writer对中文的支持并不好,输出的中文显示的是乱码。上网查了很多资料,也没有找到好的解决方案,无奈只好查看源代码,到底为什么Ruport自带的PDF工具不支持中文输出。
Ruport::Formatter::PDF::Writer中找到以下代码
metrics = load_font_metrics(font)
metrics = PDF::Writer: ......
Installing Ruby from source is my preferred method, although in Ubuntu Feisty you can supposedly install it with apt-get install ruby
now. Here’s the essential packages needed to get a source build working right though and the process I just went through:
sudo apt-get install build-essentia ......