xlsx_writer 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 0.3.1 / 2012-07-10
2
+
3
+ * Enhancements
4
+
5
+ * Allow freezing on any top left cell and on a per-sheet basis
6
+
1
7
  0.3.0 / 2012-07-10
2
8
 
3
9
  * Enhancements
data/foo.rb CHANGED
@@ -13,15 +13,16 @@ require 'xlsx_writer'
13
13
 
14
14
  @sheet1 = @doc.add_sheet("Sheet1")
15
15
  @sheet1.add_row(['a', 'a'])
16
+ @sheet1.freeze_top_left = 'A2'
16
17
  @sheet1.add_row(['a', { :value => 'a', :faded => true, :type => :String }])
17
18
  @sheet1.add_row(['a', 'a'])
18
19
  # @sheet1.add_row(['foo', 'bar'])
19
20
  @sheet1.add_autofilter 'A1:B1'
20
21
 
21
- @doc.freeze!
22
22
  @sheet2 = @doc.add_sheet("Freeze")
23
23
  @sheet2.add_row(['a', 'a'])
24
24
  @sheet2.add_row(['false1', false])
25
+ @sheet2.freeze_top_left = 'A4'
25
26
  @sheet2.add_row(['false2', {:value => false, :type => :Boolean}])
26
27
  @sheet2.add_row(['false3', 'faLse'])
27
28
  @sheet2.add_row(['true1', true])
@@ -38,15 +38,6 @@ module XlsxWriter
38
38
  @quiet_booleans == true
39
39
  end
40
40
 
41
- # Freeze the pane under the first (header) row
42
- def freeze!
43
- @freeze_pane = true
44
- end
45
-
46
- def freeze?
47
- @freeze_pane == true
48
- end
49
-
50
41
  def add_sheet(name)
51
42
  raise ::RuntimeError, "Can't add sheet, already generated!" if generated?
52
43
  sheet = Sheet.new self, name
@@ -18,6 +18,9 @@ module XlsxWriter
18
18
  attr_reader :rows
19
19
  attr_reader :autofilters
20
20
 
21
+ # Freeze the pane under this top left cell
22
+ attr_accessor :freeze_top_left
23
+
21
24
  def initialize(document, name)
22
25
  @name = Sheet.excel_name name
23
26
  @rows = []
@@ -79,17 +82,25 @@ module XlsxWriter
79
82
 
80
83
  private
81
84
 
85
+ def y_split
86
+ if freeze_top_left =~ /(\d+)$/
87
+ $1.to_i - 1
88
+ else
89
+ raise "freeze_top_left must be like 'A3', was #{freeze_top_left}"
90
+ end
91
+ end
92
+
82
93
  # not using ERB to save memory
83
94
  def to_file(f)
84
95
  f.write <<-EOS
85
96
  <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
86
97
  <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
87
98
  EOS
88
- if document.freeze?
99
+ if freeze_top_left
89
100
  f.write <<-EOS
90
101
  <sheetViews>
91
102
  <sheetView workbookViewId="0">
92
- <pane ySplit="1" topLeftCell="A2" activePane="bottomLeft" state="frozen"/>
103
+ <pane ySplit="#{y_split}" topLeftCell="#{freeze_top_left}" activePane="bottomLeft" state="frozen"/>
93
104
  </sheetView>
94
105
  </sheetViews>
95
106
  EOS
@@ -1,3 +1,3 @@
1
1
  module XlsxWriter
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -73,7 +73,7 @@ describe XlsxWriter do
73
73
  end
74
74
  end
75
75
 
76
- describe "freeze pane under first (header) row" do
76
+ describe "freeze pane under a certain row" do
77
77
  before do
78
78
  @doc = XlsxWriter::Document.new
79
79
  @sheet1 = @doc.add_sheet("Freeze")
@@ -89,9 +89,11 @@ describe XlsxWriter do
89
89
  FileUtils.rm_rf dir
90
90
  end
91
91
  it "shows TRUE or blank for false if quiet booleans is enabled" do
92
- @doc.freeze!
92
+ @sheet1.freeze_top_left = 'A3'
93
93
  dir = UnixUtils.unzip @doc.path
94
- File.read("#{dir}/xl/worksheets/sheet1.xml").must_include 'pane'
94
+ xml = File.read("#{dir}/xl/worksheets/sheet1.xml")
95
+ xml.must_include 'topLeftCell="A3"'
96
+ xml.must_include 'ySplit="2"'
95
97
  FileUtils.rm_rf dir
96
98
  end
97
99
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xlsx_writer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: