[ top ] [ prev ] [ up ] [ next ]
Excelシートの名前の一覧を得る。
require 'excel'
require 'file-win32'
filename = FileSystemObject.instance.getAbsolutePathName('inet.xls')
# filename = 'inet.xls'
excel = Excel.new
# Excel.runDuring do |excel|
excel.workbooks.open({'filename'=> filename, 'readOnly' => true})
excel.workbooks.each do |book|
book.worksheets.each do |sheet|
puts sheet.name
end
end
# end
Excelシートをデータベースとして扱う。
ADO を通す。
sheet_names = []
open('sheetnames.txt') do |f|
while f.gets
sheet_names.push chomp
end
end
require 'phi'; include Phi
require 'rdb'; include RDB
require 'com' # CoInitialize
require 'nkf'
data_set = ADODataSet.new
data_set.connection_string = 'Provider=Microsoft.Jet.OLEDB.4.0;Data Source=inet.xls;Mode=Share Deny None;Extended Properties=Excel 8.0;Persist Security Info=False'
data_set.cursor_type = CT_STATIC
sheet_no = 0
sheet_names.each do |sheet_name|
outf = open("inet/%03d.txt"%sheet_no, "w")
outf.puts "#\t#{sheet_name}"
data_set.command_text = sheet_name + '$'
data_set.command_type = CMD_TABLE_DIRECT
data_set.active = true
data_set.first
while not data_set.eof?
outf.puts data_set.fields.map{|field|
NKF.nkf('-XSs', field.value.to_s)
}.join("\t")
data_set.next
end
data_set.active = false
outf.close
sheet_no+= 1
end
Phi.mainloop
[ top ] [ prev ] [ up ] [ next ]