xlsx2latex 0.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/readme.txt +51 -0
- data/bin/xlsx2latex.rb +127 -0
- data/examples/example_xlsx2latex.rb +64 -0
- data/lib/xlsx2latex.rb +15 -0
- data/lib/xlsx2latex/excel.rb +147 -0
- data/readme.rdoc +97 -0
- data/unittest/expected/generated_test_default_sheet.tex +9 -0
- data/unittest/expected/generated_test_sheet_data.tex +9 -0
- data/unittest/expected/generated_test_sheet_data_boolean.tex +9 -0
- data/unittest/expected/generated_test_sheet_data_date_format.tex +9 -0
- data/unittest/expected/generated_test_sheet_data_floatformat.tex +9 -0
- data/unittest/expected/generated_test_sheet_data_time_format.tex +9 -0
- data/unittest/expected/generated_test_sheet_format.tex +7 -0
- data/unittest/expected/generated_test_sheet_merged_areas.tex +17 -0
- data/unittest/expected/test_bin_boolean.tex +9 -0
- data/unittest/expected/test_bin_date.tex +9 -0
- data/unittest/expected/test_bin_default.tex +9 -0
- data/unittest/expected/test_bin_float.tex +9 -0
- data/unittest/expected/test_bin_select_sheet.tex +9 -0
- data/unittest/expected/test_bin_with_target.tex +8 -0
- data/unittest/expected/test_default_sheet.tex +10 -0
- data/unittest/expected/test_sheet1.tex +10 -0
- data/unittest/expected/test_sheet1_floatformat.tex +10 -0
- data/unittest/expected/test_sheet2.tex +14 -0
- data/unittest/test_bin.rb +75 -0
- data/unittest/test_generated_xlsx.rb +69 -0
- data/unittest/test_testdata_excel2latex.rb +51 -0
- data/unittest/testdata/generated.xlsx +0 -0
- data/unittest/testdata/make_testdata.rb +130 -0
- data/unittest/testdata/simple.xlsx +0 -0
- data/unittest/testdata/testdata_excel2latex.xlsx +0 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ea49d31ba3f4b764257870012ee60ff738e2d078
|
4
|
+
data.tar.gz: 8beaf03f180091d67940296105c9c9a48e2974f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f8b47ebfe48c09ab6e84418d629d2a084e14950fb2762e75dc799b49fbca3a6ff18a2c0f464fb0fdfa6a9365bafb393f7561a492cafd7d582e7a186f0b2b4521
|
7
|
+
data.tar.gz: 0f579ab3d52d1602783baccb87364edfdbe4d33400c639061605eb940a8724e4b757082130d0932b2495630fa55bc567d393f5d4135559338c86c3088201a712
|
data/bin/readme.txt
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
xlsx2LaTeX
|
2
|
+
===========
|
3
|
+
Convert Excel-sheets into LaTeX-tables.
|
4
|
+
|
5
|
+
You can take the LaTeX-table and continue with your work.
|
6
|
+
|
7
|
+
Some features:
|
8
|
+
* Formats for numbers, booleans, dates and times can be defined.
|
9
|
+
* Selection of datasheet is possible.
|
10
|
+
|
11
|
+
Usage: xlsx2latex.exe excelfile [OPTIONS]
|
12
|
+
|
13
|
+
Options
|
14
|
+
-t, --target TARGET target filename (default STDOUT)
|
15
|
+
-s, --sheet SHEET Source sheet in Excel
|
16
|
+
-f, --float FLOAT Format for floats
|
17
|
+
-d, --date DATE Format for dates
|
18
|
+
--time TIME Format for times
|
19
|
+
--true TRUE Format for true
|
20
|
+
--false FALSE Format for false
|
21
|
+
-h, --help help
|
22
|
+
|
23
|
+
==Examples:
|
24
|
+
Write default data sheet as excel to stdout:
|
25
|
+
xlsx2latex my_excel.xlsx
|
26
|
+
|
27
|
+
Write sheet with name "DATA2" as excel to stdout:
|
28
|
+
xlsx2latex my_excel.xlsx -s DATA2
|
29
|
+
|
30
|
+
No decimals for all floats (numbers):
|
31
|
+
xlsx2latex my_excel.xlsx -f %.0f
|
32
|
+
|
33
|
+
Change data format (e.g. to "1. January 2015"):
|
34
|
+
xlsx2latex my_excel.xlsx -d "%d. %B %Y"
|
35
|
+
|
36
|
+
Change format for boolean values:
|
37
|
+
xlsx2latex my_excel.xlsx --true yes --false no
|
38
|
+
|
39
|
+
Not supported:
|
40
|
+
* xls-files [1]
|
41
|
+
* deep control on text formats [2]
|
42
|
+
* select areas or specific columns for export [3]
|
43
|
+
* column specific formats [3]
|
44
|
+
* Detect number format of Excel and use it for the output [4]
|
45
|
+
|
46
|
+
remarks:
|
47
|
+
[1] maybe possible in future - not tested yet.
|
48
|
+
[2] Not planned in future
|
49
|
+
[3] Not planned yet, but on the todo list.
|
50
|
+
[4] Not realized, but wanted
|
51
|
+
|
data/bin/xlsx2latex.rb
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
#!/usr/bin/env
|
3
|
+
=begin rdoc
|
4
|
+
Gem XLSX2LaTeX: Convert excel-files to LaTeX-tabulars.
|
5
|
+
=end
|
6
|
+
|
7
|
+
require_relative '../lib/xlsx2latex'
|
8
|
+
|
9
|
+
require 'optparse'
|
10
|
+
|
11
|
+
options = {}
|
12
|
+
|
13
|
+
opt_parser = OptionParser.new do |opt|
|
14
|
+
opt.banner = "Usage: %s excelfile [OPTIONS]" % __FILE__
|
15
|
+
opt.separator ""
|
16
|
+
opt.separator "Options"
|
17
|
+
|
18
|
+
opt.on("-t","--target TARGET","target filename (default STDOUT)") do |target|
|
19
|
+
options[:target] = target
|
20
|
+
end
|
21
|
+
|
22
|
+
opt.on("-s","--sheet SHEET","Source sheet in Excel") do |sheet|
|
23
|
+
options[:sheet] = sheet
|
24
|
+
end
|
25
|
+
|
26
|
+
opt.on("-f","--float FLOAT","Format for floats") do |float|
|
27
|
+
options[:float] = float
|
28
|
+
end
|
29
|
+
|
30
|
+
opt.on("-d","--date DATE","Format for dates") do |date|
|
31
|
+
options[:date] = date
|
32
|
+
end
|
33
|
+
|
34
|
+
opt.on("--time TIME","Format for times") do |time|
|
35
|
+
options[:time] = time
|
36
|
+
end
|
37
|
+
|
38
|
+
opt.on("--true TRUE","Format for true") do |vtrue|
|
39
|
+
options[:true] = vtrue
|
40
|
+
end
|
41
|
+
opt.on("--false FALSE", "Format for false") do |vfalse|
|
42
|
+
options[:false] = vfalse
|
43
|
+
end
|
44
|
+
|
45
|
+
=begin
|
46
|
+
Generate missing options
|
47
|
+
|
48
|
+
no_format no_bold no_italics...
|
49
|
+
bool: text, surd...
|
50
|
+
all_sheets
|
51
|
+
|
52
|
+
=end
|
53
|
+
%w{}.each{|missing|
|
54
|
+
puts <<code % [missing[0], missing, missing.upcase, missing, missing, missing, missing]
|
55
|
+
opt.on("-%s","--%s %s","%s") do |%s|
|
56
|
+
options[:%s] = %s
|
57
|
+
end
|
58
|
+
code
|
59
|
+
}
|
60
|
+
|
61
|
+
opt.on("-h","--help","help") do
|
62
|
+
puts opt_parser
|
63
|
+
puts <<examples
|
64
|
+
|
65
|
+
==Examples:
|
66
|
+
Write default data sheet as excel to stdout:
|
67
|
+
xlsx2latex my_excel.xlsx
|
68
|
+
|
69
|
+
Write sheet with name "DATA2" as excel to stdout:
|
70
|
+
xlsx2latex my_excel.xlsx -s DATA2
|
71
|
+
|
72
|
+
No decimals for all floats (numbers):
|
73
|
+
xlsx2latex my_excel.xlsx -f %.0f
|
74
|
+
|
75
|
+
Change data format (e.g. to "1. January 2015"):
|
76
|
+
xlsx2latex my_excel.xlsx -d "%d. %B %Y"
|
77
|
+
|
78
|
+
Change format for boolean values:
|
79
|
+
xlsx2latex my_excel.xlsx --true yes --false no
|
80
|
+
|
81
|
+
examples
|
82
|
+
exit
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
#Quick test
|
87
|
+
if $0 == __FILE__ and File.basename($0) == $0
|
88
|
+
ARGV << '../unittest/testdata/simple.xlsx' #source
|
89
|
+
#~ ARGV << '-t' << 'test.tex'
|
90
|
+
#~ ARGV << '-s' << 'DATA2'
|
91
|
+
#~ ARGV << '-f' << '%09.3f'
|
92
|
+
#~ ARGV << '--true' << 'yes'
|
93
|
+
#~ ARGV << '--false' << 'no'
|
94
|
+
#~ ARGV << '-d' << '%Y'
|
95
|
+
ARGV << '-h'
|
96
|
+
end
|
97
|
+
|
98
|
+
opt_parser.parse!
|
99
|
+
if ! ARGV[0]
|
100
|
+
puts "No Excel file given. Try %s -h for more information" % __FILE__
|
101
|
+
exit 1
|
102
|
+
end
|
103
|
+
if ! File.exist?(ARGV[0])
|
104
|
+
puts "Excel file %s not found" % ARGV[0]
|
105
|
+
exit 2
|
106
|
+
end
|
107
|
+
|
108
|
+
$excel = XLSX2LaTeX::Excel.new(ARGV[0])
|
109
|
+
texcode = $excel.to_latex(
|
110
|
+
sheetname: options[:sheet] || $excel.xlsx.default_sheet,
|
111
|
+
float_format: options[:float] || '%0.2f',
|
112
|
+
date_format: options[:date] || '%Y-%m-%d',
|
113
|
+
time_format: options[:time] || '%Y-%m-%d %H:%M',
|
114
|
+
bool_true: options[:true] || 'X',
|
115
|
+
bool_false: options[:false] || '-',
|
116
|
+
)
|
117
|
+
|
118
|
+
if options[:target]
|
119
|
+
File.open(options[:target], 'w:utf-8'){|f|
|
120
|
+
f << texcode
|
121
|
+
$excel.log.info("Created %s" % options[:target])
|
122
|
+
}
|
123
|
+
else
|
124
|
+
puts texcode
|
125
|
+
end
|
126
|
+
|
127
|
+
__END__
|
@@ -0,0 +1,64 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin rdoc
|
3
|
+
Example for usage of gem xlsx2latex
|
4
|
+
=end
|
5
|
+
$:.unshift('../lib')
|
6
|
+
require 'xlsx2latex'
|
7
|
+
|
8
|
+
require 'docgenerator'
|
9
|
+
require 'rake4latex'
|
10
|
+
|
11
|
+
=begin rdoc
|
12
|
+
|
13
|
+
Insipration:
|
14
|
+
http://softwarerecs.stackexchange.com/questions/2428/program-to-convert-excel-2013-spreadsheets-to-latex-tables
|
15
|
+
|
16
|
+
https://github.com/roo-rb/roo
|
17
|
+
|
18
|
+
Similar:
|
19
|
+
http://www.ctan.org/pkg/excel2latex
|
20
|
+
Excel-Makros to build LaTeX-table.
|
21
|
+
|
22
|
+
excel2latex_Testdaten.xlsx
|
23
|
+
3 sheets
|
24
|
+
* 1: Numbers
|
25
|
+
* 2: Header line
|
26
|
+
* 3: multicol + multirow
|
27
|
+
=end
|
28
|
+
|
29
|
+
file 'test.tex' => __FILE__
|
30
|
+
file 'test.tex' => '../lib/xlsx2latex/excel.rb'
|
31
|
+
file 'test.tex' => "../unittest/testdata/testdata_excel2latex.xlsx" do |tsk|
|
32
|
+
doc = Docgenerator::Document.new(:template => :article_utf8)
|
33
|
+
excel = XLSX2LaTeX::Excel.new("../unittest/testdata/testdata_excel2latex.xlsx", float_format: '%0.0f')
|
34
|
+
puts excel.info
|
35
|
+
doc.body << element(:section,{},'Sheet 1').Cr
|
36
|
+
doc.body << excel.to_latex(sheetname: 'Sheet1')
|
37
|
+
doc.body << element(:section,{},'Sheet2').Cr
|
38
|
+
doc.body << excel.to_latex(sheetname: 'Sheet2')
|
39
|
+
doc.save(tsk.name)
|
40
|
+
end
|
41
|
+
|
42
|
+
file 'test2.tex' => __FILE__
|
43
|
+
file 'test2.tex' => '../lib/xlsx2latex/excel.rb'
|
44
|
+
file 'test2.tex' => "../unittest/testdata/generated.xlsx" do |tsk|
|
45
|
+
|
46
|
+
doc = Docgenerator::Document.new(:template => :article_utf8)
|
47
|
+
doc.add_option('landscape')
|
48
|
+
excel = XLSX2LaTeX::Excel.new("../unittest/testdata/generated.xlsx", float_format: '%0.0f')
|
49
|
+
#~ excel.log.level = Log4r::DEBUG
|
50
|
+
doc.body << element(:section,{},'Data overview').Cr
|
51
|
+
doc.body << excel.to_latex(sheetname: 'DATA')
|
52
|
+
doc.body << element(:section,{},'usage of formats').Cr
|
53
|
+
doc.body << excel.to_latex(sheetname: 'Formats')
|
54
|
+
doc.body << element(:section,{},'Merged Areas').Cr
|
55
|
+
doc.body << excel.to_latex(sheetname: 'Merged Areas')
|
56
|
+
doc.save(tsk.name)
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
#~ task :default => 'test.pdf'
|
61
|
+
task :default => 'test2.pdf'
|
62
|
+
task :default => :clean
|
63
|
+
Rake.application[:default].invoke if __FILE__== $0
|
64
|
+
|
data/lib/xlsx2latex.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin rdoc
|
3
|
+
=end
|
4
|
+
module XLSX2LaTeX
|
5
|
+
=begin rdoc
|
6
|
+
Read an Excel-file (xlsx).
|
7
|
+
|
8
|
+
For conversion rules see #to_latex.
|
9
|
+
|
10
|
+
Limits:
|
11
|
+
* No support of multirow
|
12
|
+
|
13
|
+
Not realized yet:
|
14
|
+
* no lines, border
|
15
|
+
=end
|
16
|
+
class Excel
|
17
|
+
=begin rdoc
|
18
|
+
You can set the default values for the conversion rules in #to_latex.
|
19
|
+
|
20
|
+
call-seq:
|
21
|
+
Excel.new(filename, [options])
|
22
|
+
|
23
|
+
The supported options (with defaults):
|
24
|
+
* float_format: '%0.2f'
|
25
|
+
* date_format: '%Y-%m-%d',
|
26
|
+
* time_format: '%Y-%m-%d %H:%M',
|
27
|
+
* Boolean:
|
28
|
+
* bool_true: 'X',
|
29
|
+
* bool_false: '-',
|
30
|
+
|
31
|
+
=end
|
32
|
+
def initialize(filename,
|
33
|
+
float_format: '%0.2f',
|
34
|
+
date_format: '%Y-%m-%d',
|
35
|
+
time_format: '%Y-%m-%d %H:%M',
|
36
|
+
bool_true: 'X', bool_false: '-',
|
37
|
+
log_outputter: Log4r::StdoutOutputter.new('stdout')
|
38
|
+
)
|
39
|
+
|
40
|
+
@log = Log4r::Logger.new(File.basename(filename))
|
41
|
+
@log.outputters << log_outputter if log_outputter
|
42
|
+
@log.level = Log4r::INFO
|
43
|
+
|
44
|
+
@xlsx = Roo::Excelx.new(filename)
|
45
|
+
@float_format = float_format
|
46
|
+
@date_format = date_format
|
47
|
+
@time_format = time_format
|
48
|
+
@bool_true = bool_true
|
49
|
+
@bool_false = bool_false
|
50
|
+
|
51
|
+
end
|
52
|
+
#Logger.
|
53
|
+
attr_reader :log
|
54
|
+
#The internal Roo::Excelx-instance.
|
55
|
+
attr_reader :xlsx
|
56
|
+
=begin rdoc
|
57
|
+
Call #xlsx.info
|
58
|
+
=end
|
59
|
+
def info; @xlsx.info; end
|
60
|
+
=begin rdoc
|
61
|
+
|
62
|
+
call-seq:
|
63
|
+
#to_latex(options)
|
64
|
+
|
65
|
+
Options are:
|
66
|
+
* sheetname ( #xlsx#default_sheet )
|
67
|
+
* The default from ::new for the conversions can be redefined for each tabular.
|
68
|
+
=end
|
69
|
+
def to_latex(sheetname: @xlsx.default_sheet,
|
70
|
+
float_format: @float_format,
|
71
|
+
date_format: @date_format,
|
72
|
+
time_format: @time_format,
|
73
|
+
bool_true: @bool_true, bool_false: @bool_false,
|
74
|
+
xxx: nil
|
75
|
+
)
|
76
|
+
@xlsx.sheet(sheetname) #set default sheetname
|
77
|
+
sheet = @xlsx.sheet_for(sheetname)
|
78
|
+
@log.info("Convert Sheet %s to LaTeX" % sheetname)
|
79
|
+
|
80
|
+
tex = []
|
81
|
+
max_columns = 1
|
82
|
+
sheet.each_row do |line|
|
83
|
+
lineval = []
|
84
|
+
max_columns = @xlsx.last_column if @xlsx.last_column > max_columns
|
85
|
+
line.each{| cell |
|
86
|
+
@log.debug("%s(%i,%i): %s <%s> %s" % [sheetname,cell.coordinate.column,cell.coordinate.row, cell.type.inspect, cell.value.inspect, cell.inspect]) if @log.debug?
|
87
|
+
|
88
|
+
case cell.type
|
89
|
+
when nil #Overwritten parts in multicol/multirow
|
90
|
+
@log.warn("%s(%i,%i) contains Nil - Ok for multicolumn. Multirow is not supported" % [sheetname,cell.coordinate.column,cell.coordinate.row])
|
91
|
+
case lineval.last
|
92
|
+
when /multicolumn\{(\d+)\}/
|
93
|
+
lineval.last.sub!(/multicolumn\{(\d+)\}/, 'multicolumn{%i}' % [$1.to_i + 1])
|
94
|
+
else #First combined cell
|
95
|
+
lineval << ('\multicolumn{2}{c}{%s}' % lineval.pop)
|
96
|
+
end
|
97
|
+
next
|
98
|
+
when :float
|
99
|
+
value = float_format % cell.value
|
100
|
+
when :string
|
101
|
+
value = cell.value
|
102
|
+
when :formula
|
103
|
+
@log.info("%s(%i,%i): Found formula %s. Take result %s" % [sheetname,cell.coordinate.column,cell.coordinate.row, cell.formula, cell.value])
|
104
|
+
value = cell.value
|
105
|
+
when :boolean
|
106
|
+
value = case cell.value
|
107
|
+
when 'TRUE'; bool_true
|
108
|
+
when 'FALSE'; bool_false
|
109
|
+
else
|
110
|
+
@log.warn("Don't know how to handle boolean %s" % cell.value)
|
111
|
+
cell.value
|
112
|
+
end
|
113
|
+
when :date
|
114
|
+
value = cell.value.strftime(date_format)
|
115
|
+
when :datetime
|
116
|
+
value = cell.value.strftime(time_format)
|
117
|
+
else
|
118
|
+
#~ * :date * :percentage * :time * :datetime.
|
119
|
+
@log.error("%s(%i,%i) Undefined celltype %s -%s" % [sheetname,cell.coordinate.column,cell.coordinate.row,cell.type.inspect, cell.inspect])
|
120
|
+
#~ value = cell.excelx_value
|
121
|
+
value = cell.value
|
122
|
+
end
|
123
|
+
if value.respond_to?(:gsub)
|
124
|
+
value.gsub!('<', '\textless{}')
|
125
|
+
value.gsub!('>', '\textgreater{}')
|
126
|
+
value.gsub!('$', '\$')
|
127
|
+
value.gsub!('&', '\&')
|
128
|
+
value.gsub!('%', '\%')
|
129
|
+
end
|
130
|
+
|
131
|
+
if font = @xlsx.font(cell.coordinate.row,cell.coordinate.column)
|
132
|
+
value = '\textbf{%s}' % value if font.bold?
|
133
|
+
value = '\emph{%s}' % value if font.italic?
|
134
|
+
value = '\underline{%s}' % value if font.underline?
|
135
|
+
end
|
136
|
+
lineval << value
|
137
|
+
}
|
138
|
+
tex << lineval.join(' & ')
|
139
|
+
end
|
140
|
+
[
|
141
|
+
"\\begin{tabular}{%s}" % ('c|'* max_columns),
|
142
|
+
tex.join("\\\\\n"),
|
143
|
+
'\end{tabular}'
|
144
|
+
].join("\n")
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end #XLSX2LaTeX
|
data/readme.rdoc
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
=XLSX2LaTeX
|
2
|
+
Convert excel-files (xlsx) to LaTeX-tabulars.
|
3
|
+
|
4
|
+
Details see XLSX2LaTeX::Excel
|
5
|
+
|
6
|
+
|
7
|
+
==Why?
|
8
|
+
This gem is inpired by a question at
|
9
|
+
stackexchange[http://softwarerecs.stackexchange.com/questions/2428/program-to-convert-excel-2013-spreadsheets-to-latex-tables].
|
10
|
+
My first impression was:
|
11
|
+
It should be easy to write such a converter with ruby.
|
12
|
+
|
13
|
+
This gem is a quick try to solve the problem.
|
14
|
+
It uses roo[https://github.com/roo-rb/roo] to parse an excel and convert
|
15
|
+
the result to LaTeX.
|
16
|
+
|
17
|
+
==How to use
|
18
|
+
There is a command line version for this gem.
|
19
|
+
|
20
|
+
For a help, please use
|
21
|
+
bin/xlsx2latex.rb -h
|
22
|
+
|
23
|
+
output[bin/readme_txt.html]
|
24
|
+
|
25
|
+
|
26
|
+
==Philosophy
|
27
|
+
This gem allows a fast way to convert an Excel-Sheet to a LaTeX-tabular.
|
28
|
+
|
29
|
+
It is not expected, that you get a ready-to-use-result.
|
30
|
+
|
31
|
+
* The column format is 'c' for each column
|
32
|
+
* Text formats are respected if the are defined fo the whole cell.
|
33
|
+
* No gridlines are analyzed. Please set your \hlines yourself.
|
34
|
+
|
35
|
+
==Limitation
|
36
|
+
There are some limitations:
|
37
|
+
|
38
|
+
* Only tabular-like sheets are converted (e.g. no graphics)
|
39
|
+
* \multicolumn: The detection of multicolumns is a kind of guessing.
|
40
|
+
* \multirow: Not supported
|
41
|
+
|
42
|
+
===Format
|
43
|
+
|
44
|
+
* Bold, italic... are only detected if the whole cell is formated.
|
45
|
+
* Gridlines are not analyzed.
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
=Similar tools
|
50
|
+
==excel2latex
|
51
|
+
* http://www.ctan.org/pkg/excel2latex
|
52
|
+
|
53
|
+
Excel-Makros to build LaTeX-table.
|
54
|
+
Works until Excel version 2010
|
55
|
+
|
56
|
+
==maketable
|
57
|
+
* http://www.ctan.org/tex-archive/support/maketable
|
58
|
+
|
59
|
+
MAKETABLE works with copy and paste. You mark your table in the
|
60
|
+
respective Windows program, hit copy, change to MAKETABLE and
|
61
|
+
click the Paste-Button. This pastes your data into a data grid.
|
62
|
+
When you click the TEX-Output-Button, the information in the data
|
63
|
+
grid is converted to the respective tabular structure, which is
|
64
|
+
displayed in a new window. Click the Mark all-Button and the
|
65
|
+
Copy-Button to copy the tabular structure to the clipboard, change
|
66
|
+
to your TeX-editor and paste it in.
|
67
|
+
|
68
|
+
==xl2latex
|
69
|
+
* http://www.ctan.org/tex-archive/support/xl2latex
|
70
|
+
|
71
|
+
Works only with Excel97 (and hopefully above, you never know what Microsoft does)
|
72
|
+
|
73
|
+
Import xl2latex.bas in Visual Basic and save as xl2latex.xls (or any other filename).
|
74
|
+
|
75
|
+
To do so: open a new file or a file with all your macros
|
76
|
+
Extras->Macro->Visual Basic-Editor
|
77
|
+
then in Visual Basic: File->File import
|
78
|
+
close Visual Basic
|
79
|
+
save the file (File->Save As or File->Save, what you want)
|
80
|
+
close the file
|
81
|
+
now you should have a new button "LaTeX export" in your "LaTeX" toolbar
|
82
|
+
|
83
|
+
|
84
|
+
==Online tools
|
85
|
+
===http://www.tablesgenerator.com/
|
86
|
+
With http://www.tablesgenerator.com/ you can create empty templates for LaTeX tables.
|
87
|
+
|
88
|
+
===http://ericwood.org/excel2latex/
|
89
|
+
|
90
|
+
Drag any .xlsx file onto the page to extract data and convert it into a LaTeX table.
|
91
|
+
|
92
|
+
* Javascript
|
93
|
+
* No conversion of special characters
|
94
|
+
* Only default sheet
|
95
|
+
|
96
|
+
=====...
|
97
|
+
|
@@ -0,0 +1,9 @@
|
|
1
|
+
\begin{tabular}{c|c|c|c|c|c|c|c|}
|
2
|
+
\textbf{String} & \textbf{Integer} & \textbf{Formula} & \textbf{Float} & \textbf{String with float value} & \textbf{Boolean (String \textgreater{} 0.5)} & \textbf{Date} & \textbf{Time}\\
|
3
|
+
first & 9.00 & 18.0 & 0.81 & 0.8135804472781414 & X & 2015-01-01 & 2015-01-01 12:00\\
|
4
|
+
second & 6.00 & 12.0 & 0.05 & 0.05436321430643143 & - & 2015-01-02 & 2015-01-02 13:00\\
|
5
|
+
third & 8.00 & 16.0 & 0.93 & 0.9266428241878765 & X & 2015-01-03 & 2015-01-03 14:00\\
|
6
|
+
fourth & 23.00 & 46.0 & 0.31 & 0.305918915735916 & - & 2015-01-04 & 2015-01-04 15:00\\
|
7
|
+
fifth & 18.00 & 36.0 & 0.72 & 0.7199250989537036 & X & 2015-01-05 & 2015-01-05 16:00\\
|
8
|
+
sixth & 24.00 & 48.0 & 0.25 & 0.24989901388011448 & - & 2015-01-06 & 2015-01-06 17:00
|
9
|
+
\end{tabular}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
\begin{tabular}{c|c|c|c|c|c|c|c|}
|
2
|
+
\textbf{String} & \textbf{Integer} & \textbf{Formula} & \textbf{Float} & \textbf{String with float value} & \textbf{Boolean (String \textgreater{} 0.5)} & \textbf{Date} & \textbf{Time}\\
|
3
|
+
first & 9.00 & 18.0 & 0.81 & 0.8135804472781414 & X & 2015-01-01 & 2015-01-01 12:00\\
|
4
|
+
second & 6.00 & 12.0 & 0.05 & 0.05436321430643143 & - & 2015-01-02 & 2015-01-02 13:00\\
|
5
|
+
third & 8.00 & 16.0 & 0.93 & 0.9266428241878765 & X & 2015-01-03 & 2015-01-03 14:00\\
|
6
|
+
fourth & 23.00 & 46.0 & 0.31 & 0.305918915735916 & - & 2015-01-04 & 2015-01-04 15:00\\
|
7
|
+
fifth & 18.00 & 36.0 & 0.72 & 0.7199250989537036 & X & 2015-01-05 & 2015-01-05 16:00\\
|
8
|
+
sixth & 24.00 & 48.0 & 0.25 & 0.24989901388011448 & - & 2015-01-06 & 2015-01-06 17:00
|
9
|
+
\end{tabular}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
\begin{tabular}{c|c|c|c|c|c|c|c|}
|
2
|
+
\textbf{String} & \textbf{Integer} & \textbf{Formula} & \textbf{Float} & \textbf{String with float value} & \textbf{Boolean (String \textgreater{} 0.5)} & \textbf{Date} & \textbf{Time}\\
|
3
|
+
first & 9.00 & 18.0 & 0.81 & 0.8135804472781414 & yes & 2015-01-01 & 2015-01-01 12:00\\
|
4
|
+
second & 6.00 & 12.0 & 0.05 & 0.05436321430643143 & no & 2015-01-02 & 2015-01-02 13:00\\
|
5
|
+
third & 8.00 & 16.0 & 0.93 & 0.9266428241878765 & yes & 2015-01-03 & 2015-01-03 14:00\\
|
6
|
+
fourth & 23.00 & 46.0 & 0.31 & 0.305918915735916 & no & 2015-01-04 & 2015-01-04 15:00\\
|
7
|
+
fifth & 18.00 & 36.0 & 0.72 & 0.7199250989537036 & yes & 2015-01-05 & 2015-01-05 16:00\\
|
8
|
+
sixth & 24.00 & 48.0 & 0.25 & 0.24989901388011448 & no & 2015-01-06 & 2015-01-06 17:00
|
9
|
+
\end{tabular}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
\begin{tabular}{c|c|c|c|c|c|c|c|}
|
2
|
+
\textbf{String} & \textbf{Integer} & \textbf{Formula} & \textbf{Float} & \textbf{String with float value} & \textbf{Boolean (String \textgreater{} 0.5)} & \textbf{Date} & \textbf{Time}\\
|
3
|
+
first & 9.00 & 18.0 & 0.81 & 0.8135804472781414 & X & 01. January 2015 & 2015-01-01 12:00\\
|
4
|
+
second & 6.00 & 12.0 & 0.05 & 0.05436321430643143 & - & 02. January 2015 & 2015-01-02 13:00\\
|
5
|
+
third & 8.00 & 16.0 & 0.93 & 0.9266428241878765 & X & 03. January 2015 & 2015-01-03 14:00\\
|
6
|
+
fourth & 23.00 & 46.0 & 0.31 & 0.305918915735916 & - & 04. January 2015 & 2015-01-04 15:00\\
|
7
|
+
fifth & 18.00 & 36.0 & 0.72 & 0.7199250989537036 & X & 05. January 2015 & 2015-01-05 16:00\\
|
8
|
+
sixth & 24.00 & 48.0 & 0.25 & 0.24989901388011448 & - & 06. January 2015 & 2015-01-06 17:00
|
9
|
+
\end{tabular}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
\begin{tabular}{c|c|c|c|c|c|c|c|}
|
2
|
+
\textbf{String} & \textbf{Integer} & \textbf{Formula} & \textbf{Float} & \textbf{String with float value} & \textbf{Boolean (String \textgreater{} 0.5)} & \textbf{Date} & \textbf{Time}\\
|
3
|
+
first & 9 & 18.0 & 1 & 0.8135804472781414 & X & 2015-01-01 & 2015-01-01 12:00\\
|
4
|
+
second & 6 & 12.0 & 0 & 0.05436321430643143 & - & 2015-01-02 & 2015-01-02 13:00\\
|
5
|
+
third & 8 & 16.0 & 1 & 0.9266428241878765 & X & 2015-01-03 & 2015-01-03 14:00\\
|
6
|
+
fourth & 23 & 46.0 & 0 & 0.305918915735916 & - & 2015-01-04 & 2015-01-04 15:00\\
|
7
|
+
fifth & 18 & 36.0 & 1 & 0.7199250989537036 & X & 2015-01-05 & 2015-01-05 16:00\\
|
8
|
+
sixth & 24 & 48.0 & 0 & 0.24989901388011448 & - & 2015-01-06 & 2015-01-06 17:00
|
9
|
+
\end{tabular}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
\begin{tabular}{c|c|c|c|c|c|c|c|}
|
2
|
+
\textbf{String} & \textbf{Integer} & \textbf{Formula} & \textbf{Float} & \textbf{String with float value} & \textbf{Boolean (String \textgreater{} 0.5)} & \textbf{Date} & \textbf{Time}\\
|
3
|
+
first & 9.00 & 18.0 & 0.81 & 0.8135804472781414 & X & 2015-01-01 & 01. January 2015 12:00\\
|
4
|
+
second & 6.00 & 12.0 & 0.05 & 0.05436321430643143 & - & 2015-01-02 & 02. January 2015 13:00\\
|
5
|
+
third & 8.00 & 16.0 & 0.93 & 0.9266428241878765 & X & 2015-01-03 & 03. January 2015 14:00\\
|
6
|
+
fourth & 23.00 & 46.0 & 0.31 & 0.305918915735916 & - & 2015-01-04 & 04. January 2015 15:00\\
|
7
|
+
fifth & 18.00 & 36.0 & 0.72 & 0.7199250989537036 & X & 2015-01-05 & 05. January 2015 16:00\\
|
8
|
+
sixth & 24.00 & 48.0 & 0.25 & 0.24989901388011448 & - & 2015-01-06 & 06. January 2015 17:00
|
9
|
+
\end{tabular}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
\begin{tabular}{c|c|c|c|c|c|c|c|c|c|c|}
|
2
|
+
A1 & B1 & C1 & D1 & E1 & F1 & G1 & H1 & I1 & J1 & K1\\
|
3
|
+
A2 & \multicolumn{6}{c}{B2} & H2 & I2 & J2 & K2\\
|
4
|
+
A3 & B3 & C3 & D3 & E3 & F3 & G3 & H3 & I3 & J3 & K3\\
|
5
|
+
A4 & B4 & C4 & D4 & E4 & F4 & G4 & H4 & I4 & J4 & K4\\
|
6
|
+
A5 & \multicolumn{2}{c}{B5} & D5 & E5 & F5 & G5 & H5 & I5 & J5 & K5\\
|
7
|
+
A6 & \multicolumn{2}{c}{B6} & D6 & E6 & F6 & G6 & H6 & I6 & J6 & K6\\
|
8
|
+
A7 & \multicolumn{2}{c}{B7} & D7 & E7 & F7 & G7 & H7 & I7 & J7 & K7\\
|
9
|
+
A8 & \multicolumn{2}{c}{B8} & D8 & E8 & F8 & \multicolumn{3}{c}{G8} & J8 & K8\\
|
10
|
+
A9 & \multicolumn{2}{c}{B9} & D9 & E9 & \multicolumn{4}{c}{F9} & J9 & K9\\
|
11
|
+
A10 & \multicolumn{2}{c}{B10} & D10 & E10 & \multicolumn{4}{c}{F10} & J10 & K10\\
|
12
|
+
A11 & B11 & C11 & D11 & E11 & \multicolumn{4}{c}{F11} & J11 & K11\\
|
13
|
+
A12 & B12 & C12 & D12 & E12 & \multicolumn{4}{c}{F12} & J12 & K12\\
|
14
|
+
A13 & B13 & C13 & D13 & E13 & \multicolumn{4}{c}{F13} & J13 & K13\\
|
15
|
+
A14 & B14 & C14 & D14 & E14 & F14 & G14 & H14 & I14 & J14 & K14\\
|
16
|
+
A15 & B15 & C15 & D15 & E15 & F15 & G15 & H15 & I15 & J15 & K15
|
17
|
+
\end{tabular}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
INFO simple.xlsx: Convert Sheet DATA to LaTeX
|
2
|
+
\begin{tabular}{c|c|c|c|c|}
|
3
|
+
first & 9.00 & yes & 0.81 & 2015-01-01\\
|
4
|
+
second & 6.00 & no & 0.05 & 2015-01-01\\
|
5
|
+
third & 8.00 & no & 0.93 & 2015-01-01\\
|
6
|
+
fourth & 23.00 & yes & 0.31 & 2015-01-01\\
|
7
|
+
fifth & 18.00 & no & 0.72 & 2015-01-01\\
|
8
|
+
sixth & 24.00 & no & 0.25 & 2015-01-01
|
9
|
+
\end{tabular}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
INFO simple.xlsx: Convert Sheet DATA to LaTeX
|
2
|
+
\begin{tabular}{c|c|c|c|c|}
|
3
|
+
first & 9.00 & X & 0.81 & 01. January 2015\\
|
4
|
+
second & 6.00 & - & 0.05 & 01. January 2015\\
|
5
|
+
third & 8.00 & - & 0.93 & 01. January 2015\\
|
6
|
+
fourth & 23.00 & X & 0.31 & 01. January 2015\\
|
7
|
+
fifth & 18.00 & - & 0.72 & 01. January 2015\\
|
8
|
+
sixth & 24.00 & - & 0.25 & 01. January 2015
|
9
|
+
\end{tabular}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
INFO simple.xlsx: Convert Sheet DATA to LaTeX
|
2
|
+
\begin{tabular}{c|c|c|c|c|}
|
3
|
+
first & 9.00 & X & 0.81 & 2015-01-01\\
|
4
|
+
second & 6.00 & - & 0.05 & 2015-01-01\\
|
5
|
+
third & 8.00 & - & 0.93 & 2015-01-01\\
|
6
|
+
fourth & 23.00 & X & 0.31 & 2015-01-01\\
|
7
|
+
fifth & 18.00 & - & 0.72 & 2015-01-01\\
|
8
|
+
sixth & 24.00 & - & 0.25 & 2015-01-01
|
9
|
+
\end{tabular}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
INFO simple.xlsx: Convert Sheet DATA to LaTeX
|
2
|
+
\begin{tabular}{c|c|c|c|c|}
|
3
|
+
first & 09.000 & X & 00.814 & 2015-01-01\\
|
4
|
+
second & 06.000 & - & 00.054 & 2015-01-01\\
|
5
|
+
third & 08.000 & - & 00.927 & 2015-01-01\\
|
6
|
+
fourth & 23.000 & X & 00.306 & 2015-01-01\\
|
7
|
+
fifth & 18.000 & - & 00.720 & 2015-01-01\\
|
8
|
+
sixth & 24.000 & - & 00.250 & 2015-01-01
|
9
|
+
\end{tabular}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
\begin{tabular}{c|c|c|c|c|}
|
2
|
+
first & 9.00 & X & 0.81 & 2015-01-01\\
|
3
|
+
second & 6.00 & - & 0.05 & 2015-01-01\\
|
4
|
+
third & 8.00 & - & 0.93 & 2015-01-01\\
|
5
|
+
fourth & 23.00 & X & 0.31 & 2015-01-01\\
|
6
|
+
fifth & 18.00 & - & 0.72 & 2015-01-01\\
|
7
|
+
sixth & 24.00 & - & 0.25 & 2015-01-01
|
8
|
+
\end{tabular}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
\begin{tabular}{c|c|c|c|c|c|c|}
|
2
|
+
\textbf{1.00} & \textbf{2.00} & \textbf{3.00} & \textbf{4.00} & \textbf{5.00} & \textbf{6.00} & \textbf{7.00}\\
|
3
|
+
2.00 & 3.00 & 4.00 & 5.00 & 6.00 & 7.00 & 8.00\\
|
4
|
+
3.00 & 4.00 & 5.00 & 6.00 & 7.00 & 8.00 & 9.00\\
|
5
|
+
4.00 & 5.00 & 6.00 & 7.00 & 8.00 & 9.00 & 10.00\\
|
6
|
+
5.00 & 6.00 & 7.00 & 8.00 & 9.00 & 10.00 & 11.00\\
|
7
|
+
6.00 & 7.00 & 8.00 & 9.00 & 10.00 & 11.00 & 12.00\\
|
8
|
+
7.00 & 8.00 & 9.00 & 10.00 & 11.00 & 12.00 & 13.00\\
|
9
|
+
8.00 & 9.00 & 10.00 & 11.00 & 12.00 & 13.00 & 14.00
|
10
|
+
\end{tabular}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
\begin{tabular}{c|c|c|c|c|c|c|}
|
2
|
+
\textbf{1.00} & \textbf{2.00} & \textbf{3.00} & \textbf{4.00} & \textbf{5.00} & \textbf{6.00} & \textbf{7.00}\\
|
3
|
+
2.00 & 3.00 & 4.00 & 5.00 & 6.00 & 7.00 & 8.00\\
|
4
|
+
3.00 & 4.00 & 5.00 & 6.00 & 7.00 & 8.00 & 9.00\\
|
5
|
+
4.00 & 5.00 & 6.00 & 7.00 & 8.00 & 9.00 & 10.00\\
|
6
|
+
5.00 & 6.00 & 7.00 & 8.00 & 9.00 & 10.00 & 11.00\\
|
7
|
+
6.00 & 7.00 & 8.00 & 9.00 & 10.00 & 11.00 & 12.00\\
|
8
|
+
7.00 & 8.00 & 9.00 & 10.00 & 11.00 & 12.00 & 13.00\\
|
9
|
+
8.00 & 9.00 & 10.00 & 11.00 & 12.00 & 13.00 & 14.00
|
10
|
+
\end{tabular}
|
@@ -0,0 +1,10 @@
|
|
1
|
+
\begin{tabular}{c|c|c|c|c|c|c|}
|
2
|
+
\textbf{1} & \textbf{2} & \textbf{3} & \textbf{4} & \textbf{5} & \textbf{6} & \textbf{7}\\
|
3
|
+
2 & 3 & 4 & 5 & 6 & 7 & 8\\
|
4
|
+
3 & 4 & 5 & 6 & 7 & 8 & 9\\
|
5
|
+
4 & 5 & 6 & 7 & 8 & 9 & 10\\
|
6
|
+
5 & 6 & 7 & 8 & 9 & 10 & 11\\
|
7
|
+
6 & 7 & 8 & 9 & 10 & 11 & 12\\
|
8
|
+
7 & 8 & 9 & 10 & 11 & 12 & 13\\
|
9
|
+
8 & 9 & 10 & 11 & 12 & 13 & 14
|
10
|
+
\end{tabular}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
\begin{tabular}{c|c|c|c|c|c|c|}
|
2
|
+
1.00 & 2.00 & 3.00 & 4.00 & 5.00 & 6.00 & 7.00\\
|
3
|
+
2.00 & \multicolumn{5}{c}{\textbf{5 columns combined}} & 8.00\\
|
4
|
+
3.00 & 4.00 & 5.00 & 6.00 & 7.00 & 8.00 & 9.00\\
|
5
|
+
4.00 & \multicolumn{3}{c}{\textbf{3 columns and 2 rows}} & 8.00 & 9.00 & 10.00\\
|
6
|
+
\multicolumn{4}{c}{5.00} & 9.00 & 10.00 & 11.00\\
|
7
|
+
6.00 & 7.00 & 8.00 & 9.00 & 10.00 & 11.00 & 12.00\\
|
8
|
+
7.00 & 8.00 & 9.00 & 10.00 & 11.00 & 12.00 & 13.00\\
|
9
|
+
8.00 & 9.00 & 10.00 & 11.00 & 12.00 & 13.00 & 14.00\\
|
10
|
+
Formula: & 1.00 & 2.00 & 3.0\\
|
11
|
+
10.00 & 11.00 & 12.00 & 13.00 & 14.00 & 15.00 & 16.00\\
|
12
|
+
11.00 & 12.00 & 13.00 & 14.00 & 15.00 & 16.00 & 17.00\\
|
13
|
+
12.00 & 13.00 & 14.00 & 15.00 & 16.00 & 17.00 & 18.00
|
14
|
+
\end{tabular}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin rdoc
|
3
|
+
Tests for xlsx2latex-binary.
|
4
|
+
=end
|
5
|
+
gem 'minitest'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'minitest/filecontent'
|
8
|
+
|
9
|
+
$:.unshift('../lib')
|
10
|
+
require 'xlsx2latex'
|
11
|
+
|
12
|
+
class Test_bin < MiniTest::Test
|
13
|
+
def setup
|
14
|
+
#~ @cmd = 'ruby ../bin/xlsx2latex.rb'
|
15
|
+
@cmd = '../bin/xlsx2latex.exe'
|
16
|
+
@src = 'testdata/simple.xlsx'
|
17
|
+
@cmd_src = [@cmd, @src].join(' ')
|
18
|
+
end
|
19
|
+
def test_bin_no_parameter
|
20
|
+
`#{@cmd}`
|
21
|
+
assert_equal(1,$?.exitstatus)
|
22
|
+
end
|
23
|
+
def test_bin_unkown_source
|
24
|
+
`#{@cmd} notexisting.xlsx`
|
25
|
+
assert_equal(2,$?.exitstatus)
|
26
|
+
end
|
27
|
+
#Result is posted on screen
|
28
|
+
#The output contains also the Log-Messages.
|
29
|
+
def test_bin_default
|
30
|
+
output = `#{@cmd_src}`
|
31
|
+
assert_equal(0,$?.exitstatus)
|
32
|
+
assert_equal_filecontent('expected/%s.tex' % __method__, output)
|
33
|
+
end
|
34
|
+
|
35
|
+
#Save result immediate into file
|
36
|
+
def test_bin_with_target
|
37
|
+
filename = 'temporary_testfile_please_delete_%s_%s.tex' % [__method__.hash, __method__]
|
38
|
+
refute(File.exist?(filename), 'Testfile %s already exists' % filename)
|
39
|
+
output = `#{@cmd_src} -t #{filename}`
|
40
|
+
assert_equal(0,$?.exitstatus)
|
41
|
+
assert(File.exist?(filename), "Target file is not created")
|
42
|
+
assert_equal(<<LOG % filename, output)
|
43
|
+
INFO simple.xlsx: Convert Sheet DATA to LaTeX
|
44
|
+
INFO simple.xlsx: Created %s
|
45
|
+
LOG
|
46
|
+
assert_equal_filecontent('expected/%s.tex' % __method__, File.read(filename))
|
47
|
+
File.delete(filename)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_bin_select_sheet
|
51
|
+
output = `#{@cmd_src} -s DATA2`
|
52
|
+
assert_equal(0,$?.exitstatus)
|
53
|
+
assert_equal_filecontent('expected/%s.tex' % __method__, output)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_bin_float
|
57
|
+
output = `#{@cmd_src} -f %06.3f`
|
58
|
+
assert_equal(0,$?.exitstatus)
|
59
|
+
assert_equal_filecontent('expected/%s.tex' % __method__, output)
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_bin_date
|
63
|
+
output = `#{@cmd_src} -d "%d. %B %Y"`
|
64
|
+
assert_equal(0,$?.exitstatus)
|
65
|
+
assert_equal_filecontent('expected/%s.tex' % __method__, output)
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_bin_boolean
|
69
|
+
output = `#{@cmd_src} --true yes --false no`
|
70
|
+
assert_equal(0,$?.exitstatus)
|
71
|
+
assert_equal_filecontent('expected/%s.tex' % __method__, output)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
__END__
|
75
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin rdoc
|
3
|
+
Tests for xlsx2latex
|
4
|
+
=end
|
5
|
+
gem 'minitest'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'minitest/filecontent'
|
8
|
+
|
9
|
+
$:.unshift('../lib')
|
10
|
+
require 'xlsx2latex'
|
11
|
+
|
12
|
+
class Test_generated_xlsx < MiniTest::Test
|
13
|
+
def setup
|
14
|
+
@excel = XLSX2LaTeX::Excel.new("./testdata/generated.xlsx",
|
15
|
+
log_outputter: nil
|
16
|
+
)
|
17
|
+
end
|
18
|
+
def test_info
|
19
|
+
#~ puts @excel.info
|
20
|
+
assert_equal(<<INFO.strip, @excel.info)
|
21
|
+
File: generated.xlsx
|
22
|
+
Number of sheets: 3
|
23
|
+
Sheets: DATA, Merged Areas, Formats
|
24
|
+
Sheet 1:
|
25
|
+
First row: 1
|
26
|
+
Last row: 7
|
27
|
+
First column: A
|
28
|
+
Last column: H
|
29
|
+
Sheet 2:
|
30
|
+
First row: 1
|
31
|
+
Last row: 15
|
32
|
+
First column: A
|
33
|
+
Last column: K
|
34
|
+
Sheet 3:
|
35
|
+
First row: 1
|
36
|
+
Last row: 5
|
37
|
+
First column: A
|
38
|
+
Last column: A
|
39
|
+
INFO
|
40
|
+
end
|
41
|
+
def test_default_sheet
|
42
|
+
assert_equal_filecontent('expected/generated_%s.tex' % __method__, @excel.to_latex())
|
43
|
+
end
|
44
|
+
def test_sheet_data
|
45
|
+
assert_equal_filecontent('expected/generated_%s.tex' % __method__, @excel.to_latex(sheetname: 'DATA'))
|
46
|
+
end
|
47
|
+
def test_sheet_data_floatformat
|
48
|
+
assert_equal_filecontent('expected/generated_%s.tex' % __method__, @excel.to_latex(sheetname: 'DATA', float_format: '%0.0f',))
|
49
|
+
end
|
50
|
+
def test_sheet_data_date_format
|
51
|
+
assert_equal_filecontent('expected/generated_%s.tex' % __method__, @excel.to_latex(sheetname: 'DATA', date_format: '%d. %B %Y',))
|
52
|
+
end
|
53
|
+
def test_sheet_data_time_format
|
54
|
+
assert_equal_filecontent('expected/generated_%s.tex' % __method__, @excel.to_latex(sheetname: 'DATA', time_format: '%d. %B %Y %H:%M',))
|
55
|
+
end
|
56
|
+
def test_sheet_data_boolean
|
57
|
+
assert_equal_filecontent('expected/generated_%s.tex' % __method__, @excel.to_latex(sheetname: 'DATA', bool_true: 'yes', bool_false: 'no'))
|
58
|
+
end
|
59
|
+
def test_sheet_merged_areas
|
60
|
+
assert_equal_filecontent('expected/generated_%s.tex' % __method__, @excel.to_latex(sheetname: 'Merged Areas'))
|
61
|
+
end
|
62
|
+
def test_sheet_format
|
63
|
+
assert_equal_filecontent('expected/generated_%s.tex' % __method__, @excel.to_latex(sheetname: 'Formats'))
|
64
|
+
end
|
65
|
+
end
|
66
|
+
__END__
|
67
|
+
doc.body <<
|
68
|
+
doc.body << excel.to_latex('Sheet2')
|
69
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin rdoc
|
3
|
+
Tests for xlsx2latex
|
4
|
+
=end
|
5
|
+
gem 'minitest'
|
6
|
+
require 'minitest/autorun'
|
7
|
+
require 'minitest/filecontent'
|
8
|
+
|
9
|
+
$:.unshift('../lib')
|
10
|
+
require 'xlsx2latex'
|
11
|
+
|
12
|
+
class Test_xlsx2latex < MiniTest::Test
|
13
|
+
def setup
|
14
|
+
@excel = XLSX2LaTeX::Excel.new("./testdata/testdata_excel2latex.xlsx",
|
15
|
+
log_outputter: nil
|
16
|
+
)
|
17
|
+
end
|
18
|
+
def test_info
|
19
|
+
assert_equal(<<INFO.strip, @excel.info)
|
20
|
+
File: testdata_excel2latex.xlsx
|
21
|
+
Number of sheets: 2
|
22
|
+
Sheets: Sheet1, Sheet2
|
23
|
+
Sheet 1:
|
24
|
+
First row: 1
|
25
|
+
Last row: 8
|
26
|
+
First column: A
|
27
|
+
Last column: G
|
28
|
+
Sheet 2:
|
29
|
+
First row: 1
|
30
|
+
Last row: 12
|
31
|
+
First column: A
|
32
|
+
Last column: G
|
33
|
+
INFO
|
34
|
+
end
|
35
|
+
def test_default_sheet
|
36
|
+
assert_equal_filecontent('expected/%s.tex' % __method__, @excel.to_latex(sheetname: 'Sheet1'))
|
37
|
+
end
|
38
|
+
def test_sheet1
|
39
|
+
assert_equal_filecontent('expected/%s.tex' % __method__, @excel.to_latex(sheetname: 'Sheet1'))
|
40
|
+
end
|
41
|
+
def test_sheet1_floatformat
|
42
|
+
assert_equal_filecontent('expected/%s.tex' % __method__, @excel.to_latex(sheetname: 'Sheet1', float_format: '%0.0f',))
|
43
|
+
end
|
44
|
+
def test_sheet2
|
45
|
+
assert_equal_filecontent('expected/%s.tex' % __method__, @excel.to_latex(sheetname: 'Sheet2'))
|
46
|
+
end
|
47
|
+
end
|
48
|
+
__END__
|
49
|
+
doc.body <<
|
50
|
+
doc.body << excel.to_latex('Sheet2')
|
51
|
+
|
Binary file
|
@@ -0,0 +1,130 @@
|
|
1
|
+
#encoding: utf-8
|
2
|
+
=begin rdoc
|
3
|
+
Make test example.
|
4
|
+
=end
|
5
|
+
WARNING = <<-txt
|
6
|
+
Warning!
|
7
|
+
|
8
|
+
This file creator stores the data in a different way then excel.
|
9
|
+
|
10
|
+
The formula are not evaluated (they will get no value), so you have to
|
11
|
+
open and save the file once with Excel.
|
12
|
+
|
13
|
+
txt
|
14
|
+
|
15
|
+
require 'rake'
|
16
|
+
require 'axlsx'
|
17
|
+
MyRand = Random.new(15) #Make randm number, but repeatable
|
18
|
+
VALUES = %w(first second third fourth fifth sixth)
|
19
|
+
|
20
|
+
file 'generated.xlsx' => [:warning, __FILE__] do |tsk|
|
21
|
+
Axlsx::Package.new do |p|
|
22
|
+
wb = p.workbook
|
23
|
+
wb.styles{|s|
|
24
|
+
bold = s.add_style(:b => true)
|
25
|
+
italic = s.add_style(:i => true)
|
26
|
+
strike = s.add_style(:strike => true)
|
27
|
+
bold_italic = s.add_style(:b => true, :i => true)
|
28
|
+
time = s.add_style(:format_code => "YYYY-MM-DD hh:mm")
|
29
|
+
wb.add_worksheet(:name => "DATA") do |sheet|
|
30
|
+
sheet.add_row(
|
31
|
+
['String', 'Integer', 'Formula', 'Float', 'String with float value', 'Boolean (String > 0.5)', 'Date', 'Time'],
|
32
|
+
:style => bold,
|
33
|
+
)
|
34
|
+
VALUES.each_with_index { |label,i|
|
35
|
+
sheet.add_row(
|
36
|
+
[ #Values
|
37
|
+
label,
|
38
|
+
MyRand.rand(24)+1,
|
39
|
+
"=B%i * 2" % [i+2], #Formula
|
40
|
+
x = MyRand.rand,
|
41
|
+
x,
|
42
|
+
x > 0.5,
|
43
|
+
Date.new(2015,1,1) + i,
|
44
|
+
Time.new(2015,1,1,12) + i*60*60*24 + i*60*60,
|
45
|
+
],
|
46
|
+
:types => [:string, :integer, nil, :float, :string, :boolean, :date, :time],
|
47
|
+
:style => [nil, nil, nil,nil,nil,nil, nil,time],
|
48
|
+
)
|
49
|
+
}
|
50
|
+
#Only for printed sheets
|
51
|
+
#~ wb.add_defined_name("'repeated header'!$1:$1", :local_sheet_id => sheet.index, :name => '_xlnm.Print_Titles')
|
52
|
+
end
|
53
|
+
wb.add_worksheet(:name => "Merged Areas") do |sheet|
|
54
|
+
1.upto(15){|i|
|
55
|
+
sheet.add_row( 'A'.upto('K').map{|char| '%s%i' % [char,i]})
|
56
|
+
}
|
57
|
+
#The data behind stay available.
|
58
|
+
#so roo don't return nil for merged data.
|
59
|
+
#-> The invisible columns must be set to nil.
|
60
|
+
sheet.merge_cells("B2:G2") #merged column -> \multicol
|
61
|
+
sheet["C2:G2"].each{|cell| cell.value = nil } #Delete content of merged cells
|
62
|
+
|
63
|
+
sheet.merge_cells("C4:C10") #merged row -> not supported
|
64
|
+
sheet["C5:C10"].each{|cell| cell.value = nil } #Delete content of merged cells
|
65
|
+
|
66
|
+
sheet.merge_cells("G8:I13")#Block -> not supported/\multicol
|
67
|
+
sheet["H8:I13"].each{|cell| cell.value = nil } #Delete content of merged cells
|
68
|
+
sheet["G9:G13"].each{|cell| cell.value = nil } #Delete content of merged cells
|
69
|
+
end
|
70
|
+
wb.add_worksheet(:name => "Formats") do |sheet|
|
71
|
+
sheet.add_row(['Normal']) #Bold
|
72
|
+
sheet.add_row(['Bold'],:style => bold) #Bold ##this bold is not set correct
|
73
|
+
sheet.add_row(['Italic'],:style => italic)
|
74
|
+
sheet.add_row(['Strike'],:style => strike)
|
75
|
+
sheet.add_row(['Bold+Italic'],:style => bold_italic)
|
76
|
+
|
77
|
+
#This variants store boldin a different way:
|
78
|
+
#~ sheet.add_row(['Bold'],:b => true) #Bold ##this bold is not set correct
|
79
|
+
#~ sheet.add_row(['Italic'],:i => true)
|
80
|
+
#~ sheet.add_row(['Strike'],:strike => true)
|
81
|
+
#~ sheet.add_row(['Bold+Italic'],:b => true,:i => true)
|
82
|
+
end
|
83
|
+
} #styles
|
84
|
+
#~ wb.add_worksheet(:name => "References") do |sheet|
|
85
|
+
#~ sheet.add_row ['Text', 'Reference', 'lookup-formula']
|
86
|
+
#~ VALUES.each_with_index{ |label,i|
|
87
|
+
#~ #Correct example: =SVERWEIS(A1;DATA.A1:DATA.B3;2)
|
88
|
+
#~ #There is a header line -> Offsets by 1
|
89
|
+
#~ vlookup = '=VLOOKUP(A%i,DATA!A2:B%i,2)' % [i+2,VALUES.size+1]
|
90
|
+
#~ sheet.add_row [label, vlookup, "'%s" % vlookup]
|
91
|
+
#~ }
|
92
|
+
#~ end
|
93
|
+
puts "(Re)create %s" % tsk.name
|
94
|
+
p.serialize(tsk.name)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
task :warning do
|
99
|
+
puts WARNING
|
100
|
+
end
|
101
|
+
|
102
|
+
file 'simple.xlsx' => [__FILE__] do |tsk|
|
103
|
+
Axlsx::Package.new do |p|
|
104
|
+
wb = p.workbook
|
105
|
+
wb.add_worksheet(:name => "DATA") do |sheet|
|
106
|
+
VALUES.each_with_index { |label,i|
|
107
|
+
sheet.add_row([label, x = MyRand.rand(24)+1, x.odd?, MyRand.rand, Date.new(2015,1,1)],
|
108
|
+
:types => [:string, :integer, :boolean, :float, :date]
|
109
|
+
)
|
110
|
+
}
|
111
|
+
end
|
112
|
+
wb.add_worksheet(:name => "DATA2") do |sheet|
|
113
|
+
VALUES.reverse.each_with_index { |label,i|
|
114
|
+
sheet.add_row([label, MyRand.rand(24)+1, MyRand.rand],
|
115
|
+
:types => [:string, :integer, :float]
|
116
|
+
)
|
117
|
+
}
|
118
|
+
end
|
119
|
+
puts "(Re)create %s" % tsk.name
|
120
|
+
p.serialize(tsk.name)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
#~ task :default => :warning
|
125
|
+
#~ task :default=> 'generated.xlsx'
|
126
|
+
task :default=> 'simple.xlsx'
|
127
|
+
|
128
|
+
Rake.application[:default].invoke if $0 == __FILE__
|
129
|
+
|
130
|
+
__END__
|
Binary file
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xlsx2latex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0.rc1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Knut Lickert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: roo
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: log4r
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest-filecontent
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: axlsx
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2'
|
69
|
+
description: ''
|
70
|
+
email: knut@lickert.net
|
71
|
+
executables:
|
72
|
+
- xlsx2latex.rb
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files:
|
75
|
+
- readme.rdoc
|
76
|
+
- bin/readme.txt
|
77
|
+
files:
|
78
|
+
- bin/readme.txt
|
79
|
+
- bin/xlsx2latex.rb
|
80
|
+
- examples/example_xlsx2latex.rb
|
81
|
+
- lib/xlsx2latex.rb
|
82
|
+
- lib/xlsx2latex/excel.rb
|
83
|
+
- readme.rdoc
|
84
|
+
- unittest/expected/generated_test_default_sheet.tex
|
85
|
+
- unittest/expected/generated_test_sheet_data.tex
|
86
|
+
- unittest/expected/generated_test_sheet_data_boolean.tex
|
87
|
+
- unittest/expected/generated_test_sheet_data_date_format.tex
|
88
|
+
- unittest/expected/generated_test_sheet_data_floatformat.tex
|
89
|
+
- unittest/expected/generated_test_sheet_data_time_format.tex
|
90
|
+
- unittest/expected/generated_test_sheet_format.tex
|
91
|
+
- unittest/expected/generated_test_sheet_merged_areas.tex
|
92
|
+
- unittest/expected/test_bin_boolean.tex
|
93
|
+
- unittest/expected/test_bin_date.tex
|
94
|
+
- unittest/expected/test_bin_default.tex
|
95
|
+
- unittest/expected/test_bin_float.tex
|
96
|
+
- unittest/expected/test_bin_select_sheet.tex
|
97
|
+
- unittest/expected/test_bin_with_target.tex
|
98
|
+
- unittest/expected/test_default_sheet.tex
|
99
|
+
- unittest/expected/test_sheet1.tex
|
100
|
+
- unittest/expected/test_sheet1_floatformat.tex
|
101
|
+
- unittest/expected/test_sheet2.tex
|
102
|
+
- unittest/test_bin.rb
|
103
|
+
- unittest/test_generated_xlsx.rb
|
104
|
+
- unittest/test_testdata_excel2latex.rb
|
105
|
+
- unittest/testdata/generated.xlsx
|
106
|
+
- unittest/testdata/make_testdata.rb
|
107
|
+
- unittest/testdata/simple.xlsx
|
108
|
+
- unittest/testdata/testdata_excel2latex.xlsx
|
109
|
+
homepage:
|
110
|
+
licenses: []
|
111
|
+
metadata: {}
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options:
|
114
|
+
- "--main"
|
115
|
+
- readme.rdoc
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '0'
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">"
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 1.3.1
|
128
|
+
requirements: []
|
129
|
+
rubyforge_project:
|
130
|
+
rubygems_version: 2.4.5
|
131
|
+
signing_key:
|
132
|
+
specification_version: 4
|
133
|
+
summary: ''
|
134
|
+
test_files:
|
135
|
+
- unittest/test_testdata_excel2latex.rb
|
136
|
+
- unittest/test_generated_xlsx.rb
|
137
|
+
- unittest/test_bin.rb
|
138
|
+
- unittest/testdata/make_testdata.rb
|
139
|
+
- unittest/testdata/generated.xlsx
|
140
|
+
- unittest/testdata/simple.xlsx
|
141
|
+
- unittest/testdata/testdata_excel2latex.xlsx
|
142
|
+
- unittest/expected/generated_test_default_sheet.tex
|
143
|
+
- unittest/expected/generated_test_sheet_data.tex
|
144
|
+
- unittest/expected/generated_test_sheet_data_boolean.tex
|
145
|
+
- unittest/expected/generated_test_sheet_data_date_format.tex
|
146
|
+
- unittest/expected/generated_test_sheet_data_floatformat.tex
|
147
|
+
- unittest/expected/generated_test_sheet_data_time_format.tex
|
148
|
+
- unittest/expected/generated_test_sheet_format.tex
|
149
|
+
- unittest/expected/generated_test_sheet_merged_areas.tex
|
150
|
+
- unittest/expected/test_bin_boolean.tex
|
151
|
+
- unittest/expected/test_bin_date.tex
|
152
|
+
- unittest/expected/test_bin_default.tex
|
153
|
+
- unittest/expected/test_bin_float.tex
|
154
|
+
- unittest/expected/test_bin_select_sheet.tex
|
155
|
+
- unittest/expected/test_bin_with_target.tex
|
156
|
+
- unittest/expected/test_default_sheet.tex
|
157
|
+
- unittest/expected/test_sheet1.tex
|
158
|
+
- unittest/expected/test_sheet1_floatformat.tex
|
159
|
+
- unittest/expected/test_sheet2.tex
|