oxcelix 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,64 +1,21 @@
1
- * Fixed serious regression which was preventing the copy-merge routine from properly run (cols and rows were flipped). Fixed smaller bug which caused comments to be inserted as a 1-element array of hashes instead of plain text.
2
- Thu Oct 10 23:44:39 2013 +0200
3
- * Fixed major bug which prevented the comments to be pulled from the XML files.
4
- Thu Oct 10 20:12:56 2013 +0200
5
- * Fixed serious bug concerning the loading of the worksheets. Oxcelix will now correctly guess the filenames of the XML files describing the sheets
6
- Thu Oct 10 18:22:39 2013 +0200
7
- * Update workbook.rb Wed Oct 9 19:10:39 2013 +0200
8
- * Changed another instance of Ox::load_file, as it won't work under windows Wed Oct 9 18:59:50 2013 +0200
9
- * The sheet class now inherits Matrix. Sheet can return a cell based on its excel name. Sheet::data is obsolete - deleted. Moved r, v, s to the Cellvalues module - they are not needed elsewhere but the Cell class. Documentation changes. .yardopts file added.
10
- Tue Oct 8 23:10:25 2013 +0200
11
- * The sheet class now inherits Matrix. Sheet can return a cell based on its excel name. Sheet::data is obsolete - deleted. Moved r, v, s to the Cellvalues module - they are not needed elsewhere but the Cell class. Documentation changes. .yardopts file added.
12
- Tue Oct 8 23:07:10 2013 +0200
13
- * slight documentation changes, yard options added to (protected and private methods docs are now readable)
14
- Tue Oct 8 20:17:29 2013 +0200
15
- * Changed gem version Mon Oct 7 22:12:34 2013 +0200
16
- * Removed sharedstrings and sheetbase properties as they were useless. Docs updated with the change. Mon Oct 7 18:15:44 2013 +0200
17
- * Update oxcelix.gemspec Mon Oct 7 17:48:14 2013 +0200
18
- * Update oxcelix.gemspec
19
-
20
- Raised visibility in rdoc, so that all method documentation gets readable. Mon Oct 7 17:47:50 2013 +0200
21
- * Update workbook.rb
22
-
23
- replaced Ox::load_file with IO.read + Ox::load in workbook, as apparently workbook.xml could not be loaded under windows using that method Mon Oct 7 17:37:39 2013 +0200
24
- * Minor typos corrected, added gemspec
25
- Sun Oct 6 16:52:54 2013 +0200
26
- * oxcelix.rb was not added to previous commit
27
- Sun Oct 6 12:29:37 2013 +0200
28
- * Broke down oxcelix.rb. Improved YARD documentation.
29
- Sun Oct 6 12:25:59 2013 +0200
30
- * Removed unneeded method from Xlsheet. Started converting docs to YARD
31
- Sat Oct 5 09:20:31 2013 +0200
32
- * Merge branch 'master' of https://github.com/gbiczo/oxcelix
33
- Wed Oct 2 00:19:54 2013 +0200
34
- * Repeating commit as the sheetdata method code was not included. Now it will simply do some Array magic to return the list of active sheets.
35
- Wed Oct 2 00:19:18 2013 +0200
36
- * Update README.md
37
-
38
- Fixed typos Wed Oct 2 00:08:00 2013 +0200
39
- * Merge branch 'master' of https://github.com/gbiczo/oxcelix
40
- Tue Oct 1 23:51:13 2013 +0200
41
- * Moved source to lib directory.
42
- Tue Oct 1 23:43:53 2013 +0200
43
- * Added README
44
- Tue Oct 1 23:42:27 2013 +0200
45
- * Added tests, recreated include-exclude code, now it works fine. Created README.rdoc
46
- Tue Oct 1 23:42:00 2013 +0200
47
- * Update README.md
48
-
49
- Corrected typo Tue Oct 1 23:32:22 2013 +0200
50
- * Update README.md Tue Oct 1 23:31:47 2013 +0200
51
- * Initial commit
52
- Tue Oct 1 14:21:10 2013 -0700
53
- * Really deleted the last few lines of code.
54
- Sat Sep 28 15:49:06 2013 +0200
55
- * Wrapper module Oxcelix created. String, Matrix, Fixnum are not included. Sheet objects are now created as a last step instead og the simple hashes. Workbookhelper module added, with one method, [](sheetname), which accepts a string parameter and returns the sheet named sheetname. Code cleanups (especially the last lines of the code which were there only for testing purposes.)
56
- Sat Sep 28 15:46:56 2013 +0200
57
- * Corrected Cellhelper::x() and Cellhelper::y() methods, now both return correct values. RDoc documentation added.
58
- Wed Sep 25 23:44:07 2013 +0200
59
- * Added support for sheet inclusion and exclusion. Workbook#new now accepts a hash of parameters, which may contain: :copymerge (Bool), :include_sheets (Ary), :exclude_sheets (Ary)
60
- Wed Sep 25 09:49:42 2013 +0200
61
- * Added col_name to display excel column names. Style data of cell is now included. X and Y may get parameters. The Workbook constructor will now unzip and process the excel file. All sheets get converted to matrices. Upon the Array->Matrix conversion, the merged cells max be omitted or repeated.
62
- Mon Sep 23 20:32:25 2013 +0200
63
- * First gitted version.
64
- Thu Aug 29 09:14:59 2013 +0200
1
+ * Further code cleanup in numformats.rb Tue Dec 3 19:49:03 2013 +0100
2
+ * Renamed add to add_custom_formats Tue Dec 3 19:46:15 2013 +0100
3
+ * Path cleanup Tue Dec 3 19:07:47 2013 +0100
4
+ * Added documentation to Formatarray. Fixed bug which prevented cells containing e.g. String values AND datetime/numeric formatting code to be properly returned when to_ru or to_fmt was invoked. Code cleanup. Tue Dec 3 19:06:39 2013 +0100
5
+ * Numberhelper included in Cell class. Various typos corrected. Cell#to_ru and Cell#to_fmt now reflect the inclusion of the Numberformats module. Mon Dec 2 23:27:52 2013 +0100
6
+ * to_ru and to_fmt methods are now encapsulated in the Numhelper method. This is not only cleaner, ensures them to be included in Cell and only there. Mon Dec 2 23:04:13 2013 +0100
7
+ * Cleared @numformats from Workbook. Formatarray is now a Numformats module constant available to any class including it. Mon Dec 2 22:47:40 2013 +0100
8
+ * Numformat is now included in Workbook. Dtmap became a constant. New method Numformats::add converts the temparray to a series of numformat hashes and adds it to the main numformat array. to_ru, to_fmt, datetime, numeric are now Workbook methods. Slight code cleanup. Sun Dec 1 19:28:41 2013 +0100
9
+ * Numformats.rb cleanup. Documented new modules/methods. Restructured to_ru and to_fmt. Fri Nov 29 09:23:41 2013 +0100
10
+ * Code cleanup. TODO: split format string (;)? cellhelper.rb to be cleaned up Mon Nov 25 00:06:38 2013 +0100
11
+ * finalized numeric method with a regex composed by 6 members: prefix, decimals, separator, floats, expo, postfix. This obsoletes the vgrp method as well as the other ones (still in the numformats.rb file.) TODO: delete all unnecessary code and provide a meaningful return value. Mon Nov 25 00:00:52 2013 +0100
12
+ * Added Numformats Sat Nov 23 09:48:50 2013 +0100
13
+ * Merge branch '0.3.0' of https://github.com/gbiczo/oxcelix into 0.3.0 Sat Nov 23 09:43:59 2013 +0100
14
+ * Added numformats.rb. Cleaned styles.rb from unnecessary comments. Sat Nov 23 09:41:10 2013 +0100
15
+ * Added badge Fri Nov 22 12:20:48 2013 +0100
16
+ * Some speed optimizations. matrixto does not accept fmt parameter any more. fixed typos Wed Nov 13 00:03:44 2013 +0100
17
+ * Cell now has a numformat attribute. A new module called Numformats will contain methods related to numeric formatting. to_r and to_d are now obsolete. Xlsheet init parameter (styles). Stylefile is opened in the workbook. Matrixto gets a :values option (this will be obsoleted shortly). Slight Gemspec and .md description change Mon Nov 4 17:47:17 2013 +0100
18
+ * Initial version of Sheet::to_m method Sat Oct 19 11:06:42 2013 +0200
19
+ * Format array is now a constant (FARY) Fri Oct 18 21:58:39 2013 +0200
20
+ * Fixed typo in README Fri Oct 18 21:51:09 2013 +0200
21
+ * Started working on cell value formats Fri Oct 18 21:50:24 2013 +0200
data/README.rdoc CHANGED
@@ -1,12 +1,14 @@
1
1
  = \Oxcelix - A fast .xlsx file parser
