surpass 0.0.4 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. data/History.txt +4 -0
  2. data/README.txt +3 -20
  3. data/Rakefile +2 -13
  4. data/bin/surpass +8 -0
  5. data/examples/big-16mb.rb +25 -0
  6. data/examples/big-random-strings.rb +28 -0
  7. data/examples/blanks.rb +34 -0
  8. data/examples/blanks.xls +0 -0
  9. data/examples/col_width.rb +16 -0
  10. data/examples/col_width.xls +0 -0
  11. data/examples/dates.rb +31 -0
  12. data/examples/dates.xls +0 -0
  13. data/examples/format.rb +23 -0
  14. data/examples/format.xls +0 -0
  15. data/examples/hello-world.rb +9 -0
  16. data/examples/hello-world.xls +0 -0
  17. data/examples/image.rb +10 -0
  18. data/examples/image.xls +0 -0
  19. data/examples/merged.rb +36 -0
  20. data/examples/merged.xls +0 -0
  21. data/examples/merged0.rb +27 -0
  22. data/examples/merged0.xls +0 -0
  23. data/examples/merged1.rb +99 -0
  24. data/examples/merged1.xls +0 -0
  25. data/examples/num_formats.rb +55 -0
  26. data/examples/num_formats.xls +0 -0
  27. data/examples/numbers.rb +24 -0
  28. data/examples/numbers.xls +0 -0
  29. data/examples/outline.rb +110 -0
  30. data/examples/outline.xls +0 -0
  31. data/examples/panes.rb +48 -0
  32. data/examples/panes.xls +0 -0
  33. data/examples/protection.rb +132 -0
  34. data/examples/protection.xls +0 -0
  35. data/examples/python.bmp +0 -0
  36. data/examples/row_styles.rb +16 -0
  37. data/examples/row_styles.xls +0 -0
  38. data/examples/row_styles_empty.rb +15 -0
  39. data/examples/row_styles_empty.xls +0 -0
  40. data/examples/set_cell_and_range_style.rb +12 -0
  41. data/examples/set_cell_and_range_style.xls +0 -0
  42. data/examples/wrapped-text.rb +13 -0
  43. data/examples/wrapped-text.xls +0 -0
  44. data/examples/write_arrays.rb +22 -0
  45. data/examples/write_arrays.xls +0 -0
  46. data/examples/ws_props.rb +80 -0
  47. data/lib/surpass/ExcelFormula.g +366 -0
  48. data/lib/surpass/ExcelFormula.tokens +30 -0
  49. data/lib/surpass/ExcelFormulaLexer.rb +922 -0
  50. data/lib/surpass/ExcelFormulaParser.rb +602 -0
  51. data/lib/{biff_record.rb → surpass/biff_record.rb} +0 -0
  52. data/lib/{bitmap.rb → surpass/bitmap.rb} +0 -0
  53. data/lib/{cell.rb → surpass/cell.rb} +2 -34
  54. data/lib/{chart.rb → surpass/chart.rb} +0 -0
  55. data/lib/{column.rb → surpass/column.rb} +0 -0
  56. data/lib/{document.rb → surpass/document.rb} +0 -0
  57. data/lib/surpass/excel_formula.rb +23 -0
  58. data/lib/{excel_magic.rb → surpass/excel_magic.rb} +0 -0
  59. data/lib/{formatting.rb → surpass/formatting.rb} +93 -53
  60. data/lib/{row.rb → surpass/row.rb} +0 -0
  61. data/lib/{style.rb → surpass/style.rb} +2 -1
  62. data/lib/surpass/tokens.txt +2 -0
  63. data/lib/{utilities.rb → surpass/utilities.rb} +0 -0
  64. data/lib/{workbook.rb → surpass/workbook.rb} +0 -0
  65. data/lib/{worksheet.rb → surpass/worksheet.rb} +15 -6
  66. data/lib/surpass.rb +1 -1
  67. data/spec/biff_record_spec.rb +268 -0
  68. data/spec/cell_spec.rb +56 -0
  69. data/spec/data/random-strings.txt +10000 -0
  70. data/spec/document_spec.rb +168 -0
  71. data/spec/excel_formula_spec.rb +27 -0
  72. data/spec/formatting_spec.rb +53 -0
  73. data/spec/output/cells-rk.xls +0 -0
  74. data/spec/output/cells.xls +0 -0
  75. data/spec/output/mini.xls +0 -0
  76. data/spec/reference/P-0508-0000507647-3280-5298.xls +0 -0
  77. data/spec/reference/all-cell-styles.bin +0 -0
  78. data/spec/reference/all-number-formats.bin +0 -0
  79. data/spec/reference/all-styles.bin +0 -0
  80. data/spec/reference/mini.xls +0 -0
  81. data/spec/row_spec.rb +19 -0
  82. data/spec/spec_helper.rb +10 -0
  83. data/spec/style_spec.rb +89 -0
  84. data/spec/surpass_spec.rb +7 -0
  85. data/spec/utilities_spec.rb +57 -0
  86. data/spec/workbook_spec.rb +48 -0
  87. data/spec/worksheet_spec.rb +0 -0
  88. data/stats/cloc.txt +8 -0
  89. data/stats/rcov.txt +0 -0
  90. data/stats/specdoc.txt +158 -0
  91. data/surpass.gemspec +40 -0
  92. data/tasks/setup.rb +1 -1
  93. data/tasks/zentest.rake +36 -0
  94. data/webby/README.txt +6 -0
  95. data/webby/Sitefile +43 -0
  96. data/webby/content/css/pygments.txt +6 -0
  97. data/webby/content/css/style.css +279 -0
  98. data/webby/content/examples/autoformat.png +0 -0
  99. data/webby/content/examples/autoformat.rb +32 -0
  100. data/webby/content/examples/autoformat.xls +0 -0
  101. data/webby/content/examples/borders.png +0 -0
  102. data/webby/content/examples/borders.rb +15 -0
  103. data/webby/content/examples/borders.xls +0 -0
  104. data/webby/content/examples/colours.png +0 -0
  105. data/webby/content/examples/colours.rb +23 -0
  106. data/webby/content/examples/colours.xls +0 -0
  107. data/webby/content/examples/data.png +0 -0
  108. data/webby/content/examples/data.rb +11 -0
  109. data/webby/content/examples/data.xls +0 -0
  110. data/webby/content/examples/formatting.png +0 -0
  111. data/webby/content/examples/formatting.rb +78 -0
  112. data/webby/content/examples/formatting.xls +0 -0
  113. data/webby/content/examples/hello-world.png +0 -0
  114. data/webby/content/examples/hello-world.py +8 -0
  115. data/webby/content/examples/hello-world.rb +9 -0
  116. data/webby/content/examples/hello-world.xls +0 -0
  117. data/webby/content/examples/number-format-string.png +0 -0
  118. data/webby/content/examples/number-format-string.rb +14 -0
  119. data/webby/content/examples/number-format-string.xls +0 -0
  120. data/webby/content/examples/patterns.png +0 -0
  121. data/webby/content/examples/patterns.rb +26 -0
  122. data/webby/content/examples/patterns.xls +0 -0
  123. data/webby/content/examples/show-greens.sh +1 -0
  124. data/webby/content/examples/surpass-info.sh +1 -0
  125. data/webby/content/img/Thumbs.db +0 -0
  126. data/webby/content/img/bg_menu.gif +0 -0
  127. data/webby/content/img/bg_t.gif +0 -0
  128. data/webby/content/img/bullet.gif +0 -0
  129. data/webby/content/img/logo.png +0 -0
  130. data/webby/content/img/logo_.jpg +0 -0
  131. data/webby/content/img/top_bg.gif +0 -0
  132. data/webby/content/img/top_bg_.gif +0 -0
  133. data/webby/content/index.txt +16 -0
  134. data/webby/content/installation/index.txt +24 -0
  135. data/webby/content/source/ExcelFormulaLexer.txt +7 -0
  136. data/webby/content/source/ExcelFormulaParser.txt +7 -0
  137. data/webby/content/source/biff_record.txt +7 -0
  138. data/webby/content/source/bitmap.txt +7 -0
  139. data/webby/content/source/cell.txt +7 -0
  140. data/webby/content/source/chart.txt +7 -0
  141. data/webby/content/source/column.txt +7 -0
  142. data/webby/content/source/document.txt +7 -0
  143. data/webby/content/source/excel_formula.txt +7 -0
  144. data/webby/content/source/excel_magic.txt +7 -0
  145. data/webby/content/source/formatting.txt +7 -0
  146. data/webby/content/source/row.txt +7 -0
  147. data/webby/content/source/style.txt +7 -0
  148. data/webby/content/source/utilities.txt +7 -0
  149. data/webby/content/source/workbook.txt +7 -0
  150. data/webby/content/source/worksheet.txt +7 -0
  151. data/webby/content/surpass-manual.erb +198 -0
  152. data/webby/layouts/book.txt +29 -0
  153. data/webby/layouts/default.txt +27 -0
  154. data/webby/layouts/two_column.txt +25 -0
  155. data/webby/layouts/web.txt +66 -0
  156. data/webby/output/.cairn +0 -0
  157. data/webby/output/css/blueprint/ie.css +26 -0
  158. data/webby/output/css/blueprint/plugins/buttons/icons/cross.png +0 -0
  159. data/webby/output/css/blueprint/plugins/buttons/icons/key.png +0 -0
  160. data/webby/output/css/blueprint/plugins/buttons/icons/tick.png +0 -0
  161. data/webby/output/css/blueprint/plugins/buttons/readme.txt +32 -0
  162. data/webby/output/css/blueprint/plugins/buttons/screen.css +97 -0
  163. data/webby/output/css/blueprint/plugins/fancy-type/readme.txt +14 -0
  164. data/webby/output/css/blueprint/plugins/fancy-type/screen.css +71 -0
  165. data/webby/output/css/blueprint/plugins/link-icons/icons/doc.png +0 -0
  166. data/webby/output/css/blueprint/plugins/link-icons/icons/email.png +0 -0
  167. data/webby/output/css/blueprint/plugins/link-icons/icons/external.png +0 -0
  168. data/webby/output/css/blueprint/plugins/link-icons/icons/feed.png +0 -0
  169. data/webby/output/css/blueprint/plugins/link-icons/icons/im.png +0 -0
  170. data/webby/output/css/blueprint/plugins/link-icons/icons/pdf.png +0 -0
  171. data/webby/output/css/blueprint/plugins/link-icons/icons/visited.png +0 -0
  172. data/webby/output/css/blueprint/plugins/link-icons/icons/xls.png +0 -0
  173. data/webby/output/css/blueprint/plugins/link-icons/readme.txt +18 -0
  174. data/webby/output/css/blueprint/plugins/link-icons/screen.css +40 -0
  175. data/webby/output/css/blueprint/plugins/rtl/readme.txt +10 -0
  176. data/webby/output/css/blueprint/plugins/rtl/screen.css +109 -0
  177. data/webby/output/css/blueprint/print.css +30 -0
  178. data/webby/output/css/blueprint/screen.css +251 -0
  179. data/webby/output/css/blueprint/src/forms.css +49 -0
  180. data/webby/output/css/blueprint/src/grid.css +212 -0
  181. data/webby/output/css/blueprint/src/grid.png +0 -0
  182. data/webby/output/css/blueprint/src/ie.css +59 -0
  183. data/webby/output/css/blueprint/src/print.css +85 -0
  184. data/webby/output/css/blueprint/src/reset.css +38 -0
  185. data/webby/output/css/blueprint/src/typography.css +105 -0
  186. data/webby/output/css/pygments.css +59 -0
  187. data/webby/output/css/site.css +62 -0
  188. data/webby/output/css/style.css +279 -0
  189. data/webby/output/examples/autoformat.png +0 -0
  190. data/webby/output/examples/autoformat.rb +32 -0
  191. data/webby/output/examples/autoformat.xls +0 -0
  192. data/webby/output/examples/borders.png +0 -0
  193. data/webby/output/examples/borders.rb +15 -0
  194. data/webby/output/examples/borders.xls +0 -0
  195. data/webby/output/examples/colours.png +0 -0
  196. data/webby/output/examples/colours.rb +23 -0
  197. data/webby/output/examples/colours.xls +0 -0
  198. data/webby/output/examples/data.png +0 -0
  199. data/webby/output/examples/data.rb +11 -0
  200. data/webby/output/examples/data.xls +0 -0
  201. data/webby/output/examples/formatting.png +0 -0
  202. data/webby/output/examples/formatting.rb +78 -0
  203. data/webby/output/examples/formatting.xls +0 -0
  204. data/webby/output/examples/hello-world.png +0 -0
  205. data/webby/output/examples/hello-world.py +8 -0
  206. data/webby/output/examples/hello-world.rb +9 -0
  207. data/webby/output/examples/hello-world.xls +0 -0
  208. data/webby/output/examples/number-format-string.png +0 -0
  209. data/webby/output/examples/number-format-string.rb +14 -0
  210. data/webby/output/examples/number-format-string.xls +0 -0
  211. data/webby/output/examples/patterns.png +0 -0
  212. data/webby/output/examples/patterns.rb +26 -0
  213. data/webby/output/examples/patterns.xls +0 -0
  214. data/webby/output/examples/show-greens.sh +1 -0
  215. data/webby/output/examples/surpass-info.sh +1 -0
  216. data/webby/output/img/Thumbs.db +0 -0
  217. data/webby/output/img/bg_menu.gif +0 -0
  218. data/webby/output/img/bg_t.gif +0 -0
  219. data/webby/output/img/bullet.gif +0 -0
  220. data/webby/output/img/logo.png +0 -0
  221. data/webby/output/img/logo_.jpg +0 -0
  222. data/webby/output/img/top_bg.gif +0 -0
  223. data/webby/output/img/top_bg_.gif +0 -0
  224. data/webby/output/index.html +138 -0
  225. data/webby/output/installation/index.html +64 -0
  226. data/webby/output/installation/installation.html +1 -0
  227. data/webby/output/installation.html +1 -0
  228. data/webby/output/source/ExcelFormulaLexer.html +981 -0
  229. data/webby/output/source/ExcelFormulaParser.html +661 -0
  230. data/webby/output/source/biff_record.html +462 -0
  231. data/webby/output/source/bitmap.html +277 -0
  232. data/webby/output/source/cell.html +241 -0
  233. data/webby/output/source/chart.html +64 -0
  234. data/webby/output/source/column.html +99 -0
  235. data/webby/output/source/document.html +465 -0
  236. data/webby/output/source/excel_formula.html +82 -0
  237. data/webby/output/source/excel_magic.html +1072 -0
  238. data/webby/output/source/formatting.html +664 -0
  239. data/webby/output/source/row.html +169 -0
  240. data/webby/output/source/style.html +158 -0
  241. data/webby/output/source/surpass.html +110 -0
  242. data/webby/output/source/utilities.html +145 -0
  243. data/webby/output/source/workbook.html +265 -0
  244. data/webby/output/source/worksheet.html +331 -0
  245. data/webby/output/surpass-manual-0-0-5.pdf +0 -0
  246. data/webby/output/surpass-manual.aux +50 -0
  247. data/webby/output/surpass-manual.log +366 -0
  248. data/webby/output/surpass-manual.out +20 -0
  249. data/webby/output/surpass-manual.tex +582 -0
  250. data/webby/output/surpass-manual.toc +20 -0
  251. data/webby/rsync-exclude +7 -0
  252. data/webby/tasks/latex.rake +14 -0
  253. data/webby/tasks/screenshots.rb +58 -0
  254. data/webby/templates/article.erb +15 -0
  255. data/webby/templates/book.erb +16 -0
  256. data/webby/templates/page.erb +9 -0
  257. metadata +302 -24
  258. data/bin/surpass-info +0 -20
  259. data/lib/excel_formula.rb +0 -6
