diff options
| author | Randy Morgan <[email protected]> | 2011-12-06 14:26:31 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2011-12-06 14:26:31 +0900 |
| commit | cc3862f5df608d738b86bd755aec8c3282aa2cb5 (patch) | |
| tree | dc794046d40706fd8e9f4e771077d89167f9e518 /lib | |
| parent | 78de4578651503bf9fa8cc8028ac0192eb8b448d (diff) | |
| download | caxlsx-cc3862f5df608d738b86bd755aec8c3282aa2cb5.tar.gz caxlsx-cc3862f5df608d738b86bd755aec8c3282aa2cb5.zip | |
Formatting float values for column width and date values in an attempt to resolve https://github.com/randym/axlsx/issues/1
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/util/constants.rb | 4 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/cell.rb | 3 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 7 |
3 files changed, 11 insertions, 3 deletions
diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb index b0a81eac..fb5e20ea 100644 --- a/lib/axlsx/util/constants.rb +++ b/lib/axlsx/util/constants.rb @@ -12,6 +12,10 @@ module Axlsx # extended-properties namespace APP_NS = "http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" + XML_NS_MC="http://schemas.openxmlformats.org/markup-compatibility/2006" + + XML_NS_X14AC = "http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" + # doc props namespace APP_NS_VT = "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes" diff --git a/lib/axlsx/workbook/worksheet/cell.rb b/lib/axlsx/workbook/worksheet/cell.rb index c6ec30d3..5cba8f15 100644 --- a/lib/axlsx/workbook/worksheet/cell.rb +++ b/lib/axlsx/workbook/worksheet/cell.rb @@ -326,7 +326,8 @@ module Axlsx epoc1900 = -2209021200 #Time.local(1900, 1, 1) epoc1904 = -2082877200 #Time.local(1904, 1, 1) epoc = Workbook.date1904 ? epoc1904 : epoc1900 - ((v.localtime.to_f - epoc) /60.0/60.0/24.0).to_f + v = ((v.localtime.to_f - epoc) /60.0/60.0/24.0).to_f + ((v * 10**11).round.to_f / 10**11) elsif @type == :float v.to_f elsif @type == :integer diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index 8cbf876f..9a08a345 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -199,12 +199,15 @@ module Axlsx # @return [String] def to_xml builder = Nokogiri::XML::Builder.new(:encoding => ENCODING) do |xml| - xml.worksheet(:xmlns => XML_NS, :'xmlns:r' => XML_NS_R) { + xml.worksheet(:xmlns => XML_NS, + :'xmlns:r' => XML_NS_R, + :'xmlns:mc' => XML_NS_MC, + :'xmlns:x14ac' => XML_NS_X14AC) { 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 => auto_width(col), :customWidth=>"true") + xml.col(:min=>min_max, :max=>min_max, :width => ("%.2f" % auto_width(col)), :customWidth=>"true") end } end |
