Top Level Namespace

Defined Under Namespace

Modules: TrailExcel, Worksheet

Instance Method Summary collapse

Instance Method Details

#createExcelWorkbookObject

Excelのブック生成



270
271
272
273
274
275
276
277
278
279
280
281
# File 'lib/trail_excel.rb', line 270

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) ⇒ Object

絶対パス化



241
242
243
244
245
# File 'lib/trail_excel.rb', line 241

def getAbsolutePath filename
  fso = WIN32OLE.new('Scripting.FileSystemObject')
  fn = fso.GetAbsolutePathName(filename).gsub('\\','/')
  fn
end

#openExcelWorkbook(filename, visible: false, pw: nil) ⇒ Object

Excelのオープン



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/trail_excel.rb', line 249

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