require 'rubygems' require 'zip/zip' # require 'File' require 'FileUtils' module RubyXL # class Test4 def write_content_types() ' ' end def write_root_rels() ' ' end def write_core_properties() ' Vivek BhagwatVivek Bhagwat2011-05-25T19:40:48Z2011-05-25T19:40:51Z' end def write_app_properties() ' Microsoft Macintosh Excel0falseWorksheets1Sheet1Gilt Groupefalsefalsefalse12.0000' end def write_workbook_rels() ' ' end def write_workbook() ' ' end #only writes sheet1.xml def write_worksheet() ' ' end def write_styles() ' ' end def write_theme() ' ' end filepath = '/Users/vbhagwat/Desktop/blankWorkbook.xlsx' dirpath = '' if(filepath =~ /((.|\s)*)\.xlsx$/) dirpath = $1.to_s() end filename = '' if(filepath =~ /\/((.|\s)*)\/((.|\s)*)\.xlsx$/) filename = $3.to_s() end # p filepath # p dirpath # p filename zippath = dirpath + '/' + filename + '.zip' File.unlink(zippath) if File.exists?(zippath) Zip::ZipFile.open(zippath, Zip::ZipFile::CREATE) do |zipfile| zipfile.get_output_stream('[Content_Types].xml') {|f| f.puts(write_content_types())} zipfile.get_output_stream('_rels/.rels') {|f| f.puts(write_root_rels())} zipfile.get_output_stream('docProps/app.xml') {|f| f.puts(write_app_properties())} zipfile.get_output_stream('docProps/core.xml') {|f| f.puts(write_core_properties())} zipfile.get_output_stream('xl/theme/theme1.xml') {|f| f.puts(write_theme())} zipfile.get_output_stream('xl/_rels/workbook.xml.rels') {|f| f.puts(write_workbook_rels())} zipfile.get_output_stream('xl/workbook.xml') {|f| f.puts(write_workbook())} zipfile.get_output_stream('xl/styles.xml') {|f| f.puts(write_styles())} zipfile.get_output_stream('xl/worksheets/sheet1.xml') {|f| f.puts(write_worksheet())} zipfile.add('docProps/thumbnail.jpeg','/Users/vbhagwat/Desktop/test2/Workbook1/docProps/thumbnail.jpeg') # zipfile.get_output_stream('docProps/thumbnail.jpeg') {|f| } end # end end