summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2011-12-07 23:42:48 +0900
committerRandy Morgan <[email protected]>2011-12-07 23:42:48 +0900
commit29551803ab1ed987c2c13b477a2f1d86b7c616f0 (patch)
tree8a22c7641b699a1e0967b5836f3fec06c26f7749
parent2cd0870511ad34b51b689223cfea40daa7d1ba98 (diff)
downloadcaxlsx-29551803ab1ed987c2c13b477a2f1d86b7c616f0.tar.gz
caxlsx-29551803ab1ed987c2c13b477a2f1d86b7c616f0.zip
patch for issue #1
force binary encoding for zip entries. [bug] fixed error in app.rb so extended properties can now be used. improved support for OOXML cell element types.
-rw-r--r--README.md11
-rw-r--r--axlsx.gemspec8
-rw-r--r--examples/example.rb10
-rw-r--r--lib/axlsx/doc_props/app.rb6
-rw-r--r--lib/axlsx/package.rb11
-rw-r--r--lib/axlsx/stylesheet/styles.rb8
-rw-r--r--lib/axlsx/version.rb2
-rw-r--r--lib/axlsx/workbook/worksheet/cell.rb6
-rw-r--r--lib/axlsx/workbook/worksheet/worksheet.rb6
9 files changed, 34 insertions, 34 deletions
diff --git a/README.md b/README.md
index 51bba02b..1a9b0a1a 100644
--- a/README.md
+++ b/README.md
@@ -7,10 +7,10 @@ Axlsx: Office Open XML Spreadsheet Generation
**Author**: Randy Morgan
**Copyright**: 2011
**License**: MIT License
-**Latest Version**: 1.0.11
+**Latest Version**: 1.0.12
**Ruby Version**: 1.8.7, 1.9.2, 1.9.3
-**Release Date**: December 5th 2011
+**Release Date**: December 7th 2011
Synopsis
--------
@@ -81,7 +81,7 @@ A Simple Workbook
p = Axlsx::Package.new
p.workbook.add_worksheet do |sheet|
- sheet.add_row ["First", "Second", "Third"]
+ sheet.add_row ["First Column", "Second Column", "Third Column"]
sheet.add_row [1, 2, Time.now]
end
p.serialize("example1.xlsx")
@@ -105,7 +105,7 @@ Generating A Pie Chart
p.workbook.add_worksheet do |sheet|
sheet.add_row ["First", "Second", "Third", "Fourth"]
sheet.add_row [1, 2, 3, "=PRODUCT(A2:C2)"]
- sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0, 2], :end_at => [5, 15], :title=>"example 3: Pie Chart") do |chart|
+ sheet.add_chart(Axlsx::Pie3DChart, :start_at => [0, 2], :end_at => [5, 25], :title=>"example 3: Pie Chart") do |chart|
chart.add_series :data => sheet["A2:D2"], :labels => sheet["A1:D1"]
end
end
@@ -244,6 +244,9 @@ This gem has 100% test coverage using test/unit. To execute tests for this gem,
Changelog
---------
+- **December.7.11**: 1.0.12 release
+ - changed dependency from 'zip' jem to 'rubyzip' and added conditional code to force binary encoding to resolve issue with excel 2011
+ - Patched bug in app.xml that would ignore user specified properties.
- **December.5.11**: 1.0.11 release
- Added [] methods to worksheet and workbook to provide name based access to cells.
- Added support for functions as cell values
diff --git a/axlsx.gemspec b/axlsx.gemspec
index 264e4f73..0ff8dd41 100644
--- a/axlsx.gemspec
+++ b/axlsx.gemspec
@@ -14,9 +14,10 @@ Gem::Specification.new do |s|
s.description = <<-eof
xlsx generation with charts, images, automated column width, customizable styles and full schema validation. Axlsx excels at helping you generate beautiful Office Open XML Spreadsheet documents without having to understand the entire ECMA specification. Check out the README for some examples of how easy it is. Best of all, you can validate your xlsx file before serialization so you know for sure that anything generated is going to load on your client's machine.
eof
- s.files = Dir.glob("{doc,lib,test,schema,examples}/**/*") + %w{ LICENSE README.md Rakefile CHANGELOG.md }
+ s.files = Dir.glob("{lib/**/*.rb,lib/schema,examples}/**/*") + %w{ LICENSE README.md Rakefile CHANGELOG.md .yardopts }
+ s.test_files = Dir.glob("{test/**/*.rb}")
- # s.files = FileList.new('*', 'lib/**/*', 'doc/**/*', 'schema/**/*', 'examples/**/*') do |fl|
+ # s.files = FileList.new('*', 'lib/**/*.rb', 'doc/**/*', /**/*', 'examples/**/*') do |fl|
# fl.exclude("*.*~")
# fl.exclude(".*")
# fl.exclude("todo")
@@ -32,11 +33,10 @@ Gem::Specification.new do |s|
s.add_runtime_dependency 'activesupport', '>= 2.3.9'
s.add_runtime_dependency 'i18n', '>= 0.6.0'
s.add_runtime_dependency 'rmagick', '>= 2.12.2'
- s.add_runtime_dependency 'zip', '>= 2.0.2'
+ s.add_runtime_dependency 'rubyzip', '~> 0.9'
s.add_development_dependency 'rake', "0.8.7" if RUBY_VERSION == "1.9.2"
s.add_development_dependency 'rake', "~> 0.9" if ["1.9.3", "1.8.7"].include?(RUBY_VERSION)
- s.add_development_dependency 'bundler'
s.required_ruby_version = '>= 1.8.7'
s.require_path = 'lib'
diff --git a/examples/example.rb b/examples/example.rb
index 8900ea09..4bc9bf23 100644
--- a/examples/example.rb
+++ b/examples/example.rb
@@ -1,16 +1,18 @@
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
- require 'rubygems'
- require 'axlsx.rb'
+# require 'rubygems' if that is how you do it!
+require 'axlsx'
#A Simple Workbook
if ARGV.size == 0 || ARGV.include?("1")
p = Axlsx::Package.new
p.workbook.add_worksheet do |sheet|
- sheet.add_row ["First", "Second", "Third"]
- sheet.add_row [1, 2, Time.now]
+ sheet.add_row ["First Column", "Second", "Third"]
+ sheet.add_row [1, 2, 3]
end
+ #p.workbook.date1904 = true
+ p.validate.each { |e| puts e.message }
p.serialize("example1.xlsx")
end
#Generating A Bar Chart
diff --git a/lib/axlsx/doc_props/app.rb b/lib/axlsx/doc_props/app.rb
index 8e6bea27..aaf60092 100644
--- a/lib/axlsx/doc_props/app.rb
+++ b/lib/axlsx/doc_props/app.rb
@@ -102,9 +102,9 @@ module Axlsx
# @option options [String] Application
# @option options [String] AppVersion
# @option options [Integer] DocSecurity
- def initalize(options={})
+ def initialize(options={})
options.each do |o|
- self.send("#{o[0]}=", o[1]) if self.respond_to? o[0]
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
end
end
@@ -168,7 +168,7 @@ module Axlsx
builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
xml.send(:Properties, :xmlns => APP_NS, :'xmlns:vt' => APP_NS_VT) {
self.instance_values.each do |name, value|
- xml.send("ap:#{name}", value)
+ xml.send(name, value)
end
}
end
diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb
index d5171a38..0dc72395 100644
--- a/lib/axlsx/package.rb
+++ b/lib/axlsx/package.rb
@@ -11,7 +11,7 @@ module Axlsx
# @example Package.new :author => 'you!', :workbook => Workbook.new
def initialize(options={})
@workbook = nil
- @core, @app = Core.new, App.new
+ @core, @app = Core.new, App.new
@core.creator = options[:author] || @core.creator
yield self if block_given?
end
@@ -65,8 +65,9 @@ module Axlsx
Zip::ZipOutputStream.open(output) do |zip|
p.each do |part|
unless part[:doc].nil?
- zip.put_next_entry(part[:entry]);
- zip.puts(part[:doc])
+ zip.put_next_entry(part[:entry]);
+ entry = ['1.9.2', '1.9.3'].include?(RUBY_VERSION) ? part[:doc].force_encoding('BINARY') : part[:doc]
+ zip.puts(entry)
end
unless part[:path].nil?
zip.put_next_entry(part[:entry]);
@@ -108,12 +109,12 @@ module Axlsx
def parts
@parts = [
{:entry => RELS_PN, :doc => relationships.to_xml, :schema => RELS_XSD},
+ {:entry => "xl/#{STYLES_PN}", :doc => workbook.styles.to_xml, :schema => SML_XSD},
{:entry => CORE_PN, :doc => @core.to_xml, :schema => CORE_XSD},
{:entry => APP_PN, :doc => @app.to_xml, :schema => APP_XSD},
{:entry => WORKBOOK_RELS_PN, :doc => workbook.relationships.to_xml, :schema => RELS_XSD},
- {:entry => WORKBOOK_PN, :doc => workbook.to_xml, :schema => SML_XSD},
{:entry => CONTENT_TYPES_PN, :doc => content_types.to_xml, :schema => CONTENT_TYPES_XSD},
- {:entry => "xl/#{STYLES_PN}", :doc => workbook.styles.to_xml, :schema => SML_XSD}
+ {:entry => WORKBOOK_PN, :doc => workbook.to_xml, :schema => SML_XSD}
]
workbook.drawings.each do |drawing|
@parts << {:entry => "xl/#{drawing.rels_pn}", :doc => drawing.relationships.to_xml, :schema => RELS_XSD}
diff --git a/lib/axlsx/stylesheet/styles.rb b/lib/axlsx/stylesheet/styles.rb
index de5835dd..9db0a805 100644
--- a/lib/axlsx/stylesheet/styles.rb
+++ b/lib/axlsx/stylesheet/styles.rb
@@ -240,7 +240,7 @@ module Axlsx
builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
xml.styleSheet(:xmlns => XML_NS) {
[:numFmts, :fonts, :fills, :borders, :cellStyleXfs, :cellXfs, :cellStyles, :dxfs, :tableStyles].each do |key|
- self.instance_values[key.to_s].to_xml(xml)
+ self.instance_values[key.to_s].to_xml(xml) unless self.instance_values[key.to_s].nil?
end
}
end
@@ -258,7 +258,7 @@ module Axlsx
@numFmts.lock
@fonts = SimpleTypedList.new Font
- @fonts << Font.new(:name => "Arial", :sz => 11, :family=>1, :numFmt=>"0")
+ @fonts << Font.new(:name => "Arial", :sz => 11, :family=>1)
@fonts.lock
@fills = SimpleTypedList.new Fill
@@ -276,7 +276,7 @@ module Axlsx
@borders.lock
@cellStyleXfs = SimpleTypedList.new Xf, "cellStyleXfs"
- @cellStyleXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
+ @cellStyleXfs << Xf.new(:borderId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
@cellStyleXfs.lock
@cellStyles = SimpleTypedList.new CellStyle
@@ -287,7 +287,7 @@ module Axlsx
@cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
@cellXfs << Xf.new(:borderId=>1, :xfId=>0, :numFmtId=>0, :fontId=>0, :fillId=>0)
# default date formatting
- @cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>14, :fontId=>0, :fillId=>0)
+ @cellXfs << Xf.new(:borderId=>0, :xfId=>0, :numFmtId=>14, :fontId=>0, :fillId=>0, :applyNumberFormat=>1)
@cellXfs.lock
@dxfs = SimpleTypedList.new(Xf, "dxfs"); @dxfs.lock
diff --git a/lib/axlsx/version.rb b/lib/axlsx/version.rb
index f6a14039..f2f7571f 100644
--- a/lib/axlsx/version.rb
+++ b/lib/axlsx/version.rb
@@ -1,4 +1,4 @@
module Axlsx
# version
- VERSION="1.0.11"
+ VERSION="1.0.12"
end
diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb
index 5343a4cf..0a260d7e 100644
--- a/lib/axlsx/workbook/worksheet/cell.rb
+++ b/lib/axlsx/workbook/worksheet/cell.rb
@@ -225,15 +225,12 @@ module Axlsx
# @note
# Shared Strings are not used in this library. All values are set directly in the each sheet.
def to_xml(xml)
- # Both 1.8 and 1.9 return the same 'fast_xf'
- # &#12491;&#12507;&#12531;&#12468;
- # &#12491;&#12507;&#12531;&#12468;
# however nokogiri does a nice 'force_encoding' which we shall remove!
if @type == :string
#parse formula
if @value.start_with?('=')
- xml.c(:r => r, :s=>style) {
+ xml.c(:r => r, :t=>:str, :s=>style) {
xml.f @value.to_s.gsub('=', '')
}
else
@@ -269,7 +266,6 @@ module Axlsx
}
}
end
-
else
xml.c(:r => r, :s => style) { xml.v value }
end
diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb
index 9a08a345..1500d515 100644
--- a/lib/axlsx/workbook/worksheet/worksheet.rb
+++ b/lib/axlsx/workbook/worksheet/worksheet.rb
@@ -200,14 +200,12 @@ module Axlsx
def to_xml
builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml|
xml.worksheet(:xmlns => XML_NS,
- :'xmlns:r' => XML_NS_R,
- :'xmlns:mc' => XML_NS_MC,
- :'xmlns:x14ac' => XML_NS_X14AC) {
+ :'xmlns:r' => XML_NS_R) {
if @auto_fit_data.size > 0
xml.cols {
@auto_fit_data.each_with_index do |col, index|
min_max = index+1
- xml.col(:min=>min_max, :max=>min_max, :width => ("%.2f" % auto_width(col)), :customWidth=>"true")
+ xml.col(:min=>min_max, :max=>min_max, :width => auto_width(col), :customWidth=>1)
end
}
end