| 
 
| 赞 | 1 |  
| VIP | 246 |  
| 好人卡 | 87 |  
| 积分 | 1 |  
| 经验 | 34142 |  
| 最后登录 | 2015-1-15 |  
| 在线时间 | 323 小时 |  
 Lv1.梦旅人 
	梦石0 星屑55 在线时间323 小时注册时间2010-8-21帖子666 | 
| 本帖最后由 沙漠点灰 于 2013-5-10 12:38 编辑 
 由玩家完成的话= =无视下面的吧= =
 
 可以用Excel啊,微软提供了接口的。
 
 
 Ruby1.9可用,直接使用
 会将"'D:\Chassis.xls"转换为Hash表存到"D:/Chassis.rxdata"中,
 当然...对数据库的编写格式有规定的。用完需手动关闭excel.exe进程,不知道是不是bug,
 明明关了的= =
 复制代码require 'win32ole' 
WIN32OLE.codepage = WIN32OLE::CP_UTF8
def excel2rx
        excel = WIN32OLE.new("excel.application")
        excelFile = excel.WorkBooks.Open('D:\Chassis.xls') 
        excel.WorkSheets("sheet1").Activate
        data = {}
        # 长宽度确认
        h=1
        loop do
                break unless excel.Cells(h, 1).value
                h += 1
        end
        w=1
        loop do
                 break unless excel.Cells(1, w).value
                 w += 1
        end
        for i in 2..h
                data[excel.Cells(i, 1).value.to_i] = {}
        end
        for i in 2..h
                for j in 2..w
                        if excel.Cells(i, j).value.is_a?(String)
                                if excel.Cells(i, j).value.include?("[")
                                        data[excel.Cells(i, 1).value.to_i][excel.Cells(1, j).value.to_sym] = eval(excel.Cells(i, j).value)
                                else
                                        data[excel.Cells(i, 1).value.to_i][excel.Cells(1, j).value.to_sym] = excel.Cells(i, j).value
                                end
                        else
                                #next unless excel.Cells(i, 1).value.to_i][excel.Cells(1, j).value
                                begin
                                        data[excel.Cells(i, 1).value.to_i][excel.Cells(1, j).value.to_sym] = excel.Cells(i, j).value.to_i
                                rescue
                                        data[excel.Cells(i, 1).value.to_i][excel.Cells(1, j).value] = excel.Cells(i, j).value.to_i
                                end
                        end
                end
        end
        excel.Quit()
        file = File.open("D:/Chassis.rxdata","wb")
        data.delete(0)
        Marshal.dump(data, file)
        file.close
end
excel2rx
 | 
 评分
查看全部评分
 |