@@ -8,7 +8,6 @@ module Formatting
8
8
  'brown' => 0x3c,
9
9
  'coral' => 0x1d,
10
10
  'cornflower-blue' => 0x18,
11
- 'cyan' => 0x0F,
12
11
  'dark-blue' => 0x12,
13
12
  'dark-green' => 0x3a,
14
13
  'dark-red' => 0x10,
@@ -32,17 +31,14 @@ module Formatting
32
31
  'light-orange' => 0x34,
33
32
  'light-turquoise' => 0x29,
34
33
  'light-yellow' => 0x2b,
35
- 'lime' => 0x0B,
36
34
  'lime' => 0x32,
37
35
  'magenta' => 0x0E,
38
36
  'maroon' => 0x19,
39
- 'navy' => 0x12,
40
37
  'olive-green' => 0x3b,
41
38
  'orange' => 0x35,
42
39
  'orchid' => 0x1c,
43
40
  'pale-blue' => 0x2c,
44
41
  'pink' => 0x21,
45
- 'pink' => 0xe,
46
42
  'plum' => 0x3d,
47
43
  'purple' => 0x14,
48
44
  'red' => 0x0A,
@@ -115,7 +111,7 @@ class Font
115
111
  attr_accessor :shadow
116
112
  attr_accessor :colour_index
