_manager_:: com.sun.star.ServiceManager _hash_:: オプション指定(名前と値の連想配列) ret::オプション指定用の配列
# File OOo_calc.rb, line 923 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
# File OOo_calc.rb, line 1007 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
拡張子がodsなら空の配列を返す。 その他なら対応するフィルター名のプロパティ配列を返す。 =filename_::ファイル名 ret::フィルターオプション(ドキュメント形式名)
# File OOo_calc.rb, line 952 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
# File OOo_calc.rb, line 973 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
# File OOo_calc.rb, line 60 def rgb(red, green, blue) return red << 16 | green << 8 | blue end
_t_:: OOoの日付時刻を表すdoubleの数値
# File OOo_calc.rb, line 68 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