summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-12-15 10:39:37 +0900
committerRandy Morgan <[email protected]>2012-12-15 10:39:37 +0900
commit054de56d12e203a5f0696f98ac9fad3159e7abc1 (patch)
treec29ef8fb0bd35ef6170d5aa26cbd9bc8960a0a30
parentb1600deadaafdb396c5cc7ca9d448e8adab8ac11 (diff)
downloadcaxlsx-054de56d12e203a5f0696f98ac9fad3159e7abc1.tar.gz
caxlsx-054de56d12e203a5f0696f98ac9fad3159e7abc1.zip
Added methods to simplify outlining with specs
worksheet#outline_rows worksheet#outline_columns
-rwxr-xr-xexamples/example.rb12
-rw-r--r--lib/axlsx/workbook/worksheet/pivot_table.rb3
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb16
-rw-r--r--test/tc_package.rb5
-rw-r--r--test/workbook/worksheet/tc_pivot_table.rb1
-rw-r--r--test/workbook/worksheet/tc_worksheet.rb17
6 files changed, 52 insertions, 2 deletions
diff --git a/examples/example.rb b/examples/example.rb
index 94b81444..838a1fa3 100755
--- a/examples/example.rb
+++ b/examples/example.rb
@@ -14,6 +14,7 @@ examples << :surrounding_border
examples << :deep_custom_borders
examples << :row_column_style
examples << :fixed_column_width
+examples << :outline_level
examples << :merge_cells
examples << :images
examples << :format_dates
@@ -238,6 +239,17 @@ if examples.include? :fixed_column_width
sheet.column_widths nil, 3, 5, nil
end
end
+
+#```ruby
+if examples.include? :outline_level
+ wb.add_worksheet(name: 'outline_level') do |sheet|
+ sheet.add_row [1, 2, 3, 4, Time.now, 149455.15]
+ sheet.add_row [1, 2, 5, 6, Time.now,14100.19]
+ sheet.add_row [9500002267, 1212, 1212, Time.now,14100.19]
+ sheet.outline_rows 0, 2
+ sheet.outline_cols 0, 2
+ end
+end
##```
##Merging Cells.
diff --git a/lib/axlsx/workbook/worksheet/pivot_table.rb b/lib/axlsx/workbook/worksheet/pivot_table.rb
index d876f777..515f5d09 100644
--- a/lib/axlsx/workbook/worksheet/pivot_table.rb
+++ b/lib/axlsx/workbook/worksheet/pivot_table.rb
@@ -135,6 +135,9 @@ module Axlsx
# identifies the index of an object withing the collections used in generating relationships for the worksheet
# @param [Any] object the object to search for
# @return [Integer] The index of the object
+ #
+ # RM: I cannot find any place in the code base where this is actually used
+ # TODO: confirm with author before removal
def relationships_index_of(object)
objects = [cache_definition]
objects.index(object)
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 62d4e557..b6dc7c38 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -608,9 +608,25 @@ module Axlsx
@styles ||= self.workbook.styles
end
+ def outline_rows(start_index, end_index, level = 1, collapsed = true)
+ outline rows, (start_index..end_index), level, collapsed
+ end
+
+ def outline_columns(start_index, end_index, level = 1, collapsed = true)
+ outline column_info, (start_index..end_index), level, collapsed
+ end
private
+ def outline(collection, range, level = 1, collapsed = true)
+ range.each do |index|
+ unless (item = collection[index]).nil?
+ item.outline_level = level
+ item.hidden = collapsed
+ end
+ sheet_view.show_outline_symbols = true
+ end
+ end
def validate_sheet_name(name)
DataTypeValidator.validate "Worksheet.name", String, name
raise ArgumentError, (ERR_SHEET_NAME_TOO_LONG % name) if name.size > 31
diff --git a/test/tc_package.rb b/test/tc_package.rb
index be303419..8a25d946 100644
--- a/test/tc_package.rb
+++ b/test/tc_package.rb
@@ -7,8 +7,9 @@ class TestPackage < Test::Unit::TestCase
ws = @package.workbook.add_worksheet
ws.add_row ['Can', 'we', 'build it?']
ws.add_row ['Yes!', 'We', 'can!']
+ ws.outline_rows 0, 1
+ ws.outline_columns 0, 1
ws.add_hyperlink :ref => ws.rows.first.cells.last, :location => 'https://github.com/randym'
- # TODO this needs to be confirmed and checked. Validation errors should not be happening here!!!!!!
ws.workbook.add_defined_name("#{ws.name}!A1:C2", :name => '_xlnm.Print_Titles', :hidden => true)
ws.protect_range('A1:C1')
ws.protect_range(ws.rows.last.cells)
@@ -145,7 +146,7 @@ class TestPackage < Test::Unit::TestCase
#no mystery parts
- assert_equal(p.size, 24)
+ assert_equal(24, p.size)
end
diff --git a/test/workbook/worksheet/tc_pivot_table.rb b/test/workbook/worksheet/tc_pivot_table.rb
index 3a94cfae..9adbaf93 100644
--- a/test/workbook/worksheet/tc_pivot_table.rb
+++ b/test/workbook/worksheet/tc_pivot_table.rb
@@ -45,6 +45,7 @@ class TestPivotTable < Test::Unit::TestCase
assert_equal(3, pivot_table.header_index_of('Type' ))
assert_equal(4, pivot_table.header_index_of('Sales' ))
assert_equal(nil, pivot_table.header_index_of('Missing'))
+ assert_equal(%w(A1 B1 C1 D1 E1), pivot_table.header_cell_refs)
end
def test_pn
diff --git a/test/workbook/worksheet/tc_worksheet.rb b/test/workbook/worksheet/tc_worksheet.rb
index 0311018b..846c2491 100644
--- a/test/workbook/worksheet/tc_worksheet.rb
+++ b/test/workbook/worksheet/tc_worksheet.rb
@@ -475,4 +475,21 @@ class TestWorksheet < Test::Unit::TestCase
doc = Nokogiri::XML(@ws.to_xml_string)
assert(doc.xpath('//sheetPr[@filterMode="true"]'))
end
+
+ def test_outline_rows
+ 3.times { @ws.add_row [1,2,3] }
+ @ws.outline_rows 0, 2
+ assert_equal(1, @ws.rows[0].outline_level)
+ assert_equal(true, @ws.rows[2].hidden)
+ assert_equal(true, @ws.sheet_view.show_outline_symbols)
+ end
+
+ def test_outline_columns
+ 3.times { @ws.add_row [1,2,3] }
+ @ws.outline_columns 0, 2
+ assert_equal(1, @ws.column_info[0].outline_level)
+ assert_equal(true, @ws.column_info[2].hidden)
+ assert_equal(true, @ws.sheet_view.show_outline_symbols)
+ end
+
end