117
113
  attr_accessor :bold
118
- attr_accessor :weight # In practice, seems to be only 400 = normal, 700 = bold so just use bold = true.
114
+ attr_accessor :weight # Looks like only 400 = normal, 700 = bold are supported so just use bold = true.
119
115
  attr_accessor :escapement
120
116
  attr_accessor :charset
121
117
  attr_accessor :name
@@ -410,6 +406,10 @@ class Borders
410
406
  LINE_TYPE_DIRECTIVES.collect {|k, v| v}
411
407
  end
412
408
 
409
+ def self.line_type_directives_hash
410
+ Hash[*LINE_TYPE_DIRECTIVES.flatten]
411
+ end
412
+
413
413
  def initialize(hash = {})
414
414
  @left = NO_LINE
415
415
  @right = NO_LINE
@@ -456,8 +456,7 @@ class Borders
456
456
  end
457
457
 
458
458
  if Borders.line_type_directives.include?(a)
459
- line_type_directives_hash = Hash[*LINE_TYPE_DIRECTIVES.flatten]
460
- instructions[0] = line_type_directives_hash[a]
459
+ instructions[0] = Borders.line_type_directives_hash[a]
461
460
  next
462
461
  end
463
462
 
@@ -488,50 +487,64 @@ class Borders
488
487
  @bottom, @bottom_colour = process_directives(directives)
489
488
  end
490
489
  end
491
- # public final static short NO_FILL = 0 ;
492
- # /** Solidly filled */
493
- # public final static short SOLID_FOREGROUND = 1 ;
494
- # /** Small fine dots */
495
- # public final static short FINE_DOTS = 2 ;
496
- # /** Wide dots */
497
- # public final static short ALT_BARS = 3 ;
498
- # /** Sparse dots */
499
- # public final static short SPARSE_DOTS = 4 ;
500
- # /** Thick horizontal bands */
501
- # public final static short THICK_HORZ_BANDS = 5 ;
502
- # /** Thick vertical bands */
503
- # public final static short THICK_VERT_BANDS = 6 ;
504
- # /** Thick backward facing diagonals */
505
- # public final static short THICK_BACKWARD_DIAG = 7 ;
506
- # /** Thick forward facing diagonals */
507
- # public final static short THICK_FORWARD_DIAG = 8 ;
508
- # /** Large spots */
509
- # public final static short BIG_SPOTS = 9 ;
510
- # /** Brick-like layout */
511
- # public final static short BRICKS = 10 ;
512
- # /** Thin horizontal bands */
513
- # public final static short THIN_HORZ_BANDS = 11 ;
514
- # /** Thin vertical bands */
515
- # public final static short THIN_VERT_BANDS = 12 ;
516
- # /** Thin backward diagonal */
517
- # public final static short THIN_BACKWARD_DIAG = 13 ;
518
- # /** Thin forward diagonal */
519
- # public final static short THIN_FORWARD_DIAG = 14 ;
520
- # /** Squares */
521
- # public final static short SQUARES = 15 ;
522
- # /** Diamonds */
523
- # public final static short DIAMONDS = 16 ;
524
- # /** Less Dots */
525
- # public final static short LESS_DOTS = 17 ;
526
- # /** Least Dots */
527
- # public final static short LEAST_DOTS = 18 ;
490
+
491
+
528
492
  class Pattern