2
2
 
3
+ {<img src="https://badge.fury.io/rb/oxcelix.png" alt="Gem Version" />}[http://badge.fury.io/rb/oxcelix]
4
+
3
5
  == Description
4
6
 
5
7
  Oxcelix is an xlsx (Excel 2007/2010) parser. The result of the parsing is a
6
8
  Workbook which is an array of Sheet objects, which in turn store the data in
7
9
  Matrix objects. Matrices consist of Cell objects to maintain comments and
8
- formatting/style data
9
- .
10
+ formatting/style data.
11
+
10
12
  Oxcelix uses the great Ox gem (http://rubygems.org/gems/ox) for fast SAX-parsing.
11
13
 
12
14
  == Synopsis
@@ -27,4 +29,4 @@ To include only some of the sheets:
27
29
 
28
30
  To have the values of the merged cells copied over the mergegroup:
29
31
 
30
- w = Oxcelix::Workbook.new('whatever.xlsx', :mergecells => true)
32
+ w = Oxcelix::Workbook.new('whatever.xlsx', :copymerge => true)
data/lib/oxcelix/cell.rb CHANGED
@@ -10,9 +10,13 @@ module Oxcelix
10
10
  # @return [String] Comment text
11
11
  # @!attribute [rw] style
12
12
  # @return [String] Excel style attribute
13
+ # @!attribute [rw] numformat
14
+ # @return [String] Excel style number formatting
15
+
13
16
  class Cell
14
- attr_accessor :xlcoords, :type, :value, :comment, :style
17
+ attr_accessor :xlcoords, :type, :value, :comment, :style, :numformat
15
18
  include Cellhelper
16
19
  include Cellvalues
20
+ include Numberhelper
17
21
  end
18
22
  end
@@ -1,6 +1,7 @@
1
-
2
1
  module Oxcelix
3
- # The Cellhelper module defines some methods useful to manipulate Cell objects
2
+
3
+ # The Cellvalues module provides methods for setting cell values. They are named after the relevant XML entitiesd and
4
+ # called directly by the Xlsheet SAX parser.
4
5
  module Cellvalues
5
6
  # Set the excel cell name (eg: 'A2')
6
7
  # @param [String] val Excel cell address name
@@ -13,6 +14,7 @@ module Oxcelix
13
14
  def s(val); @style = val; end;
14
15
  end
15
16
 
17
+ # The Cellhelper module defines some methods useful to manipulate Cell objects
16
18
  module Cellhelper
17
19
  # When called without parameters, returns the x coordinate of the calling cell object based on the value of #@xlcoords
18
20
  # If a parameter is given, #x will return the x coordinate corresponding to the parameter
data/lib/oxcelix/nf.rb ADDED
@@ -0,0 +1,172 @@
1
+ module Oxcelix
2
+ module Numformats
3
+ # Formatarray is the array of default format strings in Excel. Nil values should apparently contain CJK date format strings,
4
+ #feel free to add/document those according to existing standards.
5
+ Formatarray = [
6
+ {:id => '0', :xl => 'General', :ostring => nil, :cls => 'string'},
7
+ {:id => '1', :xl => '0', :ostring => '%1d', :cls => 'numeric'},
8
+ {:id => '2', :xl => '0.00', :ostring => '%1.2f', :cls => 'numeric'},
9
+ {:id => '3', :xl => '#,##0', :ostring => '%#4d', :cls => 'numeric'},
10
+ {:id => '4', :xl => '#,##0.00', :ostring => '%#4.2f', :cls => 'numeric'},
11
+ {:id => '5', :xl => '', :ostring => nil, :cls => 'string'},
12
+ {:id => '6', :xl => '', :ostring => nil, :cls => 'string'},
13
+ {:id => '7', :xl => '', :ostring => nil, :cls => 'string'},
14
+ {:id => '8', :xl => '', :ostring => nil, :cls => 'string'},
15
+ {:id => '9', :xl => '0%', :ostring => '%1d%', :cls => 'numeric'},
16
+ {:id => '10', :xl => '0.00%', :ostring => '%1.2f%', :cls => 'numeric'},
17
+ {:id => '11', :xl => '0.00E+00', :ostring => '%1.2fE+', :cls => 'numeric'},
18
+ {:id => '12', :xl => '# ?/?', :ostring => '%#1d', :cls => 'rational'},
19
+ {:id => '13', :xl => '# ??/??', :ostring => '%#1d', :cls => 'rational'},
20
+ {:id => '14', :xl => 'd/m/yyyy', :ostring => '%-d/%-m/%Y', :cls => 'date'},
21
+ {:id => '15', :xl => 'd-mmm-yy', :ostring => '%-d-%b-%y', :cls => 'date'},
22
+ {:id => '16', :xl => 'd-mmm', :ostring => '%-d-%b', :cls => 'date'},
23
+ {:id => '17', :xl => 'mmm-yy', :ostring => '%b-%y', :cls => 'date'},
24
+ {:id => '18', :xl => 'h:mm tt', :ostring => '%-k:%M tt', :cls => 'date'},
25
+ {:id => '19', :xl => 'h:mm:ss tt', :ostring => '%-k:%M:%-S tt', :cls => 'date'},
26
+ {:id => '20', :xl => 'H:mm', :ostring => '%-k:%M', :cls => 'date'},
27
+ {:id => '21', :xl => 'H:mm:ss', :ostring => '%-k:%M:%-S', :cls => 'date'},
28
+ {:id => '22', :xl => 'm/d/yyyy H:mm', :ostring => '%-m/%-d/%Y %-k:%M', :cls => 'date'},
29
+ {:id => '23', :xl => '', :ostring => nil, :cls => 'string'},
30
+ {:id => '24', :xl => '', :ostring => nil, :cls => 'string'},
31
+ {:id => '25', :xl => '', :ostring => nil, :cls => 'string'},
32
+ {:id => '26', :xl => '', :ostring => nil, :cls => 'string'},
33
+ {:id => '27', :xl => '', :ostring => nil, :cls => 'string'},
34
+ {:id => '28', :xl => '', :ostring => nil, :cls => 'string'},
35
+ {:id => '29', :xl => '', :ostring => nil, :cls => 'string'},
36
+ {:id => '30', :xl => '', :ostring => nil, :cls => 'string'},
37
+ {:id => '31', :xl => '', :ostring => nil, :cls => 'string'},
38
+ {:id => '32', :xl => '', :ostring => nil, :cls => 'string'},
39
+ {:id => '33', :xl => '', :ostring => nil, :cls => 'string'},
40
+ {:id => '34', :xl => '', :ostring => nil, :cls => 'string'},
41
+ {:id => '35', :xl => '', :ostring => nil, :cls => 'string'},
42
+ {:id => '36', :xl => '', :ostring => nil, :cls => 'string'},
43
+ {:id => '37', :xl => '#,##0 ;(#,##0)', :ostring => '%#4d', :cls => 'numeric'},
44
+ {:id => '38', :xl => '#,##0 ;[Red](#,##0)', :ostring => '%#4d', :cls => 'numeric'},
45
+ {:id => '39', :xl => '#,##0.00;(#,##0.00)', :ostring => '%#4.2f', :cls => 'numeric'},
46
+ {:id => '40', :xl => '#,##0.00;[Red](#,##0.00)', :ostring => '%#4.2f', :cls => 'numeric'},
47
+ {:id => '41', :xl => '', :ostring => nil, :cls => 'string'},
48
+ {:id => '42', :xl => '', :ostring => nil, :cls => 'string'},
49
+ {:id => '43', :xl => '', :ostring => nil, :cls => 'string'},
50
+ {:id => '44', :xl => '', :ostring => nil, :cls => 'string'},
51
+ {:id => '45', :xl => 'mm:ss', :ostring => '%M:%-S', :cls => 'date'},
52
+ {:id => '46', :xl => '[h]:mm:ss', :ostring => '%-k:%M:%-S', :cls => 'date'},
53
+ {:id => '47', :xl => 'mmss.0', :ostring => '%M%-S.%1n', :cls => 'date'},
54
+ {:id => '48', :xl => '##0.0E+0', :ostring => '%#3.1E', :cls => 'numeric'},
55
+ {:id => '49', :xl => '@,', :ostring => '@%d', :cls => 'numeric'},
56
+ {:id => '50', :xl => '', :ostring => nil, :cls => 'string'},
57
+ {:id => '51', :xl => '', :ostring => nil, :cls => 'string'},
58
+ {:id => '52', :xl => '', :ostring => nil, :cls => 'string'},
59
+ {:id => '53', :xl => '', :ostring => nil, :cls => 'string'},
60
+ {:id => '54', :xl => '', :ostring => nil, :cls => 'string'},
61
+ {:id => '55', :xl => '', :ostring => nil, :cls => 'string'},
62
+ {:id => '56', :xl => '', :ostring => nil, :cls => 'string'},
63
+ {:id => '57', :xl => '', :ostring => nil, :cls => 'string'},
64
+ {:id => '58', :xl => '', :ostring => nil, :cls => 'string'},
65
+ {:id => '59', :xl => '', :ostring => nil, :cls => 'string'},
66
+ {:id => '60', :xl => '', :ostring => nil, :cls => 'string'},
67
+ {:id => '61', :xl => '', :ostring => nil, :cls => 'string'},
68
+ {:id => '62', :xl => '', :ostring => nil, :cls => 'string'},
69
+ {:id => '63', :xl => '', :ostring => nil, :cls => 'string'},
70
+ {:id => '64', :xl => '', :ostring => nil, :cls => 'string'},
71
+ {:id => '65', :xl => '', :ostring => nil, :cls => 'string'},
72
+ {:id => '66', :xl => '', :ostring => nil, :cls => 'string'},
73
+ {:id => '67', :xl => '', :ostring => nil, :cls => 'string'},
74
+ {:id => '68', :xl => '', :ostring => nil, :cls => 'string'},
75
+ {:id => '69', :xl => '', :ostring => nil, :cls => 'string'},
76
+ {:id => '70', :xl => '', :ostring => nil, :cls => 'string'},
77
+ {:id => '71', :xl => '', :ostring => nil, :cls => 'string'},
78
+ {:id => '72', :xl => '', :ostring => nil, :cls => 'string'},
79
+ {:id => '73', :xl => '', :ostring => nil, :cls => 'string'},
80
+ {:id => '74', :xl => '', :ostring => nil, :cls => 'string'},
81
+ {:id => '75', :xl => '', :ostring => nil, :cls => 'string'},
82
+ {:id => '76', :xl => '', :ostring => nil, :cls => 'string'},
83
+ {:id => '77', :xl => '', :ostring => nil, :cls => 'string'},
84
+ {:id => '78', :xl => '', :ostring => nil, :cls => 'string'},
85
+ {:id => '79', :xl => '', :ostring => nil, :cls => 'string'},
86
+ {:id => '80', :xl => '', :ostring => nil, :cls => 'string'},
87
+ {:id => '81', :xl => '', :ostring => nil, :cls => 'string'},
88
+ {:id => '82', :xl => '', :ostring => nil, :cls => 'string'},
89
+ {:id => '83', :xl => '', :ostring => nil, :cls => 'string'},
90
+ {:id => '84', :xl => '', :ostring => nil, :cls => 'string'},
91
+ {:id => '85', :xl => '', :ostring => nil, :cls => 'string'},
92
+ {:id => '86', :xl => '', :ostring => nil, :cls => 'string'},
93
+ {:id => '87', :xl => '', :ostring => nil, :cls => 'string'},
94
+ {:id => '88', :xl => '', :ostring => nil, :cls => 'string'},
95
+ {:id => '89', :xl => '', :ostring => nil, :cls => 'string'},
96
+ {:id => '90', :xl => '', :ostring => nil, :cls => 'string'},
97
+ {:id => '91', :xl => '', :ostring => nil, :cls => 'string'},
98
+ {:id => '92', :xl => '', :ostring => nil, :cls => 'string'},
99
+ {:id => '93', :xl => '', :ostring => nil, :cls => 'string'},
100
+ {:id => '94', :xl => '', :ostring => nil, :cls => 'string'},
101
+ {:id => '95', :xl => '', :ostring => nil, :cls => 'string'},
102
+ {:id => '96', :xl => '', :ostring => nil, :cls => 'string'},
103
+ {:id => '97', :xl => '', :ostring => nil, :cls => 'string'},
104
+ {:id => '98', :xl => '', :ostring => nil, :cls => 'string'},
105
+ {:id => '99', :xl => '', :ostring => nil, :cls => 'string'},
106
+ {:id => '100', :xl => '', :ostring => nil, :cls => 'string'},
107
+ {:id => '101', :xl => '', :ostring => nil, :cls => 'string'},
108
+ {:id => '102', :xl => '', :ostring => nil, :cls => 'string'},
109
+ {:id => '103', :xl => '', :ostring => nil, :cls => 'string'},
110
+ {:id => '104', :xl => '', :ostring => nil, :cls => 'string'},
111
+ {:id => '105', :xl => '', :ostring => nil, :cls => 'string'},
112
+ {:id => '106', :xl => '', :ostring => nil, :cls => 'string'},
113
+ {:id => '107', :xl => '', :ostring => nil, :cls => 'string'},
114
+ {:id => '108', :xl => '', :ostring => nil, :cls => 'string'},
115
+ {:id => '109', :xl => '', :ostring => nil, :cls => 'string'},
116
+ {:id => '110', :xl => '', :ostring => nil, :cls => 'string'},
117
+ {:id => '111', :xl => '', :ostring => nil, :cls => 'string'},
118
+ {:id => '112', :xl => '', :ostring => nil, :cls => 'string'},
119
+ {:id => '113', :xl => '', :ostring => nil, :cls => 'string'},
120
+ {:id => '114', :xl => '', :ostring => nil, :cls => 'string'},
121
+ {:id => '115', :xl => '', :ostring => nil, :cls => 'string'},
122
+ {:id => '116', :xl => '', :ostring => nil, :cls => 'string'},
123
+ {:id => '117', :xl => '', :ostring => nil, :cls => 'string'},
124
+ {:id => '118', :xl => '', :ostring => nil, :cls => 'string'},
125
+ {:id => '119', :xl => '', :ostring => nil, :cls => 'string'},
126
+ {:id => '120', :xl => '', :ostring => nil, :cls => 'string'},
127
+ {:id => '121', :xl => '', :ostring => nil, :cls => 'string'},
128
+ {:id => '122', :xl => '', :ostring => nil, :cls => 'string'},
129
+ {:id => '123', :xl => '', :ostring => nil, :cls => 'string'},
130
+ {:id => '124', :xl => '', :ostring => nil, :cls => 'string'},
131
+ {:id => '125', :xl => '', :ostring => nil, :cls => 'string'},
132
+ {:id => '126', :xl => '', :ostring => nil, :cls => 'string'},
133
+ {:id => '127', :xl => '', :ostring => nil, :cls => 'string'},
134
+ {:id => '128', :xl => '', :ostring => nil, :cls => 'string'},
135
+ {:id => '129', :xl => '', :ostring => nil, :cls => 'string'},
136
+ {:id => '130', :xl => '', :ostring => nil, :cls => 'string'},
137
+ {:id => '131', :xl => '', :ostring => nil, :cls => 'string'},
138
+ {:id => '132', :xl => '', :ostring => nil, :cls => 'string'},
139
+ {:id => '133', :xl => '', :ostring => nil, :cls => 'string'},
140
+ {:id => '134', :xl => '', :ostring => nil, :cls => 'string'},
141
+ {:id => '135', :xl => '', :ostring => nil, :cls => 'string'},
142
+ {:id => '136', :xl => '', :ostring => nil, :cls => 'string'},
143
+ {:id => '137', :xl => '', :ostring => nil, :cls => 'string'},
144
+ {:id => '138', :xl => '', :ostring => nil, :cls => 'string'},
145
+ {:id => '139', :xl => '', :ostring => nil, :cls => 'string'},
146
+ {:id => '140', :xl => '', :ostring => nil, :cls => 'string'},
147
+ {:id => '141', :xl => '', :ostring => nil, :cls => 'string'},
148
+ {:id => '142', :xl => '', :ostring => nil, :cls => 'string'},
149
+ {:id => '143', :xl => '', :ostring => nil, :cls => 'string'},
150
+ {:id => '144', :xl => '', :ostring => nil, :cls => 'string'},
151
+ {:id => '145', :xl => '', :ostring => nil, :cls => 'string'},
152
+ {:id => '146', :xl => '', :ostring => nil, :cls => 'string'},
153
+ {:id => '147', :xl => '', :ostring => nil, :cls => 'string'},
154
+ {:id => '148', :xl => '', :ostring => nil, :cls => 'string'},
155
+ {:id => '149', :xl => '', :ostring => nil, :cls => 'string'},
156
+ {:id => '150', :xl => '', :ostring => nil, :cls => 'string'},
157
+ {:id => '151', :xl => '', :ostring => nil, :cls => 'string'},
158
+ {:id => '152', :xl => '', :ostring => nil, :cls => 'string'},
159
+ {:id => '153', :xl => '', :ostring => nil, :cls => 'string'},
160
+ {:id => '154', :xl => '', :ostring => nil, :cls => 'string'},
161
+ {:id => '155', :xl => '', :ostring => nil, :cls => 'string'},
162
+ {:id => '156', :xl => '', :ostring => nil, :cls => 'string'},
163
+ {:id => '157', :xl => '', :ostring => nil, :cls => 'string'},
164
+ {:id => '158', :xl => '', :ostring => nil, :cls => 'string'},
165
+ {:id => '159', :xl => '', :ostring => nil, :cls => 'string'},
166
+ {:id => '160', :xl => '', :ostring => nil, :cls => 'string'},
167
+ {:id => '161', :xl => '', :ostring => nil, :cls => 'string'},
168
+ {:id => '162', :xl => '', :ostring => nil, :cls => 'string'},
169
+ {:id => '163', :xl => '', :ostring => nil, :cls => 'string'},
170
+ ]
171
+ end
172
+ end
@@ -0,0 +1,105 @@
1
+ module Oxcelix
2
+ # The Numformats module provides helper methods that either return the Cell object's raw @value as a ruby value
3
+ # (e.g. Numeric, DateTime, String) or formats it according to the excel _numformat_ string (#Cell.numformat).
4
+ module Numformats
5
+ Dtmap = {'hh'=>'%H', 'ii'=>'%M', 'i'=>'%-M', 'H'=>'%-k', 'h'=>'%-k',\
6
+ 'ss'=>'%-S', 's'=>'%S', 'mmmmm'=>'%b', 'mmmm'=>'%B', 'mmm'=>'%b', 'mm'=>'%m', \
7
+ 'm'=>'%-m', 'dddd'=>'%A', 'ddd'=>'%a', 'dd'=>'%d', 'd'=>'%-d', 'yyyy'=>'%Y', \
8
+ 'yy'=>'%y', 'AM/PM'=>'%p', 'A/P'=>'%p', '.0'=>'', 'ss'=>'%-S', 's'=>'%S'}
9
+
10
+ # Convert the temporary format array (the collection of non-default number formatting strings defined in the excel sheet in use)
11
+ # to a series of hashes containing an id, an excel format string, a converted format string and an object class the format is
12
+ # interpreted on.
13
+ def add_custom_formats fmtary
14
+ fmtary.each do |x|
15
+ if x[:formatCode] =~ /[#0%\?]/
16
+ ostring = numeric x[:formatCode]
17
+ if x[:formatCode] =~ /\//
18
+ cls = 'rational'
19
+ else
20
+ cls = 'numeric'
21
+ end
22
+ elsif x[:formatCode].downcase =~ /[dmysh]/
23
+ ostring = datetime x[:formatCode]
24
+ cls = 'date'
25
+ elsif x[:formatCode].downcase == "general"
26
+ ostring = nil
27
+ cls = 'string'
28
+ end
29
+ Formatarray << {:id => x[:numFmtId].to_s, :xl => x[:formatCode].to_s, :ostring => ostring, :cls => cls}
30
+ end
31
+ end
32
+
33
+ # Convert the excel-style number format to a ruby #Kernel::Format string and return that String.
34
+ # The conversion is internally done by regexp'ing 7 groups: prefix, decimals, separator, floats, exponential (E+)
35
+ # and postfix. Rational numbers ar not handled yet.
36
+ # @param [String] val an Excel number format string.
37
+ # @return [String] a rubyish Kernel::Format string.
38
+ def numeric val
39
+ ostring = "%"
40
+ strippedfmt = @numformat.gsub(/\?/, '0').gsub(',','')
41
+ prefix, decimals, sep, floats, expo, postfix=/(^[^\#0e].?)?([\#0]*)?(\.)?([\#0]*)?(e.?)?(.?[^\#0e]$)?/i.match(strippedfmt).captures
42
+ ostring.prepend prefix.to_s
43
+ if !decimals.nil? && decimals.size != 0
44
+ if (eval decimals) == nil
45
+ ostring += "##{decimals.size}"
46
+ elsif (eval decimals) == 0
47
+ ostring += decimals.size.to_s
48
+ end
49
+ else
50
+ ostring += decimals
51
+ end
52
+ ostring += sep.to_s
53
+ if !floats.nil? && floats.size != 0 # expo!!!
54
+ ostring += ((floats.size.to_s) +"f")
55
+ end
56
+ if sep.nil? && floats.nil? || floats.size == 0
57
+ ostring += "d"
58
+ end
59
+ ostring += (expo.to_s + postfix.to_s) #postfix '+' ?
60
+ return ostring
61
+ end
62
+
63
+ # Convert excel-style date formats into ruby DateTime strftime format strings
64
+ # @param [String] val an Excel number format string.
65
+ # @return [String] a DateTime::strftime format string.
66
+ def datetime formatcode
67
+ deminutified = formatcode.downcase.gsub(/(?<hrs>H|h)(?<div>.)m/, '\k<hrs>\k<div>i')
68
+ .gsub(/im/, 'ii')
69
+ .gsub(/m(?<div>.)(?<secs>s)/, 'i\k<div>\k<secs>')
70
+ .gsub(/mi/, 'ii')
71
+ return deminutified.gsub(/[yMmDdHhSsi]*/, Dtmap)
72
+ end
73
+ end
74
+
75
+ # The Numberhelper module implements methods that return the formatted value or the value converted into a Ruby type (DateTime, Numeric, etc)
76
+ module Numberhelper
77
+ include Numformats
78
+ # Get the cell's value and excel format string and return a string, a ruby Numeric or a DateTime object accordingly
79
+ def to_ru
80
+ if !@value.numeric? || Numformats::Formatarray[@numformat.to_i][:xl] == nil || Numformats::Formatarray[@numformat.to_i][:xl].downcase == "general"
81
+ return @value
82
+ end
83
+ if Numformats::Formatarray[@numformat.to_i][:cls] == 'numeric' || Numformats::Formatarray[@numformat.to_i][:cls] == 'rational'
84
+ return eval @value
85
+ elsif Numformats::Formatarray[@numformat.to_i][:cls] == 'date'
86
+ return DateTime.new(1899, 12, 30) + (eval @value)
87
+ else
88
+ eval @value rescue @value
89
+ end
90
+ end
91
+
92
+ # Get the cell's value, convert it with to_ru and finally, format it based on the value's type.
93
+ def to_fmt
94
+ begin
95
+ if Numformats::Formatarray[@numformat][:cls] == 'date'
96
+ self.to_ru.strftime(datetime(Numformats::Formatarray[@numformat][:xl])) rescue @value
97
+ elsif Numformats::Formatarray[@numformat.to_i][:cls] == 'numeric' || Numformats::Formatarray[@numformat.to_i][:cls] == 'rational'
98
+ sprintf(numeric(Numformats::Formatarray[@numformat][:xl]), self.to_ru) rescue @value
99
+ else
100
+ return @value
101
+ end
102
+ end
103
+ end
104
+ end
105
+ end
@@ -0,0 +1,49 @@
1
+ require 'ox'
2
+ module Oxcelix
3
+
4
+ # Ox based SAX parser which pushes the number formats (taken from the styles.xml file) to an array
5
+ # The reference taken from the cell's 's' attribute points to an element of the
6
+ # style array, which in turn points to a number format (numFmt) that can be
7
+ # either built-in (@formats) or defined in the styles.xml itself.
8
+ class Styles < ::Ox::Sax
9
+ attr_accessor :styleary, :xmlstack, :temparray
10
+ def initialize
11
+ @temparray=[]
12
+ @styleary=[]
13
+ @xmlstack = []
14
+ @numform={}
15
+ end
16
+
17
+ def nf key, value
18
+ @numform[key]=value
19
+ if @numform.size == 2
20
+ @temparray << @numform
21
+ @numform = {}
22
+ end
23
+ end
24
+
25
+ def numFmtId str
26
+ if @xmlstack[-2] == :cellXfs
27
+ @styleary << str
28
+ elsif @xmlstack[-2] == :numFmts
29
+ nf :numFmtId, str
30
+ end
31
+ end
32
+
33
+ def formatCode str
34
+ nf :formatCode, str
35
+ end
36
+
37
+ def start_element(name)
38
+ @xmlstack << name
39
+ end
40
+
41
+ def end_element(name)
42
+ @xmlstack.pop
43
+ end
44
+
45
+ def attr(name, str)
46
+ self.send name, str if self.respond_to?(name)
47
+ end
48
+ end
49
+ end
@@ -62,8 +62,9 @@ module Oxcelix
62
62
  end
63
63
  end
64
64
 
65
- # String type cell content is parsed here. String interpolation using the
66
- # sharedStrings.xml file is done in the #Sharedstrings class
65
+ # Cell content is parsed here. For cells containing strings, interpolation using the
66
+ # sharedStrings.xml file is done in the #Sharedstrings class.
67
+ # The numformat attribute gets a value here based on the styles variable, to preserve the numeric formatting (thus the type) of values.
67
68
  def text(str)
68
69
  if @xmlstack.last == :c
69
70
  if @cell.type != "shared" && @cell.type != "e" && str.numeric?
data/lib/oxcelix/sheet.rb CHANGED
@@ -25,5 +25,15 @@ module Oxcelix
25
25
  super(i,j[0])
26
26
  end
27
27
  end
28
+
29
+ def to_m(*attrs)
30
+ m=Matrix.build(self.col(0).length, self.row(0).length){nil}
31
+ self.each do |x, row, col|
32
+ if attrs.size == 0 || attrs.nil?
33
+ m[row, col]=x.value
34
+ end
35
+ end
36
+ return m
37
+ end
28
38
  end
29
39
  end
@@ -19,7 +19,10 @@ module Oxcelix
19
19
  class Workbook
20
20
  include Cellhelper
21
21
  include Workbookhelper
22
+ include Numformats
23
+
22
24
  attr_accessor :sheets
25
+
23
26
  ##
24
27
  # Create a new {Workbook} object.
25
28
  #
@@ -31,6 +34,8 @@ module Oxcelix
31
34
  # the group of three merged cells <tt>| a |</tt> will become <tt>|a|a|a|</tt>
32
35
  # * :include (Ary) - an array of sheet names to be included
33
36
  # * :exclude (Ary) - an array of sheet names not to be processed
37
+ # * :values (Symbol) - cell values. This can be: :false, if the whole cell is needed, :excel, if the raw excel values need to be inserted
38
+ # and :ruby if ruby objects are preferred.
34
39
  #
35
40
  # The excel file is first getting unzipped, then the workbook.xml file gets
36
41
  # processed. This file stores sheet metadata, which will be filtered (by including
@@ -56,10 +61,19 @@ module Oxcelix
56
61
  @sheetbase={}
57
62
  @sharedstrings=[]
58
63
 
59
- f=IO.read(@destination+'/xl/workbook.xml')
64
+ f=IO.read(@destination + '/xl/workbook.xml')
60
65
  @a=Ox::load(f)
61
66
 
62
67
  sheetdata(options); commentsrel; shstrings;
68
+
69
+ styles = Styles.new()
70
+ File.open(@destination + '/xl/styles.xml', 'r') do |f|
71
+ Ox.sax_parse(styles, f)
72
+ end
73
+
74
+ styles.temparray.sort_by!{|st| st[:numFmtId].to_i}
75
+ add_custom_formats styles.temparray
76
+ styles.styleary.map!{|s| Numformats::Formatarray[s.to_i][:id].to_i}
63
77
 
64
78
  @sheets.each do |x|
65
79
 
@@ -70,6 +84,7 @@ module Oxcelix
70
84
  end
71
85
  comments = mkcomments(x[:comments])
72
86
  @sheet.cellarray.each do |sh|
87
+ sh.numformat = styles.styleary[sh.style.to_i]
73
88
  if sh.type=="s"
74
89
  sh.value = @sharedstrings[sh.value.to_i]
75
90
  end
@@ -85,7 +100,7 @@ module Oxcelix
85
100
  x[:mergedcells] = @sheet.mergedcells
86
101
  end
87
102
  FileUtils.remove_dir(@destination, true)
88
- matrixto(options[:copymerge])
103
+ matrixto options[:copymerge]
89
104
  end
90
105
 
91
106
  private
@@ -196,14 +211,15 @@ module Oxcelix
196
211
  # of each copied cell is changed to reflect the actual Excel coordinate.
197
212
  #
198
213
  # The matrix will replace the array of cells in the actual sheet.
199
- # @param [Bool ] copymerge
214
+ # @param [Bool] copymerge
215
+ # @yield a value to be put as a cell. e.g: matrixto true, { |x| x = x.value.to_ru }
200
216
  # @return [Matrix] a Matrix object that stores the cell values, and, depending on the copymerge parameter, will copy the merged value
201
217
  # into every merged cell
202
218
  def matrixto(copymerge)
203
219
  @sheets.each_with_index do |sheet, i|
204
220
  m=Sheet.build(sheet[:cells].last.y+1, sheet[:cells].last.x+1) {nil}
205
221
  sheet[:cells].each do |c|
206
- m[c.y, c.x]=c
222
+ m[c.y, c.x] = c
207
223
  end
208
224
  if copymerge==true
209
225
  sheet[:mergedcells].each do |mc|
data/lib/oxcelix.rb CHANGED
@@ -4,12 +4,15 @@ require 'matrix'
4
4
  require 'fileutils'
5
5
  require 'zip'
6
6
  require 'oxcelix/cellhelper'
7
+ require 'oxcelix/numformats'
8
+ require 'oxcelix/nf'
7
9
  require 'oxcelix/cell'
8
10
  require 'oxcelix/sheet'
9
11
  require 'oxcelix/workbook'
10
12
  require 'oxcelix/sax/sharedstrings'
11
13
  require 'oxcelix/sax/comments'
12
14
  require 'oxcelix/sax/xlsheet'
15
+ require 'oxcelix/sax/styles'
13
16
 
14
17
  class String
15
18
  # Returns true if the given String represents a numeric value
data/oxcelix.gemspec CHANGED
@@ -3,16 +3,20 @@
3
3
  require 'rake'
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'oxcelix'
6
- s.version = '0.2.4'
7
- s.date = '2013-10-10'
6
+ s.version = '0.3.0'
7
+ s.date = '2013-11-12'
8
8
  s.summary = 'A fast Excel 2007/2010 file parser'
9
- s.description = 'A fast .xlsx file parser that returns a collection of Matrix objects'
9
+ s.description = 'A fast Excel 2007/2010 (.xlsx) file parser that returns a collection of Matrix objects'
10
10
  s.authors = 'Giovanni Biczo'
11
11
  s.homepage = 'http://github.com/gbiczo/oxcelix'
12
12
  s.rubyforge_project = 'oxcelix'
13
13
 
14
14
  s.files = FileList["LICENSE", "README.rdoc", "README.md",
15
- "lib/*", "lib/oxcelix/*", "lib/oxcelix/sax/*",
15
+ "lib/oxcelix.rb", "lib/oxcelix/cellhelper.rb",
16
+ "lib/oxcelix/cell.rb", "lib/oxcelix/numformats.rb",
17
+ "lib/oxcelix/nf.rb",
18
+ "lib/oxcelix/sheet.rb", "lib/oxcelix/workbook.rb",
19
+ "lib/oxcelix/sax/*",
16
20
  "oxcelix.gemspec", "spec/*", ".yardopts", "CHANGES"].to_a
17
21
  s.license = 'MIT'
18
22
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxcelix
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-10-10 00:00:00.000000000 Z
12
+ date: 2013-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ox
@@ -43,7 +43,8 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: 0.9.9
46
- description: A fast .xlsx file parser that returns a collection of Matrix objects
46
+ description: A fast Excel 2007/2010 (.xlsx) file parser that returns a collection
47
+ of Matrix objects
47
48
  email:
48
49
  executables: []
49
50
  extensions: []
@@ -52,14 +53,16 @@ files:
52
53
  - LICENSE
53
54
  - README.rdoc
54
55
  - README.md
55
- - lib/lofaszka.rb
56
56
  - lib/oxcelix.rb
57
+ - lib/oxcelix/cellhelper.rb
57
58
  - lib/oxcelix/cell.rb
58
- - lib/oxcelix/workbook.rb
59
+ - lib/oxcelix/numformats.rb
60
+ - lib/oxcelix/nf.rb
59
61
  - lib/oxcelix/sheet.rb
60
- - lib/oxcelix/cellhelper.rb
62
+ - lib/oxcelix/workbook.rb
61
63
  - lib/oxcelix/sax/sharedstrings.rb
62
64
  - lib/oxcelix/sax/xlsheet.rb
65
+ - lib/oxcelix/sax/styles.rb
63
66
  - lib/oxcelix/sax/comments.rb
64
67
  - oxcelix.gemspec
65
68
  - spec/test.xlsx
data/lib/lofaszka.rb DELETED
@@ -1,6 +0,0 @@
1
- require './oxcelix.rb'
2
- require 'ruby-debug'
3
- debugger
4
- w=Oxcelix::Workbook.new('../Schedules.xlsx', :copymerge=>true)
5
- #w=Oxcelix::Workbook.new('../Schedules.xlsx')
6
- puts "kesz"