rubyXL 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. data/Gemfile +16 -0
  2. data/Gemfile.lock +34 -0
  3. data/LICENSE.txt +20 -0
  4. data/README +0 -0
  5. data/README.rdoc +19 -0
  6. data/Rakefile +53 -0
  7. data/VERSION +1 -0
  8. data/lib/.DS_Store +0 -0
  9. data/lib/Hash.rb +60 -0
  10. data/lib/cell.rb +360 -0
  11. data/lib/color.rb +14 -0
  12. data/lib/parser.rb +413 -0
  13. data/lib/private_class.rb +182 -0
  14. data/lib/rubyXL.rb +9 -0
  15. data/lib/test.html +1 -0
  16. data/lib/tests/test.rb +110 -0
  17. data/lib/tests/test10.rb +16 -0
  18. data/lib/tests/test2.rb +118 -0
  19. data/lib/tests/test3.rb +76 -0
  20. data/lib/tests/test4.rb +92 -0
  21. data/lib/tests/test5.rb +90 -0
  22. data/lib/tests/test6.rb +50 -0
  23. data/lib/tests/test7.rb +48 -0
  24. data/lib/tests/test8.rb +12 -0
  25. data/lib/tests/test9.rb +60 -0
  26. data/lib/workbook.rb +336 -0
  27. data/lib/worksheet.rb +1245 -0
  28. data/lib/writer/app_writer.rb +62 -0
  29. data/lib/writer/calc_chain_writer.rb +33 -0
  30. data/lib/writer/content_types_writer.rb +77 -0
  31. data/lib/writer/core_writer.rb +51 -0
  32. data/lib/writer/root_rels_writer.rb +25 -0
  33. data/lib/writer/shared_strings_writer.rb +44 -0
  34. data/lib/writer/styles_writer.rb +376 -0
  35. data/lib/writer/theme_writer.rb +346 -0
  36. data/lib/writer/workbook_rels_writer.rb +59 -0
  37. data/lib/writer/workbook_writer.rb +77 -0
  38. data/lib/writer/worksheet_writer.rb +208 -0
  39. data/lib/zip.rb +20 -0
  40. data/pkg/rubyXL-1.0.4.gem +0 -0
  41. data/rubyXL.gemspec +106 -0
  42. data/spec/lib/cell_spec.rb +359 -0
  43. data/spec/lib/color_spec.rb +14 -0
  44. data/spec/lib/hash_spec.rb +28 -0
  45. data/spec/lib/parser_spec.rb +49 -0
  46. data/spec/lib/workbook_spec.rb +51 -0
  47. data/spec/lib/worksheet_spec.rb +1650 -0
  48. metadata +222 -0