529
493
  NO_PATTERN = 0x00
530
- SOLID_PATTERN = 0x01
494
+ SOLID_FOREGROUND = 0x01
495
+ SOLID_PATTERN = SOLID_FOREGROUND # for backwards compatibility
496
+ FINE_DOTS = 0x02
497
+ ALT_BARS = 0x03
498
+ SPARSE_DOTS = 0x04
499
+ THICK_HORZ_BANDS = 0x05
500
+ THICK_VERT_BANDS = 0x06
501
+ THICK_BACKWARD_DIAG = 0x07
502
+ THICK_FORWARD_DIAG = 0x08
503
+ BIG_SPOTS = 0x09
504
+ BRICKS = 0x0A
505
+ THIN_HORZ_BANDS = 0x0B
506
+ THIN_VERT_BANDS = 0x0C
507
+ THIN_BACKWARD_DIAG = 0x0D
508
+ THIN_FORWARD_DIAG = 0x0E
509
+ SQUARES = 0x0F
510
+ DIAMONDS = 0x10
511
+ LESS_DOTS = 0x11
512
+ LEAST_DOTS = 0x12
531
513
 
532
- attr_accessor :pattern
533
- attr_accessor :pattern_fore_colour
534
- attr_accessor :pattern_back_colour
514
+ # Want to keep these sorted in this order, so need nested array instead of hash.
515
+ PATTERN_DIRECTIVES = [
516
+ ['none', NO_PATTERN],
517
+ ['solid', SOLID_FOREGROUND],
518
+ ['fine-dots', FINE_DOTS],
519
+ ['alt-bars', ALT_BARS],
520
+ ['sparse-dots', SPARSE_DOTS],
521
+ ['thick-horz-bands', THICK_HORZ_BANDS],
522
+ ['thick-vert-bands', THICK_VERT_BANDS],
523
+ ['thick-backward-diag', THICK_BACKWARD_DIAG],
524
+ ['thick-forward-diag', THICK_FORWARD_DIAG],
525
+ ['big-spots', BIG_SPOTS],
526
+ ['bricks', BRICKS],
527
+ ['thin-horz-bands', THIN_HORZ_BANDS],
528
+ ['thin-vert-bands', THIN_VERT_BANDS],
529
+ ['thin-backward-diag', THIN_BACKWARD_DIAG],
530
+ ['thin-forward-diag', THIN_FORWARD_DIAG],
531
+ ['squares', SQUARES],
532
+ ['diamonds', DIAMONDS],
533
+ ['less-dots', LESS_DOTS],
534
+ ['least-dots', LEAST_DOTS]
535
+ ]
536
+
537
+ attr_reader :pattern
538
+ attr_reader :pattern_fore_colour
539
+ attr_reader :pattern_back_colour
540
+
541
+ def self.fill_directives
542
+ PATTERN_DIRECTIVES.collect {|a| a[0]}
543
+ end
544
+
545
+ def self.directives_hash
546
+ Hash[*PATTERN_DIRECTIVES.flatten]
547
+ end
535
548
 
536
549
  def initialize(hash = {})
537
550
  @pattern = NO_PATTERN
@@ -543,12 +556,39 @@ class Pattern
543
556
  end
544
557
  end
545
558
 
546
- # Convenience method to set fill colour
559
+ def pattern=(arg)
560
+ case arg
561
+ when String
562
+ pattern_index = Pattern.directives_hash[arg]
563
+ when Integer
564
+ pattern_index = arg
565
+ else
566
+ raise "I don't know how to interpret #{arg.inspect} as a pattern!"
567
+ end
568
+ raise "invalid pattern #{arg}" if pattern_index.nil?
569
+
570
+ @pattern = pattern_index
571
+ end
572
+
573
+ def fore_colour=(arg)
574
+ colour_index = Formatting::COLOURS[arg]
575
+ raise "Invalid colour #{arg}" if colour_index.nil?
576
+ @pattern_fore_colour = colour_index
577
+ end
578
+ alias :fore_color= :fore_colour=
579
+
580
+ def back_colour=(arg)
581
+ colour_index = Formatting::COLOURS[arg]
582
+ raise "Invalid colour #{arg}" if colour_index.nil?
583
+ @pattern_back_colour = colour_index
584
+ end
585
+ alias :back_color= :back_colour=
586
+
587
+ # Sets the foreground colour, also if no pattern has been specified
588
+ # will assume you want a solid colour fill.
547
589
  def colour=(arg)
548
- colour_index = Formatting::COLOURS[arg]
549
- raise "Invalid colour #{arg}" if colour_index.nil?
550
- @pattern = SOLID_PATTERN
551
- @pattern_fore_colour = colour_index
590
+ self.fore_colour = arg
591
+ @pattern = SOLID_PATTERN if @pattern == NO_PATTERN
552
592
  end
553
593
  alias :color= :colour=
554
594
  alias :fill= :colour=
File without changes
@@ -12,7 +12,7 @@ class StyleFormat
12
12
  @font = Font.new(hash_select(hash, /^font_/))
13
13
  @alignment = Alignment.new(hash_select(hash, /^text_/))
14
14
  @borders = Borders.new(hash_select(hash, /^border_/))
15
- @pattern = Pattern.new(hash_select(hash, /^fill_/))
15
+ @pattern = Pattern.new(hash_select(hash, /^(fill|pattern)_/))
16
16
  @protection = Protection.new
17
17
  end
18
18
 
@@ -115,6 +115,7 @@ class StyleCollection
115
115
  if style.nil?
116
116
  0x10 # Return the index of the default style.
117
117
  else
118
+ # TODO find way to freeze style so if someone modifies a StyleFormat instance it won't affect previously formatted cells.
118
119
  add_style(style)[1] # Return the index of the style just stored.
119
120
  end
120
121
  end
@@ -0,0 +1,2 @@
1
+ 'B' -> 'C'
2
+ '2B' -> 'C2'
File without changes
File without changes
@@ -38,7 +38,7 @@ class Worksheet
38
38
 
39
39
  attr_accessor :delta
40
40
  attr_accessor :save_recalc
41
-
41
+ attr_accessor :formula_options
42
42
  attr_accessor :print_headers
43
43
  attr_accessor :print_grid
44
44
  attr_accessor :grid_set
@@ -269,24 +269,32 @@ class Worksheet
269
269
  end
270
270
  end
271
271
 
272
- # Write the text stored in label in a single cell at (r,c) according to style.
272
+ # TODO get rid of meaningless default value for label, should be required?
273
+ ### @export "write-method"
273
274
  def write(r, c, label = "", style = nil)
274
- row(r).write(c, label, style)
275
+ if label.is_a?(Array)
276
+ if label[0].is_a?(Array)
277
+ write_arrays(r, c, label, style || true)
278
+ else
279
+ write_array_to_row(label, r, c)
280
+ end
281
+ else
282
+ row(r).write(c, label, style)
283
+ end
275
284
  end
276
-
285
+
286
+ ### @export "write-arrays"
277
287
  def write_array_to_row(array, r, c = 0, style = true)
278
288
  array.each_with_index do |a, i|
279
289
  row(r).write(c + i, a, style)
280
290
  end
281
291
  end
282
- alias :rarray :write_array_to_row
283
292
 
284
293
  def write_array_to_column(array, c, r = 0, style = true)
285
294
  array.each_with_index do |a, i|
286
295
  row(r + i).write(c, a, style)
287
296
  end
288
297
  end
289
- alias :carray :write_array_to_column
290
298
 
291
299
  def write_arrays(r, c, array_of_arrays, style = true)
292
300
  array_of_arrays.each_with_index do |a, i|
@@ -294,6 +302,7 @@ class Worksheet
294
302
  write_array_to_row(a, r + i, c, style)
295
303
  end
296
304
  end
305
+ ### @end
297
306
 
298
307
  # Comment from xlwt:
299
308
  ## Stand-alone merge of previously written cells.
data/lib/surpass.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Surpass
2
2
 
3
3
  # :stopdoc:
4
- VERSION = '0.0.4'
4
+ VERSION = '0.0.6'
5
5
  LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
6
6
  PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
7
7
  # :startdoc:
@@ -0,0 +1,268 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe InterfaceHeaderRecord do
4
+ it "should pack correctly" do
5
+ b = InterfaceHeaderRecord.new
6
+ b.to_biff.unpack('M*').should === ["\341\000\002\000\260\004"]
7
+ end
8
+ end
9
+
10
+ describe InterfaceEndRecord do
11
+ it "should pack correctly" do
12
+ b = InterfaceEndRecord.new
13
+ b.to_biff.unpack('M*').should === ["\342\000\000\000"]
14
+ end
15
+ end
16
+
17
+ describe MMSRecord do
18
+ it "should pack correctly" do
19
+ b = MMSRecord.new
20
+ b.to_biff.unpack('M*').should === ["\301\000\002\000\000\000"]
21
+ end
22
+ end
23
+
24
+ describe WriteAccessRecord do
25
+ it "should pack correctly" do
26
+ b = WriteAccessRecord.new("Ana")
27
+ b.to_biff.unpack('M*').should === ["\\\000p\000Ana" + " " * 109]
28
+ end
29
+ end
30
+
31
+ describe DSFRecord do
32
+ it "should pack correctly" do
33
+ b = DSFRecord.new
34
+ b.to_biff.unpack('M*').should === ["a\001\002\000\000\000"]
35
+ end
36
+ end
37
+
38
+ describe TabIDRecord do
39
+ it "should pack correctly" do
40
+ b = TabIDRecord.new(2)
41
+ b.record_data.should === "\001\000\002\000"
42
+ b.to_biff.unpack('A*').should === ["=\001\004\000\001\000\002"]
43
+ end
44
+ end
45
+
46
+ describe FnGroupCountRecord do
47
+ it "should pack correctly" do
48
+ b = FnGroupCountRecord.new
49
+ b.record_data.should === "\016\000"
50
+ b.to_biff.unpack('A*').should === ["\234\000\002\000\016"]
51
+ end
52
+ end
53
+
54
+ describe WindowProtectRecord do
55
+ it "should pack correctly" do
56
+ b = WindowProtectRecord.new(0)
57
+ b.record_data.should === "\000\000"
58
+ b.to_biff.unpack('A*').should === ["\031\000\002"]
59
+ end
60
+ end
61
+
62
+ describe ObjectProtectRecord do
63
+ it "should pack correctly" do
64
+ b = ObjectProtectRecord.new(0)
65
+ b.record_data.should === "\000\000"
66
+ b.to_biff.unpack('A*').should === ["c\000\002"]
67
+ end
68
+ end
69
+
70
+ describe ScenarioProtectRecord do
71
+ it "should pack correctly" do
72
+ b = ScenarioProtectRecord.new(0)
73
+ b.record_data.should === "\000\000"
74
+ b.to_biff.unpack('A*').should === ["\335\000\002"]
75
+ end
76
+ end
77
+
78
+ describe PasswordRecord do
79
+ before(:each) do
80
+ @b = PasswordRecord.new
81
+ end
82
+ it "should pack correctly with blank password" do
83
+ @b.password_hash("").should == 0
84
+ end
85
+
86
+ it "should pack correctly with a password of 123456" do
87
+ @b.password_hash("123456").should === 50975
88
+ end
89
+
90
+ it "should pack correctly with a password of abcdefghij" do
91
+ @b.password_hash("abcdefghij").should == 65265
92
+ end
93
+
94
+ it "should pack correctly with a password of ok" do
95
+ @b.password_hash("ok").should == 53051
96
+ end
97
+ end
98
+
99
+ describe Prot4RevRecord do
100
+ it "should pack correctly" do
101
+ b = Prot4RevRecord.new
102
+ b.record_data.should === "\000\000"
103
+ b.to_biff.unpack('A*').should === ["\257\001\002"]
104
+ end
105
+ end
106
+
107
+ describe Prot4RevPassRecord do
108
+ it "should pack correctly" do
109
+ b = Prot4RevPassRecord.new
110
+ b.record_data.should === "\000\000"
111
+ b.to_biff.unpack('A*').should === ["\274\001\002"]
112
+ end
113
+ end
114
+
115
+ describe BackupRecord do
116
+ it "should pack correctly" do
117
+ b = BackupRecord.new(0)
118
+ b.record_data.should === "\000\000"
119
+ b.to_biff.unpack('A*').should === ["@\000\002"]
120
+ end
121
+ end
122
+
123
+ describe HideObjRecord do
124
+ it "should pack correctly" do
125
+ b = HideObjRecord.new
126
+ b.record_data.should === "\000\000"
127
+ b.to_biff.unpack('A*').should === ["\215\000\002"]
128
+ end
129
+ end
130
+
131
+ describe RefreshAllRecord do
132
+ it "should pack correctly" do
133
+ b = RefreshAllRecord.new
134
+ b.record_data.should === "\000\000"
135
+ b.to_biff.unpack('A*').should === ["\267\001\002"]
136
+ end
137
+ end
138
+
139
+ describe BookBoolRecord do
140
+ it "should pack correctly" do
141
+ b = BookBoolRecord.new
142
+ b.record_data.should === "\000\000"
143
+ b.to_biff.unpack('A*').should === ["\332\000\002"]
144
+ end
145
+ end
146
+
147
+ describe CountryRecord do
148
+ it "should pack correctly" do
149
+ b = CountryRecord.new(1,1)
150
+ b.record_data.should === "\001\000\001\000"
151
+ b.to_biff.unpack('A*').should === ["\332\000\004\000\001\000\001"]
152
+ end
153
+ end
154
+
155
+ describe UseSelfsRecord do
156
+ it "should pack correctly" do
157
+ b = UseSelfsRecord.new
158
+ b.record_data.should === "\001\000"
159
+ b.to_biff.unpack('A*').should === ["`\001\002\000\001"]
160
+ end
161
+ end
162
+
163
+ describe EOFRecord do
164
+ it "should pack correctly" do
165
+ b = EOFRecord.new
166
+ b.record_data.should === ""
167
+ b.to_biff.unpack('A*').should === ["\n"]
168
+ end
169
+ end
170
+
171
+ describe DateModeRecord do
172
+ it "should pack correctly when passed true" do
173
+ b = DateModeRecord.new(true)
174
+ b.record_data.should === "\001\000"
175
+ b.to_biff.unpack('A*').should === ["\"\000\002\000\001"]
176
+ end
177
+ it "should pack correctly when passed false" do
178
+ b = DateModeRecord.new(false)
179
+ b.record_data.should === "\000\000"
180
+ b.to_biff.unpack('A*').should === ["\"\000\002"]
181
+ end
182
+ end
183
+
184
+ describe PrecisionRecord do
185
+ it "should pack correctly when passed true" do
186
+ b = PrecisionRecord.new(true)
187
+ b.record_data.should === "\001\000"
188
+ b.to_biff.unpack('A*').should === ["\016\000\002\000\001"]
189
+ end
190
+ it "should pack correctly when passed false" do
191
+ b = PrecisionRecord.new(false)
192
+ b.record_data.should === "\000\000"
193
+ b.to_biff.unpack('A*').should === ["\016\000\002"]
194
+ end
195
+ end
196
+
197
+ describe CodepageBiff8Record do
198
+ it "should pack correctly" do
199
+ b = CodepageBiff8Record.new
200
+ b.record_data.should === "\260\004"
201
+ b.to_biff.unpack('A*').should === ["B\000\002\000\260\004"]
202
+ end
203
+ end
204
+
205
+ describe Window1Record do
206
+ it "should pack correctly" do
207
+ b = Window1Record.new(1,1,1,1,1,1,1,1,1)
208
+ b.record_data.should === "\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000"
209
+ b.to_biff.unpack('A*').should === ["=\000\022\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001\000\001"]
210
+ end
211
+ end
212
+
213
+ describe FontRecord do
214
+ it "should pack correctly" do
215
+
216
+ b = FontRecord.new(200,0,32767,400,0,0,0,204,"Arial")
217
+ b.record_data.should === "\310\000\000\000\377\177\220\001\000\000\000\000\314\000\005\000Arial"
218
+ end
219
+ end
220
+
221
+ # describe XFRecord do
222
+ # it "should pack correctly" do
223
+ # b = XFRecord.new([1,1,Alignment.new,Borders.new,Pattern.new,Protection.new])
224
+ # puts binary_string_to_hex_array(b.record_data)
225
+ # b.record_data.should === "\001\000\001\000\001\000"
226
+ # b.to_biff.unpack('A*').should === ["\257\001\002"]
227
+ # end
228
+ # end
229
+
230
+ describe StyleRecord do
231
+ it "should pack correctly" do
232
+ b = StyleRecord.new
233
+ b.record_data.should === "\000\200\000\377"
234
+ b.to_biff.unpack('A*').should === ["\223\002\004\000\000\200\000\377"]
235
+ end
236
+ end
237
+
238
+ describe BoundSheetRecord do
239
+ it "should pack correctly" do
240
+ b = BoundSheetRecord.new(0, 0, "x")
241
+ b.record_data.should === "\000\000\000\000\000\000\001\000x"
242
+ b.to_biff.unpack('A*').should === ["\205\000\t\000\000\000\000\000\000\000\001\000x"]
243
+ end
244
+ end
245
+
246
+ # describe ExtSSTRecord do
247
+ # it "should pack correctly" do
248
+ # b = ExtSSTRecord.new(1,[1],1)
249
+ # b.record_data.should === "\000\000"
250
+ # b.to_biff.unpack('A*').should === ["\257\001\002"]
251
+ # end
252
+ # end
253
+
254
+ describe DimensionsRecord do
255
+ it "should pack correctly" do
256
+ b = DimensionsRecord.new(0,0,5,5)
257
+ b.record_data.should === "\000\000\000\000\001\000\000\000\005\000\006\000\000\000"
258
+ b.to_biff.unpack('A*').should === ["\000\002\016\000\000\000\000\000\001\000\000\000\005\000\006"]
259
+ end
260
+ end
261
+
262
+ # describe MergedCellsRecord do
263
+ # it "should pack correctly" do
264
+ # b = MergedCellsRecord.new([[1,1,2,2]])
265
+ # b.record_data.should === "\345\000\n\000\001\000\001\000\001\000\002\000\002\000"
266
+ # b.to_biff.unpack('A*').should === ["\345\000\n\000\001\000\001\000\001\000\002\000\002"]
267
+ # end
268
+ # end
data/spec/cell_spec.rb ADDED
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe NumberCell, "to_biff" do
4
+ before(:all) do
5
+ @w = Workbook.new
6
+ @s = @w.add_sheet('rk_tests')
7
+ end
8
+
9
+ it "should encode with rk_encode" do
10
+ TEST_VALUES.each_with_index do |x, i|
11
+ # Write original test values
12
+ @s.write(i, 0, x)
13
+
14
+ # Write test values divided by 100
15
+ @s.write(i, 3, x/100.00)
16
+
17
+ # Write negative of test values
18
+ @s.write(i, 6, x)
19
+
20
+ # Write negative test values divided by 100
21
+ @s.write(i, 9, -x/100.00)
22
+ end
23
+ end
24
+
25
+ after(:all) do
26
+ @w.save("spec/output/cells-rk.xls")
27
+ end
28
+ end
29
+
30
+ TEST_VALUES = [
31
+ 130.63999999999999,
32
+ 130.64,
33
+ -18.649999999999999,
34
+ -18.65,
35
+ 137.19999999999999,
36
+ 137.20,
37
+ -16.079999999999998,
38
+ -16.08,
39
+ 0,
40
+ 1,
41
+ 2,
42
+ 3,
43
+ 0x1fffffff,
44
+ 0x20000000,
45
+ 0x20000001,
46
+ 1000999999,
47
+ 0x3fffffff,
48
+ 0x40000000,
49
+ 0x40000001,
50
+ 0x7fffffff,
51
+ 0x80000000,
52
+ 0x80000001,
53
+ 0xffffffff,
54
+ 0x100000000,
55
+ 0x100000001
56
+ ]