spreadsheet 0.7.8 → 0.7.9

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.
@@ -1,3 +1,12 @@
1
+ === 0.7.9 / 06.02.2013
2
+
3
+ Author: Eugeniy Belyaev (zhekanax)
4
+
5
+ * You can merge if you are interested in perl-like Workbook.set_custom_color
6
+ implementation. I know it is not really a proper way to deal with custom colors, but
7
+ nevertheless it makes it possible.
8
+ * https://github.com/zdavatz/spreadsheet/pull/27
9
+
1
10
  === 0.7.8 / 06.02.2013
2
11
 
3
12
  Author: Kenichi Kamiya <kachick1@gmail.com>
@@ -42,7 +42,7 @@ module Spreadsheet
42
42
 
43
43
  ##
44
44
  # The version of Spreadsheet you are using.
45
- VERSION = '0.7.8'
45
+ VERSION = '0.7.9'
46
46
 
47
47
  ##
48
48
  # Default client Encoding. Change this value if your application uses a
@@ -434,6 +434,7 @@ class Workbook < Spreadsheet::Writer
434
434
  # ●● STYLE ➜ 5.103
435
435
  write_styles workbook, buffer1
436
436
  # ○ PALETTE ➜ 5.74
437
+ write_palette workbook, buffer1
437
438
  # ○ USESELFS ➜ 5.106
438
439
  buffer1.rewind
439
440
  # ●● BOUNDSHEET ➜ 5.95
@@ -588,6 +589,18 @@ class Workbook < Spreadsheet::Writer
588
589
  ]
589
590
  write_op writer, 0x0293, data.pack('vC2')
590
591
  end
592
+ def write_palette workbook, writer
593
+ data = default_palette
594
+
595
+ workbook.palette.each do |idx, color|
596
+ idx = SEDOC_ROLOC[idx] - 8 if idx.kind_of? Symbol
597
+ raise "Undefined color index: #{idx}" unless data[idx]
598
+ data[idx] = color
599
+ end
600
+
601
+ writer.write [opcode(:palette), 2 + 4 * data.size, data.size].pack('v3')
602
+ writer.write data.collect { |c| c.push(0).pack('C4') }.join
603
+ end
591
604
  def write_tabid workbook, writer
592
605
  write_op writer, 0x013d, [1].pack('v')
593
606
  end
@@ -653,6 +666,68 @@ class Workbook < Spreadsheet::Writer
653
666
  def xf_index workbook, format
654
667
  @formats[workbook][:xf_indexes][format] || 0
655
668
  end
669
+ ##
670
+ # Returns Excel 97+ default colour palette.
671
+ def default_palette
672
+ [
673
+ [0x00, 0x00, 0x00],
674
+ [0xff, 0xff, 0xff],
675
+ [0xff, 0x00, 0x00],
676
+ [0x00, 0xff, 0x00],
677
+ [0x00, 0x00, 0xff],
678
+ [0xff, 0xff, 0x00],
679
+ [0xff, 0x00, 0xff],
680
+ [0x00, 0xff, 0xff],
681
+ [0x80, 0x00, 0x00],
682
+ [0x00, 0x80, 0x00],
683
+ [0x00, 0x00, 0x80],
684
+ [0x80, 0x80, 0x00],
685
+ [0x80, 0x00, 0x80],
686
+ [0x00, 0x80, 0x80],
687
+ [0xc0, 0xc0, 0xc0],
688
+ [0x80, 0x80, 0x80],
689
+ [0x99, 0x99, 0xff],
690
+ [0x99, 0x33, 0x66],
691
+ [0xff, 0xff, 0xcc],
692
+ [0xcc, 0xff, 0xff],
693
+ [0x66, 0x00, 0x66],
694
+ [0xff, 0x80, 0x80],
695
+ [0x00, 0x66, 0xcc],
696
+ [0xcc, 0xcc, 0xff],
697
+ [0x00, 0x00, 0x80],
698
+ [0xff, 0x00, 0xff],
699
+ [0xff, 0xff, 0x00],
700
+ [0x00, 0xff, 0xff],
701
+ [0x80, 0x00, 0x80],
702
+ [0x80, 0x00, 0x00],
703
+ [0x00, 0x80, 0x80],
704
+ [0x00, 0x00, 0xff],
705
+ [0x00, 0xcc, 0xff],
706
+ [0xcc, 0xff, 0xff],
707
+ [0xcc, 0xff, 0xcc],
708
+ [0xff, 0xff, 0x99],
709
+ [0x99, 0xcc, 0xff],
710
+ [0xff, 0x99, 0xcc],
711
+ [0xcc, 0x99, 0xff],
712
+ [0xff, 0xcc, 0x99],
713
+ [0x33, 0x66, 0xff],
714
+ [0x33, 0xcc, 0xcc],
715
+ [0x99, 0xcc, 0x00],
716
+ [0xff, 0xcc, 0x00],
717
+ [0xff, 0x99, 0x00],
718
+ [0xff, 0x66, 0x00],
719
+ [0x66, 0x66, 0x99],
720
+ [0x96, 0x96, 0x96],
721
+ [0x00, 0x33, 0x66],
722
+ [0x33, 0x99, 0x66],
723
+ [0x00, 0x33, 0x00],
724
+ [0x33, 0x33, 0x00],
725
+ [0x99, 0x33, 0x00],
726
+ [0x99, 0x33, 0x66],
727
+ [0x33, 0x33, 0x99],
728
+ [0x33, 0x33, 0x33]
729
+ ]
730
+ end
656
731
  end
657
732
  end
658
733
  end
@@ -12,12 +12,13 @@ module Spreadsheet
12
12
  # Row#default_format or Worksheet#default_format.
13
13
  class Workbook
14
14
  include Spreadsheet::Encodings
15
- attr_reader :io, :worksheets, :formats, :fonts
15
+ attr_reader :io, :worksheets, :formats, :fonts, :palette
16
16
  attr_accessor :active_worksheet, :encoding, :default_format, :version
17
17
  def initialize io = nil, opts={:default_format => Format.new}
18
18
  @worksheets = []
19
19
  @io = io
20
20
  @fonts = []
21
+ @palette = {}
21
22
  @formats = []
22
23
  @formats_set = {}
23
24
  if @default_format = opts[:default_format]
@@ -49,6 +50,13 @@ module Spreadsheet
49
50
  worksheet
50
51
  end
51
52
  ##
53
+ # Change the RGB components of the elements in the colour palette.
54
+ def set_custom_color idx, red, green, blue
55
+ raise 'Invalid format' if [red, green, blue].find { |c| ! (0..255).include?(c) }
56
+
57
+ @palette[idx] = [red, green, blue]
58
+ end
59
+ ##
52
60
  # Create a new Worksheet in this Workbook.
53
61
  # Used without options this creates a Worksheet with the name 'WorksheetN'
54
62
  # where the new Worksheet is the Nth Worksheet in this Workbook.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spreadsheet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.8
4
+ version: 0.7.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-02-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ruby-ole
16
- requirement: &23099500 !ruby/object:Gem::Requirement
16
+ requirement: &23604080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *23099500
24
+ version_requirements: *23604080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rdoc
27
- requirement: &23099000 !ruby/object:Gem::Requirement
27
+ requirement: &23603660 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '3.10'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *23099000
35
+ version_requirements: *23603660
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hoe
38
- requirement: &23098580 !ruby/object:Gem::Requirement
38
+ requirement: &23603200 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '2.13'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *23098580
46
+ version_requirements: *23603200
47
47
  description: ! 'The Spreadsheet Library is designed to read and write Spreadsheet
48
48
  Documents.
49
49