class Object

Constants

DisplayAlerts
Visible

Public Instance Methods

createExcelWorkbook() { |book| ... } click to toggle source

Excelのブック生成

# File excel.rb, line 265
def createExcelWorkbook
  xl = WIN32OLE.new('Excel.Application')
  xl.Visible = false
  xl.DisplayAlerts = false
  book = xl.Workbooks.Add()
  begin
    yield book
  ensure
    xl.Workbooks.Close
    xl.Quit
  end
end
getAbsolutePath(filename) click to toggle source

絶対パス化

# File excel.rb, line 236
def getAbsolutePath filename
  fso = WIN32OLE.new('Scripting.FileSystemObject')
  fn = fso.GetAbsolutePathName(filename).gsub('\','/')
  fn
end
openExcelWorkbook(filename, visible:false, pw:nil) { |book| ... } click to toggle source

Excelのオープン

# File excel.rb, line 244
def openExcelWorkbook (filename, visible:false, pw:nil)
  filename = getAbsolutePath(filename)
  xl = WIN32OLE.new('Excel.Application')
  xl.Visible = visible
  xl.DisplayAlerts = true
  if pw
    book = xl.Workbooks.Open(:FileName=>"#{filename}",:Password=>pw)
  else
    book = xl.Workbooks.Open(filename)
  end

  begin
    yield book
  ensure
    xl.Workbooks.Close
    xl.Quit
  end
end