@@ -0,0 +1,9 @@
1
+ $: << File.expand_path(File.dirname(__FILE__))
2
+ require File.expand_path(File.join(File.dirname(__FILE__),'workbook'))
3
+ require File.expand_path(File.join(File.dirname(__FILE__), 'private_class'))
4
+ require File.expand_path(File.join(File.dirname(__FILE__),'worksheet'))
5
+ require File.expand_path(File.join(File.dirname(__FILE__),'cell'))
6
+ require File.expand_path(File.join(File.dirname(__FILE__),'parser'))
7
+
8
+ module RubyXL
9
+ end
@@ -0,0 +1 @@
1
+ <!doctype html><html><head></head><body><h1 style='text-align:center'>/Users/vbhagwat/Documents/excelTestFiles/threeSheetWorkbook/threeSheetWorkbook.xlsx</h1><h2>Sheet1</h2><table border="1"><tr><td style="color:#000000; background-color:#ffffff">1</td></tr></table><br /><br /><h2>ASD</h2><table border="1"><tr><td style="color:#000000; background-color:#ffffff">1</td><td style="color:#000000; background-color:#ffffff">2</td><td style="color:#000000; background-color:#ffffff">3</td></tr></table><br /><br /><h2>asdf</h2><table border="1"><tr><td style="color:#000000; background-color:#ffffff">1</td><td>----</td><td>----</td></tr><tr><td>----</td><td style="color:#000000; background-color:#ffffff">2</td><td>----</td></tr><tr><td>----</td><td>----</td><td style="color:#000000; background-color:#ffffff">3</td></tr></table><br /><br /></body></html>
@@ -0,0 +1,110 @@
1
+ require '../rubyXL'
2
+ require 'rubygems'
3
+ require 'FileUtils'
4
+ require 'nokogiri'
5
+
6
+
7
+ module RubyXL
8
+ #writes blank_workbook to .xlsx
9
+
10
+ # file_p ath = "/Users/vbhagwat/Documents/excelTestFiles/styledWorkbook/styledWorkbook.xlsx"
11
+ # file_path = "/Users/vbhagwat/Documents/excelTestFiles/smallFormulaWorkbook2/smallFormulaWorkbook2.xlsx"
12
+ # file_path = "/Users/vbhagwat/Documents/excelTestFiles/threeSheetWorkbook/threeSheetWorkbook.xlsx"
13
+ # file_path = "/Users/vbhagwat/Documents/excelTestFiles/numWorkbook2/numWorkbook2.xlsx"
14
+ file_path = "/Users/vbhagwat/Documents/excelTestFiles/blankWorkbook/blankWorkbook.xlsx"
15
+ # file_path = '/Users/vbhagwat/Desktop/test2/Archive.xlsx'
16
+ # file_path = "/Users/vbhagwat/Desktop/5-1_5-20.xlsx"
17
+
18
+ # puts 'begin parsing ' + file_path
19
+ # wb = Parser.parse(file_path)
20
+ # puts 'completed parsing ' + file_path
21
+
22
+ # def initialize(worksheets,filepath,creator=nil,modifier=nil,created_at=nil,modified_at=nil, company=nil, application=nil,appversion=nil,
23
+
24
+
25
+ dirpath = '/Users/vbhagwat/Documents/excelTestFiles'
26
+ wb = Workbook.new(
27
+ [], #worksheets
28
+ file_path, #filepath
29
+ 'Vivek Bhagwat', #creator
30
+ 'Vivek Bhagwat', #modifier
31
+ '2011-05-16T15:41:00Z', #created_at
32
+ 'Gilt Groupe', #company
33
+ 'Microsoft Macintosh Excel', #application
34
+ '12.0000')
35
+ wb.worksheets = [Worksheet.new(wb,'Sheet1',[[nil]])]
36
+ wb2 = Workbook.new(
37
+ [], #worksheets
38
+ file_path, #filepath
39
+ 'Vivek Bhagwat', #creator
40
+ 'Vivek Bhagwat', #modifier
41
+ '2011-05-16T15:41:00Z', #created_at
42
+ 'Gilt Groupe', #company
43
+ 'Microsoft Macintosh Excel', #application
44
+ '12.0000')
45
+ wb.worksheets = [Worksheet.new('Sheet1')]
46
+
47
+ wb2[0].sheet_data = [[Cell.new(wb2[0],0,0,'6/8/2011'), Cell.new(wb2[0],0,1,'test2')]]
48
+
49
+ # wb = Parser.parse(file_path)
50
+ file_path = '/Users/vbhagwat/Desktop/test2/Output/blank.xlsx'
51
+ puts 'begin writing ' + file_path
52
+ p wb
53
+ wb.write(file_path)
54
+ puts 'completed writing ' + file_path
55
+
56
+ # file_path = "/Users/vbhagwat/Documents/excelTestFiles/twoSheetWorkbook/twoSheetWorkbook.xlsx"
57
+ file_path = "/Users/vbhagwat/Documents/excelTestFiles/styledWorkbook7/styledWorkbook7.xlsx"
58
+
59
+ wb3 = Parser.parse(file_path)
60
+ wb3.write('/Users/vbhagwat/Desktop/test2/Output/small_before.xlsx')
61
+
62
+
63
+ # file_path = "/Users/vbhagwat/Desktop/5-1_5-20.xlsx"
64
+ wb2 = Parser.parse(file_path)
65
+ file_path = '/Users/vbhagwat/Desktop/test2/Output/small.xlsx'
66
+
67
+ wb2.worksheets[0].change_row_font_name(1,'Courier') #0 indexed.
68
+ wb2.worksheets[0].change_row_font_size(1,30) #0 indexed.
69
+ cell = wb2.worksheets[0].add_cell(0,0,'A1')
70
+ wb2.worksheets[0].change_row_fill(0,'00FF00')
71
+ wb2.worksheets[0].add_cell(0,1,'B1')
72
+
73
+ wb2.worksheets[0].change_column_fill(0,'FFFF00')
74
+ wb2.worksheets[0].change_column_font_size(0,20)
75
+ wb2.worksheets[0].change_column_width(0,30)
76
+ wb2.worksheets[0].change_row_height(2,100)
77
+
78
+
79
+ p wb2.worksheets[0].row_styles
80
+
81
+ wb2.worksheets[0].insert_row(0)
82
+
83
+ wb2.worksheets[0].change_column_width(3,50)
84
+
85
+ wb2.worksheets[0].insert_column(0)
86
+
87
+ p wb2.worksheets[0].row_styles
88
+ # raise 'end'
89
+
90
+ puts 'begin writing ' + file_path
91
+ # p wb2
92
+ wb2[0].change_row_font_color(2,'ffffff')
93
+
94
+ wb2.write(file_path)
95
+ puts 'completed writing ' + file_path
96
+
97
+ # app = Writer::AppWriter.new(dirpath, wb)
98
+ # p app.hash
99
+ # two = app.hash
100
+ # puts ''
101
+ # app.write()
102
+ #
103
+ #
104
+ # str = XmlSimple.xml_out(two)
105
+ # str = str.gsub(/opt/,'Properties')
106
+ # puts '..'
107
+ # p str
108
+
109
+
110
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'rubyXL'
3
+
4
+ @workbook = RubyXL::Workbook.new
5
+ @worksheet = RubyXL::Worksheet.new(@workbook)
6
+ @workbook.worksheets[0] = @worksheet
7
+ (0..10).each do |i|
8
+ (0..10).each do |j|
9
+ @worksheet.add_cell(i, j, "#{i}:#{j}")
10
+ end
11
+ end
12
+
13
+ @worksheet.change_column_font_color(0,'ff0000')
14
+ @worksheet.change_column_font_size(0,"30")
15
+
16
+ @workbook.write('/Users/vbhagwat/Desktop/test2/Output/test10.xlsx')
@@ -0,0 +1,118 @@
1
+ require 'rubygems'
2
+ require 'xmlsimple'
3
+ require 'zip/zip'
4
+ require 'FileUtils'
5
+ require 'zip/zipfilesystem'
6
+ require 'zip'
7
+
8
+ module RubyXL
9
+ #takes /Users/vbhagwat/Desktop/test1/Workbook1.xlsx
10
+ #copies, unzips, zips
11
+
12
+ # #takes path of directoy to be compressed
13
+ # #writes zip in that directory
14
+ # def compress(path)
15
+ # puts 'path'
16
+ # p path
17
+ # path.sub!(%r[/$],'')
18
+ # p path
19
+ # archive = File.join(path,File.basename(path))+'.zip'
20
+ # puts 'archive'
21
+ # p archive
22
+ # FileUtils.rm archive, :force=>true
23
+ # Zip::ZipFile.open(archive, 'w') do |zipfile|
24
+ # Dir["#{path}/**/**"].reject{|f|f==archive}.each do |file|
25
+ # puts 'here'
26
+ # p file.to_s()
27
+ # temp = file
28
+ # p temp.sub(path+'/','')
29
+ # zipfile.add(file.sub(path+'/',''),file)
30
+ # end
31
+ # end
32
+ # end
33
+ #
34
+ # #unzips file
35
+ # def unzip(zipPath,zipDirPath)
36
+ # Zip::ZipFile.open(zipPath) { |zip_file|
37
+ # zip_file.each { |f|
38
+ # fpath = File.join(zipDirPath, f.name)
39
+ # FileUtils.mkdir_p(File.dirname(fpath))
40
+ # zip_file.extract(f, fpath) unless File.exist?(fpath)
41
+ # }
42
+ # }
43
+ # end
44
+
45
+ z = MyZip.new
46
+
47
+
48
+ dirPath = '/Users/vbhagwat/Desktop/test2/'
49
+ filePath = dirPath + 'Workbook1.xlsx'
50
+ zipDirPath = dirPath+'Workbook1/'
51
+ zipPath = zipDirPath + 'Workbook1.zip'
52
+
53
+ FileUtils.mkdir_p(dirPath+'Workbook1')
54
+ FileUtils.cp(filePath,zipPath)
55
+
56
+ z.unzip(zipPath,zipDirPath)
57
+ #TODO test if xml_in then xml_out corrupts it
58
+ # FileUtils.rm(zipPath) #removes zip file created
59
+
60
+ #commented out because i copy this anyway
61
+ # contents = XmlSimple.xml_in(zipDirPath + '[Content_Types].xml')
62
+ # contents = XmlSimple.xml_out(contents).gsub(/<\/?opt>/,'')
63
+ # file = File.new(zipDirPath+'[Content_Types].xml', 'w+')
64
+ # file.write(contents)
65
+ # file.close
66
+
67
+ # contents = XmlSimple.xml_in(zipDirPath+'docProps/app.xml')
68
+ # contents = XmlSimple.xml_out(contents).gsub(/<\/?opt>/,'')
69
+ # file = File.new(zipDirPath+'docProps/app.xml', 'w+')
70
+ # file.write(contents)
71
+ # file.close
72
+ #
73
+ # contents = XmlSimple.xml_in(zipDirPath+'docProps/core.xml')
74
+ # contents = XmlSimple.xml_out(contents).gsub(/<\/?opt>/,'')
75
+ # file = File.new(zipDirPath+'docProps/core.xml', 'w+')
76
+ # file.write(contents)
77
+ # file.close
78
+ #
79
+ # contents = XmlSimple.xml_in(zipDirPath+'xl/_rels/workbook.xml.rels')
80
+ # contents = XmlSimple.xml_out(contents).gsub(/<\/?opt>/,'')
81
+ # file = File.new(zipDirPath+'xl/_rels/workbook.xml.rels', 'w+')
82
+ # file.write(contents)
83
+ # file.close
84
+ #
85
+ # contents = XmlSimple.xml_in(zipDirPath+'xl/styles.xml')
86
+ # contents = XmlSimple.xml_out(contents).gsub(/<\/?opt>/,'')
87
+ # file = File.new(zipDirPath+'xl/styles.xml', 'w+')
88
+ # file.write(contents)
89
+ # file.close
90
+ #
91
+ # contents = XmlSimple.xml_in(zipDirPath+'xl/workbook.xml')
92
+ # contents = XmlSimple.xml_out(contents).gsub(/<\/?opt>/,'')
93
+ # file = File.new(zipDirPath+'xl/workbook.xml', 'w+')
94
+ # file.write(contents)
95
+ # file.close
96
+ #
97
+ # #commented out because i copy this anyway
98
+ # # contents = XmlSimple.xml_in(zipDirPath+'xl/theme/theme1.xml')
99
+ # # contents = XmlSimple.xml_out(contents).gsub(/<\/?opt>/,'')
100
+ # # file = File.new(zipDirPath+'[Content_Types].xml', 'w+')
101
+ # # file.write(contents)
102
+ # # file.close
103
+ #
104
+ # contents = XmlSimple.xml_in(zipDirPath+'xl/worksheets/sheet1.xml')
105
+ # contents = XmlSimple.xml_out(contents).gsub(/<\/?opt>/,'')
106
+ # file = File.new(zipDirPath+'xl/worksheets/sheet1.xml', 'w+')
107
+ # file.write(contents)
108
+ # file.close
109
+
110
+ #TODO manually reorder the xml tags to correlate, then compress using this compression method,
111
+ #(not archive utility), then see if that xlsx file opens
112
+
113
+ z.compress('/Users/vbhagwat/Desktop/test2/Workbook1/')
114
+
115
+
116
+ # compress(dirPath)
117
+
118
+ end
@@ -0,0 +1,76 @@
1
+ require 'rubygems'
2
+ require 'FileUtils'
3
+ require 'writer'
4
+
5
+
6
+ module RubyXL
7
+
8
+ def convertToIndex(cellString)
9
+ index = Array.new(2)
10
+ index[0]=-1
11
+ index[1]=-1
12
+ if(cellString =~ /^([A-Z]+)(\d+)/)
13
+ one = $1.to_s()
14
+ row = Integer($2) - 1 #-1 for 0 indexing
15
+ col = 0
16
+ i = 0
17
+ one = one.reverse #because of 26^i calculation
18
+ one.each_byte do |c|
19
+ intVal = c - 64 #converts A to 1 (0, actually)
20
+ col += intVal * 26**(i)
21
+ i=i+1
22
+ end
23
+ col -= 1 #zer0 index
24
+ index[0] = row
25
+ index[1] = col
26
+ end
27
+ index
28
+ end
29
+
30
+
31
+ #TODO FIX THIS
32
+ def convertToCell(row, col)
33
+ puts "input = (#{row}, #{col})"
34
+ #convert col to letter, convert row to row-1, join
35
+ rowString = (row + 1).to_s #+1 for 0 indexing
36
+ colString = ''
37
+ unless col == 0
38
+ colLength = 1+Integer(Math.log(col) / Math.log(26)) #opposite of 26**
39
+ else
40
+ colLength = 1
41
+ end
42
+
43
+ puts "colLength = #{colLength}"
44
+ 1.upto(colLength) do |i|
45
+ puts "i = #{i}"
46
+ puts "col = #{col}"
47
+ puts "26**(colLength-i) = #{26**(colLength-i)}"
48
+
49
+ if i == colLength
50
+ col+=1
51
+ end
52
+
53
+ if col >= 26**(colLength-i)
54
+ intVal = col / 26**(colLength-i) #+1 for 0 indexing
55
+ intVal += 64 #converts 1 to A, etc.
56
+ puts "intVal = #{intVal}"
57
+ puts "col = #{col}, #{intVal.chr}"
58
+
59
+ # colString = intVal.chr + colString
60
+ colString += intVal.chr
61
+
62
+ puts "colString = #{colString}"
63
+ col -= (intVal-64)*26**(colLength-i)
64
+ end
65
+ end
66
+ p colString
67
+ p rowString
68
+
69
+ colString+rowString
70
+ end
71
+ row = 0
72
+ col = 16168
73
+
74
+ puts "(#{row},#{col})=>#{convertToCell(row,col)}"
75
+
76
+ end
@@ -0,0 +1,92 @@
1
+ require 'rubygems'
2
+ require 'zip/zip'
3
+ # require 'File'
4
+ require 'FileUtils'
5
+
6
+ module RubyXL
7
+ # class Test4
8
+ def write_content_types()
9
+ '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
10
+ <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types"><Default Extension="xml" ContentType="application/xml"/><Override PartName="/xl/workbook.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml"/><Override PartName="/xl/styles.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.styles+xml"/><Default Extension="jpeg" ContentType="image/jpeg"/><Default Extension="rels" ContentType="application/vnd.openxmlformats-package.relationships+xml"/><Override PartName="/xl/theme/theme1.xml" ContentType="application/vnd.openxmlformats-officedocument.theme+xml"/><Override PartName="/xl/worksheets/sheet1.xml" ContentType="application/vnd.openxmlformats-officedocument.spreadsheetml.worksheet+xml"/><Override PartName="/docProps/core.xml" ContentType="application/vnd.openxmlformats-package.core-properties+xml"/><Override PartName="/docProps/app.xml" ContentType="application/vnd.openxmlformats-officedocument.extended-properties+xml"/></Types>'
11
+ end
12
+
13
+ def write_root_rels()
14
+ '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
15
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/><Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/thumbnail" Target="docProps/thumbnail.jpeg"/></Relationships>'
16
+ end
17
+
18
+ def write_core_properties()
19
+ '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
20
+ <cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><dc:creator>Vivek Bhagwat</dc:creator><cp:lastModifiedBy>Vivek Bhagwat</cp:lastModifiedBy><dcterms:created xsi:type="dcterms:W3CDTF">2011-05-25T19:40:48Z</dcterms:created><dcterms:modified xsi:type="dcterms:W3CDTF">2011-05-25T19:40:51Z</dcterms:modified></cp:coreProperties>'
21
+ end
22
+
23
+ def write_app_properties()
24
+ '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
25
+ <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes"><Application>Microsoft Macintosh Excel</Application><DocSecurity>0</DocSecurity><ScaleCrop>false</ScaleCrop><HeadingPairs><vt:vector size="2" baseType="variant"><vt:variant><vt:lpstr>Worksheets</vt:lpstr></vt:variant><vt:variant><vt:i4>1</vt:i4></vt:variant></vt:vector></HeadingPairs><TitlesOfParts><vt:vector size="1" baseType="lpstr"><vt:lpstr>Sheet1</vt:lpstr></vt:vector></TitlesOfParts><Company>Gilt Groupe</Company><LinksUpToDate>false</LinksUpToDate><SharedDoc>false</SharedDoc><HyperlinksChanged>false</HyperlinksChanged><AppVersion>12.0000</AppVersion></Properties>'
26
+ end
27
+
28
+ def write_workbook_rels()
29
+ '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
30
+ <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/></Relationships>'
31
+ end
32
+
33
+ def write_workbook()
34
+ '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
35
+ <workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><fileVersion appName="xl" lastEdited="4" lowestEdited="4" rupBuild="4505"/><workbookPr date1904="1" showInkAnnotation="0" autoCompressPictures="0"/><bookViews><workbookView xWindow="-20" yWindow="-20" windowWidth="34400" windowHeight="22000" tabRatio="500"/></bookViews><sheets><sheet name="Sheet1" sheetId="1" r:id="rId1"/></sheets><calcPr calcId="130407" concurrentCalc="0"/><extLst><ext xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main" uri="http://schemas.microsoft.com/office/mac/excel/2008/main"><mx:ArchID Flags="2"/></ext></extLst></workbook>'
36
+ end
37
+
38
+ #only writes sheet1.xml
39
+ def write_worksheet()
40
+ '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
41
+ <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" mc:Ignorable="mv" mc:PreserveAttributes="mv:*"><dimension ref="A1"/><sheetViews><sheetView tabSelected="1" view="pageLayout" workbookViewId="0"/></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="13"/><sheetData/><phoneticPr fontId="1" type="noConversion"/><pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/><pageSetup orientation="portrait" horizontalDpi="4294967292" verticalDpi="4294967292"/><extLst><ext xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main" uri="http://schemas.microsoft.com/office/mac/excel/2008/main"><mx:PLV Mode="1" OnePage="0" WScale="0"/></ext></extLst></worksheet>'
42
+ end
43
+
44
+ def write_styles()
45
+ '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
46
+ <styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><fonts count="2"><font><sz val="10"/><name val="Verdana"/></font><font><sz val="8"/><name val="Verdana"/></font></fonts><fills count="2"><fill><patternFill patternType="none"/></fill><fill><patternFill patternType="gray125"/></fill></fills><borders count="1"><border><left/><right/><top/><bottom/><diagonal/></border></borders><cellStyleXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0"/></cellStyleXfs><cellXfs count="1"><xf numFmtId="0" fontId="0" fillId="0" borderId="0" xfId="0"/></cellXfs><cellStyles count="1"><cellStyle name="Normal" xfId="0" builtinId="0"/></cellStyles><dxfs count="0"/><tableStyles count="0" defaultTableStyle="TableStyleMedium9"/></styleSheet>'
47
+ end
48
+
49
+ def write_theme()
50
+ '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
51
+ <a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme"><a:themeElements><a:clrScheme name="Office"><a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="1F497D"/></a:dk2><a:lt2><a:srgbClr val="EEECE1"/></a:lt2><a:accent1><a:srgbClr val="4F81BD"/></a:accent1><a:accent2><a:srgbClr val="C0504D"/></a:accent2><a:accent3><a:srgbClr val="9BBB59"/></a:accent3><a:accent4><a:srgbClr val="8064A2"/></a:accent4><a:accent5><a:srgbClr val="4BACC6"/></a:accent5><a:accent6><a:srgbClr val="F79646"/></a:accent6><a:hlink><a:srgbClr val="0000FF"/></a:hlink><a:folHlink><a:srgbClr val="800080"/></a:folHlink></a:clrScheme><a:fontScheme name="Office"><a:majorFont><a:latin typeface="Cambria"/><a:ea typeface=""/><a:cs typeface=""/><a:font script="Jpan" typeface="MS Pゴシック"/><a:font script="Hang" typeface="맑은 고딕"/><a:font script="Hans" typeface="宋体"/><a:font script="Hant" typeface="新細明體"/><a:font script="Arab" typeface="Times New Roman"/><a:font script="Hebr" typeface="Times New Roman"/><a:font script="Thai" typeface="Tahoma"/><a:font script="Ethi" typeface="Nyala"/><a:font script="Beng" typeface="Vrinda"/><a:font script="Gujr" typeface="Shruti"/><a:font script="Khmr" typeface="MoolBoran"/><a:font script="Knda" typeface="Tunga"/><a:font script="Guru" typeface="Raavi"/><a:font script="Cans" typeface="Euphemia"/><a:font script="Cher" typeface="Plantagenet Cherokee"/><a:font script="Yiii" typeface="Microsoft Yi Baiti"/><a:font script="Tibt" typeface="Microsoft Himalaya"/><a:font script="Thaa" typeface="MV Boli"/><a:font script="Deva" typeface="Mangal"/><a:font script="Telu" typeface="Gautami"/><a:font script="Taml" typeface="Latha"/><a:font script="Syrc" typeface="Estrangelo Edessa"/><a:font script="Orya" typeface="Kalinga"/><a:font script="Mlym" typeface="Kartika"/><a:font script="Laoo" typeface="DokChampa"/><a:font script="Sinh" typeface="Iskoola Pota"/><a:font script="Mong" typeface="Mongolian Baiti"/><a:font script="Viet" typeface="Times New Roman"/><a:font script="Uigh" typeface="Microsoft Uighur"/></a:majorFont><a:minorFont><a:latin typeface="Calibri"/><a:ea typeface=""/><a:cs typeface=""/><a:font script="Jpan" typeface="MS Pゴシック"/><a:font script="Hang" typeface="맑은 고딕"/><a:font script="Hans" typeface="宋体"/><a:font script="Hant" typeface="新細明體"/><a:font script="Arab" typeface="Arial"/><a:font script="Hebr" typeface="Arial"/><a:font script="Thai" typeface="Tahoma"/><a:font script="Ethi" typeface="Nyala"/><a:font script="Beng" typeface="Vrinda"/><a:font script="Gujr" typeface="Shruti"/><a:font script="Khmr" typeface="DaunPenh"/><a:font script="Knda" typeface="Tunga"/><a:font script="Guru" typeface="Raavi"/><a:font script="Cans" typeface="Euphemia"/><a:font script="Cher" typeface="Plantagenet Cherokee"/><a:font script="Yiii" typeface="Microsoft Yi Baiti"/><a:font script="Tibt" typeface="Microsoft Himalaya"/><a:font script="Thaa" typeface="MV Boli"/><a:font script="Deva" typeface="Mangal"/><a:font script="Telu" typeface="Gautami"/><a:font script="Taml" typeface="Latha"/><a:font script="Syrc" typeface="Estrangelo Edessa"/><a:font script="Orya" typeface="Kalinga"/><a:font script="Mlym" typeface="Kartika"/><a:font script="Laoo" typeface="DokChampa"/><a:font script="Sinh" typeface="Iskoola Pota"/><a:font script="Mong" typeface="Mongolian Baiti"/><a:font script="Viet" typeface="Arial"/><a:font script="Uigh" typeface="Microsoft Uighur"/></a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="50000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="35000"><a:schemeClr val="phClr"><a:tint val="37000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="15000"/><a:satMod val="350000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="16200000" scaled="1"/></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="100000"/><a:shade val="100000"/><a:satMod val="130000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="50000"/><a:shade val="100000"/><a:satMod val="350000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="16200000" scaled="0"/></a:gradFill></a:fillStyleLst><a:lnStyleLst><a:ln w="9525" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"><a:shade val="95000"/><a:satMod val="105000"/></a:schemeClr></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="25400" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="38100" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="20000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="38000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst><a:scene3d><a:camera prst="orthographicFront"><a:rot lat="0" lon="0" rev="0"/></a:camera><a:lightRig rig="threePt" dir="t"><a:rot lat="0" lon="0" rev="1200000"/></a:lightRig></a:scene3d><a:sp3d><a:bevelT w="63500" h="25400"/></a:sp3d></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="40000"/><a:satMod val="350000"/></a:schemeClr></a:gs><a:gs pos="40000"><a:schemeClr val="phClr"><a:tint val="45000"/><a:shade val="99000"/><a:satMod val="350000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="20000"/><a:satMod val="255000"/></a:schemeClr></a:gs></a:gsLst><a:path path="circle"><a:fillToRect l="50000" t="-80000" r="50000" b="180000"/></a:path></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="80000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="30000"/><a:satMod val="200000"/></a:schemeClr></a:gs></a:gsLst><a:path path="circle"><a:fillToRect l="50000" t="50000" r="50000" b="50000"/></a:path></a:gradFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements><a:objectDefaults><a:spDef><a:spPr/><a:bodyPr/><a:lstStyle/><a:style><a:lnRef idx="1"><a:schemeClr val="accent1"/></a:lnRef><a:fillRef idx="3"><a:schemeClr val="accent1"/></a:fillRef><a:effectRef idx="2"><a:schemeClr val="accent1"/></a:effectRef><a:fontRef idx="minor"><a:schemeClr val="lt1"/></a:fontRef></a:style></a:spDef><a:lnDef><a:spPr/><a:bodyPr/><a:lstStyle/><a:style><a:lnRef idx="2"><a:schemeClr val="accent1"/></a:lnRef><a:fillRef idx="0"><a:schemeClr val="accent1"/></a:fillRef><a:effectRef idx="1"><a:schemeClr val="accent1"/></a:effectRef><a:fontRef idx="minor"><a:schemeClr val="tx1"/></a:fontRef></a:style></a:lnDef></a:objectDefaults><a:extraClrSchemeLst/></a:theme>'
52
+ end
53
+
54
+ filepath = '/Users/vbhagwat/Desktop/blankWorkbook.xlsx'
55
+ dirpath = ''
56
+ if(filepath =~ /((.|\s)*)\.xlsx$/)
57
+ dirpath = $1.to_s()
58
+ end
59
+ filename = ''
60
+ if(filepath =~ /\/((.|\s)*)\/((.|\s)*)\.xlsx$/)
61
+ filename = $3.to_s()
62
+ end
63
+ # p filepath
64
+ # p dirpath
65
+ # p filename
66
+
67
+ zippath = dirpath + '/' + filename + '.zip'
68
+ File.unlink(zippath) if File.exists?(zippath)
69
+ Zip::ZipFile.open(zippath, Zip::ZipFile::CREATE) do |zipfile|
70
+ zipfile.get_output_stream('[Content_Types].xml') {|f| f.puts(write_content_types())}
71
+
72
+ zipfile.get_output_stream('_rels/.rels') {|f| f.puts(write_root_rels())}
73
+
74
+ zipfile.get_output_stream('docProps/app.xml') {|f| f.puts(write_app_properties())}
75
+
76
+ zipfile.get_output_stream('docProps/core.xml') {|f| f.puts(write_core_properties())}
77
+
78
+ zipfile.get_output_stream('xl/theme/theme1.xml') {|f| f.puts(write_theme())}
79
+
80
+ zipfile.get_output_stream('xl/_rels/workbook.xml.rels') {|f| f.puts(write_workbook_rels())}
81
+
82
+ zipfile.get_output_stream('xl/workbook.xml') {|f| f.puts(write_workbook())}
83
+
84
+ zipfile.get_output_stream('xl/styles.xml') {|f| f.puts(write_styles())}
85
+
86
+ zipfile.get_output_stream('xl/worksheets/sheet1.xml') {|f| f.puts(write_worksheet())}
87
+
88
+ zipfile.add('docProps/thumbnail.jpeg','/Users/vbhagwat/Desktop/test2/Workbook1/docProps/thumbnail.jpeg')
89
+ # zipfile.get_output_stream('docProps/thumbnail.jpeg') {|f| }
90
+ end
91
+ # end
92
+ end
@@ -0,0 +1,90 @@
1
+ require '../rubyXL'
2
+ require 'rubygems'
3
+ require 'nokogiri'
4
+ # require File.expand_path(File.join(File.dirname(__FILE__),'Hash'))
5
+ # require File.expand_path(File.join(File.dirname(__FILE__),'cell'))
6
+ # require File.expand_path(File.join(File.dirname(__FILE__),'workbook'))
7
+ # require File.expand_path(File.join(File.dirname(__FILE__),'parser'))
8
+
9
+ # module RubyXL
10
+ file_path = '/Users/vbhagwat/Documents/excelTestFiles/styledWorkbook2/styledWorkbook2.xlsx'
11
+ wb = RubyXL::Parser.parse(file_path)
12
+ puts "parsed #{file_path}"
13
+ p wb.cell_xfs
14
+ cell = wb.worksheets[0].sheet_data[0][0]
15
+ cell2 = wb.worksheets[0].sheet_data[1][1]
16
+ cell3 = wb.worksheets[0].sheet_data[0][2]
17
+
18
+ cell4 = wb.worksheets[0].add_cell(4,4,'test')
19
+ cell5 = wb.worksheets[0].add_cell(4,4,'test2',nil,false)
20
+
21
+ # cells = Array.new()
22
+ #
23
+ # cells << Cell.new(0,3,'black', nil,'str') #8
24
+ # cells << Cell.new(0,4,'white',nil,'str')
25
+ # cells << Cell.new(0,5,'red',nil,'str')
26
+ # cells << Cell.new(0,6,'brightgreen',nil,'str')
27
+ # cells << Cell.new(0,7,'blue',nil,'str')
28
+ # cells << Cell.new(0,8,'yellow',nil,'str')
29
+ # cells << Cell.new(0,9,'magenta',nil,'str')
30
+ # cells << Cell.new(0,10,'cyan',nil,'str')
31
+ # cells << Cell.new(0,11,'darkred',nil,'str')
32
+ # cells << Cell.new(0,12,'green',nil,'str')
33
+ # cells << Cell.new(0,13,'darkblue',nil,'str')
34
+ # cells << Cell.new(0,14,'darkyellow',nil,'str')
35
+ # cells << Cell.new(0,15,'purple',nil,'str')
36
+ # cells << Cell.new(0,16,'teal',nil,'str')
37
+ # cells << Cell.new(0,17,'gray25',nil,'str')
38
+ # cells << Cell.new(0,18,'gray50',nil,'str') #23
39
+ # 19.upto(58) do |ind|
40
+ # cells << Cell.new(0,ind,(ind+5).to_s,nil,'str')
41
+ # end
42
+ #
43
+ # cells.each_with_index do |c,i|
44
+ # wb.worksheets[0].sheet_data[0] << c
45
+ # c.change_fill((i+8).to_s)
46
+ # end
47
+ def print_stuff(wb)
48
+ puts 'begin print_stuff'
49
+ puts ''
50
+ puts ''
51
+ puts ''
52
+ p wb.cell_xfs[:xf][0]
53
+ puts ''
54
+ puts ''
55
+ puts ''
56
+ puts 'end print_stuff'
57
+ end
58
+
59
+ print_stuff(wb)
60
+ cell.change_font_name('Verdana')
61
+ print_stuff(wb)
62
+ cell2.change_font_size(30)
63
+ print_stuff(wb)
64
+ cell.change_fill('ff0000')
65
+ print_stuff(wb)
66
+ wb.worksheets[0].change_row_font_name(1,'Courier')
67
+ print_stuff(wb)
68
+ wb.worksheets[0].change_row_fill(1,'00ff00')
69
+ print_stuff(wb)
70
+ wb.worksheets[0].change_column_font_size(0,20)
71
+ print_stuff(wb)
72
+ cell.change_font_bold(false)
73
+ print_stuff(wb)
74
+ cell2.change_font_underline(true)
75
+ print_stuff(wb)
76
+ cell3.change_fill('000000')
77
+ print_stuff(wb)
78
+ cell3.change_font_name('Verddddana')
79
+ print_stuff(wb)
80
+ # cell3.change_fill('52')
81
+
82
+ wb.write('/Users/vbhagwat/Desktop/test2/Output/cell.xlsx')
83
+
84
+ p wb.style_corrector
85
+
86
+ print_stuff(wb)
87
+ puts 'completed writing /Users/vbhagwat/Desktop/test2/Output/cell.xlsx'
88
+ #TODO
89
+
90
+ # end