Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge master

  • Loading branch information...
commit 09a68453cf0fa674b5e5aa16347c6f376f7b0ad6 2 parents 61c6833 + e485b3b
@scottwillson scottwillson authored
View
58 GUIDE.txt
@@ -168,6 +168,64 @@ a particular Cell, Spreadsheet will leave it untouched:
row[6] = Time.new 2008, 10, 12
# -> the Format of cell 6 is left unchanged.
+== Outline (Grouping) and Hiding
+Spreadsheet supports outline (grouping) and hiding functions from version
+0.6.5. In order to hide rows or columns, you can use 'hidden' property.
+As for outline, 'outline_level' property is also available. You can use
+both 'hidden' and 'outline_level' at the same time.
+
+You can create a new file with outline and hiding rows and columns as
+follows:
+
+ require 'spreadsheet'
+
+ # create a new book and sheet
+ book = Spreadsheet::Workbook.new
+ sheet = book.create_worksheet
+ 5.times {|j| 5.times {|i| sheet[j,i] = (i+1)*10**j}}
+
+ # column
+ sheet.column(2).hidden = true
+ sheet.column(3).hidden = true
+ sheet.column(2).outline_level = 1
+ sheet.column(3).outline_level = 1
+
+ # row
+ sheet.row(2).hidden = true
+ sheet.row(3).hidden = true
+ sheet.row(2).outline_level = 1
+ sheet.row(3).outline_level = 1
+
+ # save file
+ book.write 'out.xls'
+
+Also you can read an existing file and change the hidden and outline
+properties. Here is the example below:
+
+ require 'spreadsheet'
+
+ # read an existing file
+ file = ARGV[0]
+ book = Spreadsheet.open(file, 'rb')
+ sheet= book.worksheet(0)
+
+ # column
+ sheet.column(2).hidden = true
+ sheet.column(3).hidden = true
+ sheet.column(2).outline_level = 1
+ sheet.column(3).outline_level = 1
+
+ # row
+ sheet.row(2).hidden = true
+ sheet.row(3).hidden = true
+ sheet.row(2).outline_level = 1
+ sheet.row(3).outline_level = 1
+
+ # save file
+ book.write "out.xls"
+
+Notes
+ * The outline_level should be under 8, which is due to the Excel data format.
== More about Encodings
Spreadsheet assumes it's running on Ruby 1.8 with Iconv-support. It is your
View
15 History.txt
@@ -1,11 +1,14 @@
-=== 0.6.4.2 / 2009-08-26
+=== 0.6.5 / 07.12.2010
-* 1 Bugfix
+* 2 Enhancements courtesy to ISS AG.
+
+ * Outlining (Grouping) of lines and columns is now possible. The outlining
+ maximum is 8. This means you can do 8 subgroups in a group.
+
+ * Hiding and Unhiding of lines and columns is now possible.
- * Fixes the issue reported by Qiong Peng and tracked down by Moo Yu and
- Matthias Huber (independently) in
- http://rubyforge.org/tracker/index.php?func=detail&aid=28007&group_id=678&atid=2677
- where skip amount would not be properly applied in incomplete shared strings
+ * Both of above two points is now possible by creating a new Excel File from
+ scratch or editing an existing XLS and adding groups or hiding lines to it.
=== 0.6.4.1 / 2009-09-17
View
16 README.txt
@@ -1,14 +1,13 @@
-Last Update: 17.09.2009, 16.32 - hwyss
+Last Update: 08.12.2010 - Zeno Davatz
= Spreadsheet
http://spreadsheet.rubyforge.org
-http://scm.ywesee.com/spreadsheet
For a viewable directory of all recent changes, please see:
-http://scm.ywesee.com/?p=spreadsheet;a=summary
+http://scm.ywesee.com/?p=spreadsheet/.git;a=summary
For Non-GPLv3 commercial licencing, please see:
@@ -26,6 +25,7 @@ Hannes Wyss. Spreadsheet can read, write and modify Spreadsheet Documents.
== What's new?
+* Supported outline (grouping) functions
* Significantly improved memory-efficiency when reading large Excel Files
* Limited Spreadsheet modification support
* Improved handling of String Encodings
@@ -45,7 +45,6 @@ Hannes Wyss. Spreadsheet can read, write and modify Spreadsheet Documents.
== Dependencies
* ruby 1.8
-* Iconv
* ruby-ole[http://code.google.com/p/ruby-ole/]
@@ -63,6 +62,13 @@ Using RubyGems[http://www.rubygems.org]:
If you don't like RubyGems[http://www.rubygems.org], let me know which
installation solution you prefer and I'll include it in the future.
+If you can use 'rake' and 'hoe' library is also installed, you can
+build a gem package as follows:
+
+* rake gem
+
+The gem package is built in pkg directory.
+
== Authors
@@ -75,7 +81,7 @@ ParseExcel:
Copyright (c) 2003 by Hannes Wyss (hannes.wyss@gmail.com)
New Code:
-Copyright (c) 2008 by Hannes Wyss (hannes.wyss@gmail.com)
+Copyright (c) 2010 ywesee GmbH (mhatakeyama@ywesee.com, zdavatz@ywesee.com)
== License
View
11 Rakefile
@@ -1,16 +1,17 @@
# -*- ruby -*-
+$: << File.expand_path("./lib", File.dirname(__FILE__))
+
require 'rubygems'
require 'hoe'
require './lib/spreadsheet.rb'
ENV['RDOCOPT'] = '-c utf8'
-Hoe.spec 'spreadsheet' do
- self.rubyforge_name = 'spreadsheet'
- self.version = Spreadsheet::VERSION
- self.developer 'Hannes Wyss', 'hannes.wyss@gmail.com'
- p.extra_deps << ['ruby-ole', ">= 1.2.11.1"]
+Hoe.spec('spreadsheet') do |p|
+ p.developer('Masaomi Hatakeyama, Zeno R.R. Davatz','mhatakeyama@ywesee.com, zdavatz@ywesee.com')
+ p.remote_rdoc_dir = ''
+ p.extra_deps << ['ruby-ole', ">= 1.2.11.1"]
end
# vim: syntax=Ruby
View
8 lib/spreadsheet.rb
@@ -1,6 +1,6 @@
### Spreadsheet - A Library for reading and writing Spreadsheet Documents.
#
-# Copyright (C) 2008 Hannes Wyss
+# Copyright (C) 2008-2010 ywesee GmbH
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -17,9 +17,9 @@
#
# Contact Information:
#
-# E-Mail: hannes.wyss@gmail.com
+# E-Mail: mhatakeyama@ywesee.com, zdavatz@ywesee.com
# P-Mail: ywesee GmbH
-# Hannes Wyss
+# Zeno R.R. Davatz
# Winterthurerstrasse 52
# 8006 Zürich
### Switzerland
@@ -42,7 +42,7 @@ module Spreadsheet
##
# The version of Spreadsheet you are using.
- VERSION = '0.6.4.2'
+ VERSION = '0.6.5.0'
##
# Default client Encoding. Change this value if your application uses a
View
16 lib/spreadsheet/excel/reader.rb
@@ -216,7 +216,7 @@ def read_colinfo worksheet, work, pos, len
:width => width.to_f / 256,
:hidden => (opts & 0x0001) > 0,
:collapsed => (opts & 0x1000) > 0,
- :outline_level => (opts & 0x0700)
+ :outline_level => (opts & 0x0700) / 256
column.worksheet = worksheet
worksheet.columns[col] = column
end
@@ -831,6 +831,8 @@ def read_worksheet worksheet, offset
#when :index # ○ INDEX ➜ 5.7 (Row Blocks), ➜ 6.55
# TODO: if there are changes in rows, omit index when writing
#read_index worksheet, work, pos, len
+ when :guts # GUTS 5.53
+ read_guts worksheet, work, pos, len
when :colinfo # ○○ COLINFO ➜ 6.18
read_colinfo worksheet, work, pos, len
when :dimensions # ● DIMENSIONS ➜ 6.31
@@ -850,6 +852,18 @@ def read_worksheet worksheet, offset
previous = op
end
end
+ def read_guts worksheet, work, pos, len
+ # Offset Size Contents
+ # 0 2 Width of the area to display row outlines (left of the sheet), in pixel
+ # 2 2 Height of the area to display column outlines (above the sheet), in pixel
+ # 4 2 Number of visible row outline levels (used row levels + 1; or 0, if not used)
+ # 6 2 Number of visible column outline levels (used column levels + 1; or 0, if not used)
+ width, height, row_level, col_level = work.unpack 'v4'
+ worksheet.guts[:width] = width
+ worksheet.guts[:height] = height
+ worksheet.guts[:row_level] = row_level
+ worksheet.guts[:col_level] = col_level
+ end
def read_style work, pos, len
# User-Defined Cell Styles:
# Offset Size Contents
View
3  lib/spreadsheet/excel/worksheet.rb
@@ -11,13 +11,14 @@ module Excel
class Worksheet < Spreadsheet::Worksheet
include Spreadsheet::Excel::Offset
offset :dimensions
- attr_reader :offset, :ole, :links
+ attr_reader :offset, :ole, :links, :guts
def initialize opts = {}
@row_addresses = nil
super
@offset, @ole, @reader = opts[:offset], opts[:ole], opts[:reader]
@dimensions = nil
@links = {}
+ @guts = {}
end
def add_link row, column, link
@links.store [row, column], link
View
41 lib/spreadsheet/excel/writer/worksheet.rb
@@ -240,6 +240,15 @@ def write_cellblocks row
write_multiples row, first_idx, multiples if multiples
end
def write_changes reader, endpos, sst_status
+
+ ## FIXME this is not smart solution to update outline_level.
+ # without this process, outlines in row disappear in MS Excel.
+ @worksheet.row_count.times do |i|
+ if @worksheet.row(i).outline_level > 0
+ @worksheet.row(i).outline_level = @worksheet.row(i).outline_level
+ end
+ end
+
reader.seek @worksheet.offset
blocks = row_blocks
lastpos = reader.pos
@@ -296,6 +305,13 @@ def write_changes reader, endpos, sst_status
lastpos = pos + len
reader.seek lastpos
end
+
+ # Necessary for outline (grouping) and hiding functions
+ # but these below are not necessary to run
+ # if [Row|Column]#hidden? = false and [Row|Column]#outline_level == 0
+ write_colinfos
+ write_guts
+
@io.write reader.read(endpos - lastpos)
end
def write_colinfo bunch
@@ -448,6 +464,7 @@ def write_from_scratch
# ○ PRINTGRIDLINES ➜ 5.80
# ○ GRIDSET ➜ 5.52
# ○ GUTS ➜ 5.53
+ write_guts
# ○ DEFAULTROWHEIGHT ➜ 5.31
write_defaultrowheight
# ○ WSBOOL ➜ 5.113
@@ -483,6 +500,28 @@ def write_from_scratch
# ● EOF ➜ 5.36
write_eof
end
+ ##
+ # Write record that contains information about the layout of outline symbols.
+ def write_guts
+ # find the maximum outline_level in rows and columns
+ row_outline_level = 0
+ col_outline_level = 0
+ if(row = @worksheet.rows.select{|x| x!=nil}.max{|a,b| a.outline_level <=> b.outline_level})
+ row_outline_level = row.outline_level
+ end
+ if(col = @worksheet.columns.select{|x| x!=nil}.max{|a,b| a.outline_level <=> b.outline_level})
+ col_outline_level = col.outline_level
+ end
+ # set data
+ data = [
+ 0, # Width of the area to display row outlines (left of the sheet), in pixel
+ 0, # Height of the area to display column outlines (above the sheet), in pixel
+ row_outline_level+1, # Number of visible row outline levels (used row levels+1; or 0,if not used)
+ col_outline_level+1 # Number of visible column outline levels (used column levels+1; or 0,if not used)
+ ]
+ # write record
+ write_op opcode(:guts), data.pack('v4')
+ end
def write_hlink row, col, link
# FIXME: only Hyperlinks are supported at present.
cell_range = [
@@ -793,6 +832,8 @@ def write_window2
if @worksheet.selected
flags |= 0x0200
end
+ flags |= 0x0080 # Show outline symbols,
+ # but if [Row|Column]#outline_level = 0 the symbols are not shown.
data = [ flags, 0, 0, 0, 0, 0 ].pack binfmt(:window2)
write_op opcode(:window2), data
end
View
3  lib/spreadsheet/font.rb
@@ -59,7 +59,8 @@ class Font
enum :encoding, :default, :iso_latin1, :symbol, :apple_roman, :shift_jis,
:korean_hangul, :korean_johab, :chinese_simplified,
:chinese_traditional, :greek, :turkish, :vietnamese,
- :hebrew, :arabic, :cyrillic, :thai, :iso_latin2, :oem_latin1
+ :hebrew, :arabic, :baltic, :cyrillic, :thai, :iso_latin2,
+ :oem_latin1
def initialize name, opts={}
self.name = name
@color = :text
View
2  lib/spreadsheet/link.rb
@@ -30,7 +30,7 @@ def initialize url='', description=url, fragment=nil
def href
href = (@url || @dos).to_s.dup
if @fragment
- href << client('#') << @fragment
+ href << client('#', 'UTF-8') << @fragment
end
href
end
View
BIN  spreadsheet-0.6.5.gem
Binary file not shown
View
37 spreadsheet.gemspec
@@ -1,21 +1,22 @@
-# encoding: utf-8
+require "rubygems"
+require "rake"
-Gem::Specification.new do |s|
- s.name = %q{spreadsheet}
- s.version = "0.6.4.1"
- s.date = %q{2010-11-16}
-
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Hannes Wyss"]
- s.description = %q{Library to read and write MS Excel Spreadsheets}
- s.summary = %q{Read and Write Excel Spreadsheets}
- s.email = %q{hannes.wyss@gmail.com}
- s.files = Dir.glob("bin/*") + Dir.glob("lib/**/*") + %w(LICENSE.txt README.txt)
- s.homepage = %q{http://github.com/scottwillson/spreadsheet/tree/master}
- s.rdoc_options = ["--charset=UTF-8"]
- s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.6}
-
- s.add_dependency(%q<ruby-ole>, [">= 1.2.11.1"])
+spec = Gem::Specification.new do |s|
+ s.name = "spreadsheet"
+ s.version = "0.6.5"
+ s.summary = "The Spreadsheet Library is designed to read and write Spreadsheet Documents"
+ s.description = "As of version 0.6.0, only Microsoft Excel compatible spreadsheets are supported"
+ s.author = "Masaomi Hatakeyama, Zeno R.R. Davatz"
+ s.email = "mhatakeyama@ywesee.com, zdavatz@ywesee.com"
+ s.platform = Gem::Platform::RUBY
+ s.files = Dir.glob("{bin,lib,test}/**/*") + Dir.glob("*.txt")
+ s.test_file = "test/suite.rb"
+ s.executables << 'xlsopcodes'
+ s.add_dependency('ruby-ole')
+ s.homepage = "http://scm.ywesee.com/?p=spreadsheet/.git;a=summary"
+end
+if $0 == __FILE__
+ Gem.manage_gems
+ Gem::Builder.new(spec).build
end
View
9 test/integration.rb
@@ -829,7 +829,7 @@ def test_write_new_workbook
sheet1[5,0] = 0.75
sheet1.row(5).set_format 0, fmt
link = Link.new 'http://scm.ywesee.com/?p=spreadsheet;a=summary',
- 'The Spreadsheet GitWeb'
+ 'The Spreadsheet GitWeb', 'top'
sheet1[5,1] = link
sheet1[6,0] = 1
fmt = Format.new :color => 'green'
@@ -962,6 +962,7 @@ def test_write_new_workbook
url = @@iconv.iconv 'http://scm.ywesee.com/?p=spreadsheet;a=summary'
assert_equal @@iconv.iconv('The Spreadsheet GitWeb'), link
assert_equal url, link.url
+ assert_equal @@iconv.iconv('top'), link.fragment
row = sheet.row 6
assert_equal :green, row.format(0).font.color
assert_equal 1, row[0]
@@ -1270,5 +1271,11 @@ def test_changes
target = File.join @var, 'test_changes.xls'
assert_nothing_raised do book.write target end
end
+ def test_read_baltic
+ path = File.join @data, 'test_baltic.xls'
+ assert_nothing_raised do
+ Spreadsheet.open path
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.