fastxl 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 18365bad1e1d156b030b366b970c2967a736f593
4
- data.tar.gz: ed79d2ebeba1d0c8e1a52db9664f43da0c424d94
3
+ metadata.gz: 621e49823895d3c8115c1a67bd9187ff8c66c2da
4
+ data.tar.gz: 7a9ce8cae33b5cb15c353e9a42ce186eb4bd741c
5
5
  SHA512:
6
- metadata.gz: fbbb9daaa5aa3547dc5f955875b1cbe3e3b192724d3f3a08841e2ae5aa7423b4631e8ce80e15f4bf416080416360c161a55b5cbb45cce0f2a1a8c9383947df92
7
- data.tar.gz: 8dbcd393bf9d957c8c6d818508d3a241b0ffcfa60c2e9d2d288ffb7bc26ffc097dadaf2002c09fbad65e50e393d74367fd5a15f6d683d50d0462ce5274b4f91f
6
+ metadata.gz: f418e5561e57ab22e183c04c1ea980f364fe8523004fde9a4e2b228faaaf05524946163776f55cf8f36fd614be4d7f961e55dd89bc7ddc3cf3aefeeec221cfe5
7
+ data.tar.gz: 4dcf877739c56b61000c620b8e353dccf30600167df0b9d846313a7dff282f32212a4f55da89e0587c9a7923ec1745aff3b1cde6cae46b926917ef7c7c757ba7
@@ -1,3 +1,3 @@
1
1
  module Fastxl
2
- VERSION = "0.4.0"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -24,18 +24,10 @@ class Fastxl::Workbook
24
24
  document_paths = @virtual_dom.keys
25
25
 
26
26
  @xlsx.entries.each do |e|
27
- if e.name.in?(document_paths)
27
+ if document_paths.include?(e.name)
28
28
  document_path = e.name
29
- doc = xml_doc(document_path)
30
- doc.xpath('//xmlns:sheetData').xpath('//xmlns:row').remove
31
- doc.xpath('//xmlns:sheetData').first.add_child(rows(@virtual_dom[document_path]))
32
-
33
- doc.xpath('//xmlns:worksheet').xpath('//xmlns:cols').remove
34
- doc.xpath('//xmlns:worksheet').first.add_child('<cols><col collapsed="false" hidden="false" max="1025" min="1" style="0" width="11.3418367346939"/></cols>')
35
-
36
29
  out.put_next_entry(document_path)
37
-
38
- out.write doc.to_xml(:indent => 0).gsub("\n","")
30
+ out.write(sheet_content_to_xml(@virtual_dom[document_path]))
39
31
  else
40
32
  out.put_next_entry(e.name)
41
33
  out.write e.get_input_stream.read
@@ -54,6 +46,20 @@ class Fastxl::Workbook
54
46
 
55
47
  private
56
48
 
49
+ def sheet_content_to_xml(sheet_content)
50
+ ret = '<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" mc:Ignorable="x14ac">'
51
+ ret << "<dimension ref=\"A1:#{sheet_content.first ? excel_letter(sheet_content.first.size) : 'A'}#{sheet_content.size > 0 ? sheet_content.size : 1}\"/>"
52
+ ret << '<sheetViews>'
53
+ ret << '<sheetView showOutlineSymbols="0" showWhiteSpace="0" workbookViewId="0"/>'
54
+ ret << '</sheetViews>'
55
+ ret << '<sheetFormatPr defaultRowHeight="14.25" x14ac:dyDescent="0.2"/>'
56
+ ret << '<sheetData>'
57
+ ret << rows(sheet_content)
58
+ ret << '</sheetData>'
59
+ ret << '<pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/>'
60
+ ret << '</worksheet>'
61
+ end
62
+
57
63
  def rows(sheet_content)
58
64
  xml = ''
59
65
 
@@ -65,7 +71,7 @@ class Fastxl::Workbook
65
71
  end
66
72
 
67
73
  def xml_row(row, row_id)
68
- xml = "<row r=\"#{row_id}\" customFormat=\"false\" ht=\"14.25\" hidden=\"false\" customHeight=\"false\" outlineLevel=\"0\" collapsed=\"false\">"
74
+ xml = "<row r=\"#{row_id}\" >"
69
75
 
70
76
  row.each_with_index do |c, idx|
71
77
  xml << xml_col(c, idx + 1, row_id)
@@ -75,7 +81,7 @@ class Fastxl::Workbook
75
81
  end
76
82
 
77
83
  def xml_col(col, idx, row_id)
78
- "<c r=\"#{excel_letter(idx)}#{row_id}\" s=\"1\" t=\"inlineStr\"><is><t>#{col}</t></is></c>"
84
+ "<c r=\"#{excel_letter(idx)}#{row_id}\" t=\"inlineStr\"><is><t>#{col.to_s.encode(xml: :text)}</t></is></c>"
79
85
  end
80
86
 
81
87
  def excel_letter(idx)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastxl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Campos
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-10-31 00:00:00.000000000 Z
11
+ date: 2016-11-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler