class Aio::Base::Toolkit::ExcelOffice::WorkBook
Constants
- DisplayAlerts
- HorizontalAlignment
- View
Public Class Methods
bold_style(sty)
click to toggle source
# File lib/aio/base/toolkit/excel_office.rb, line 66 def self.bold_style(sty) sty.font.size = 9 sty.font.bold = true sty.HorizontalAlignment = -4108 end
new(encoding = "utf-8")
click to toggle source
# File lib/aio/base/toolkit/excel_office.rb, line 8 def initialize(encoding = "utf-8") if Aio::Base::Toolkit::OS.windows? require "win32ole" else print_error "只有Windows系统才能使用Excel模块" exit 0 end @excel = WIN32OLE.new("excel.Application") @excel.visible = false @workbook = @excel.workbooks.add @encoding = encoding create_style end
normal_style(sty)
click to toggle source
# File lib/aio/base/toolkit/excel_office.rb, line 61 def self.normal_style(sty) sty.font.size = 9 sty.HorizontalAlignment = -4108 end
title_style(sty)
click to toggle source
# File lib/aio/base/toolkit/excel_office.rb, line 72 def self.title_style(sty) sty.font.size = 20 sty.font.bold = true sty.HorizontalAlignment = -4108 end
Public Instance Methods
add_worksheet(name)
click to toggle source
# File lib/aio/base/toolkit/excel_office.rb, line 39 def add_worksheet(name) while @@worksheets_name.include?(name) name += "1" end @@worksheets_name << name worksheet = @workbook.worksheets.add worksheet.activate worksheet.name = name return WorkSheet.new(worksheet) end
close()
click to toggle source
# File lib/aio/base/toolkit/excel_office.rb, line 87 def close @workbook.close @excel.quit end
create_style()
click to toggle source
# File lib/aio/base/toolkit/excel_office.rb, line 50 def create_style sty = @workbook.styles.add("NormalStyle") self.class.normal_style(sty) sty = @workbook.styles.add("BoldStyle") self.class.bold_style(sty) sty = @workbook.styles.add("TitleStyle") self.class.title_style(sty) end
display_alerts=(bool)
click to toggle source
警告提示开关
# File lib/aio/base/toolkit/excel_office.rb, line 35 def display_alerts=(bool) @excel.DisplayAlerts = bool end
save(path)
click to toggle source
# File lib/aio/base/toolkit/excel_office.rb, line 82 def save(path) path = Aio::Base::Toolkit::String.safe_path(path) @workbook.saveas(path) end
show()
click to toggle source
# File lib/aio/base/toolkit/excel_office.rb, line 78 def show @excel.visible = true end
window_normal()
click to toggle source
切换到普通视图
# File lib/aio/base/toolkit/excel_office.rb, line 30 def window_normal @excel.ActiveWindow.View = 1 end
window_pagebreak()
click to toggle source
切换到分页预览视图
# File lib/aio/base/toolkit/excel_office.rb, line 25 def window_pagebreak @excel.ActiveWindow.View = 2 end