class Object

Constants

Document_Types
Name
Value

Public Instance Methods

_opts(manager,hash) click to toggle source

オプション指定用配列の作成

_manager_:: com.sun.star.ServiceManager
_hash_:: オプション指定(名前と値の連想配列)
ret::オプション指定用の配列
# File Trail_Calc.rb, line 921
def _opts(manager,hash)
  hash.inject(opts = []) {|x,y|
    opt = manager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
    opt[0].Name = y[0]
    opt[0].Value = y[1]
    x << opt
  }
  opts
end
createCalcWorkbook(visible=true) { |book| ... } click to toggle source
# File Trail_Calc.rb, line 1005
def createCalcWorkbook visible=true
  manager = WIN32OLE.new("com.sun.star.ServiceManager")
  $manager = manager
  desktop = manager.createInstance("com.sun.star.frame.Desktop")
  if visible
    book    = desktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, [])
  else
    book    = desktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, _opts(manager,{"Hidden" => true}))
  end
  book.extend(OOoDocument)
  
  begin
    yield book
  ensure
    book.close(false)
  end
##  desktop.terminate   ## 開いている他のOOoドキュメントも道ずれにしてすべて終了してしまう

end
getAbsolutePath(filename) click to toggle source

絶対パスの取得

_filename_ :: ファイル名
# File Trail_Calc.rb, line 91
def getAbsolutePath filename
  fso = WIN32OLE.new('Scripting.FileSystemObject')
  fn = fso.GetAbsolutePathName(filename)
  fn.gsub!(/\/,'/')
  fn
end
get_filtername_option( filename) click to toggle source

ドキュメント形式名取り出し

 拡張子がodsなら空の配列を返す。
 その他なら対応するフィルター名のプロパティ配列を返す。
=filename_::ファイル名
ret::フィルターオプション(ドキュメント形式名)
# File Trail_Calc.rb, line 950
def get_filtername_option( filename)
  filename =~ /\.([^\/\.\]+?)$/
  ext = $1
  return [] if (ext == nil) or (ext == '')
  ext.downcase!

  return [] if ext == 'ods'
  t = Document_Types[ext]
  return [] if !t
  return _opts($manager,{"FilterName"=>t})

end
openCalcWorkbook(filename, visible=true) { |book| ... } click to toggle source
# File Trail_Calc.rb, line 971
def openCalcWorkbook filename, visible=true
  if filename !~ /^file\:\/\/\//
    filename = 'file:///'+getAbsolutePath(filename)
  end
  manager = WIN32OLE.new("com.sun.star.ServiceManager")
  $manager = manager
  desktop = manager.createInstance("com.sun.star.frame.Desktop")
  
  options = []
#  options += get_filtername_option(filename)
  options += _opts(manager,{"Hidden" => true}) if !visible
  
  book     = desktop.loadComponentFromURL(filename, "_blank", 0,options)

  book.extend(OOoDocument)

  begin
    yield book
  ensure
    book.close(false)
  end
##  desktop.terminate   ## 開いている他のOOoドキュメントも道ずれにしてすべて終了してしまう
  
end
rgb(red, green, blue) click to toggle source
# File Trail_Calc.rb, line 62
def rgb(red, green, blue)
  return red << 16 | green << 8 | blue
end
time_ooo2ruby(t) click to toggle source

OpenOffice.orgの時刻からrubyの時刻へ変換

_t_:: OOoの日付時刻を表すdoubleの数値
# File Trail_Calc.rb, line 70
def time_ooo2ruby(t)  ## t はOOoの日付時刻を表すdoubleの数値
  #OOoの基準はデフォルトだと1899/12/30日
  #Appleは1904/1/1, StartOfficeは1900/1/1
  #rubyは1970//1/1 9:0:0 (JSTだから+9時間)
  diff = -2209194000  # Time.at(Time.new(1899,12,30)).to_i
  Time.at(t * 24 * 60 * 60 + diff +0.1) ## 0.1は微妙な変換誤差の補正用
end
time_ruby2ooo(t) click to toggle source

rubyの時刻からOpenOffice.orgの時刻へ変換

_t_:: rubyのTimeオブジェクト
# File Trail_Calc.rb, line 82
def time_ruby2ooo(t)  ## t rubyのTimeオブジェクト
  diff = -2209194000  # Time.at(Time.new(1899,12,30)).to_i
  d = (t.to_i - diff)/(24.0 * 60.0 * 60.0)
end