7
7
render::T
8
8
breaks::Vector{Int}
9
9
colwidths::Vector{Int}
10
+ vertical_gaps::Vector{Int}
10
11
end
11
12
12
13
RegressionTable(header::Vector, body::Matrix, args...; vargs...)
@@ -32,6 +33,8 @@ lines (e.g., `\\midrule` in LaTeX).
32
33
the line number is printed (breaks = [5] will print a break after the 5th line is printed).
33
34
- `colwidths`: A vector of integers, one for each column, indicating the width of the column. Can calculate the widths
34
35
automatically using [`calc_widths`](@ref) and update them with [`update_widths!`](@ref).
36
+ - `vertical_gaps`: A vector of integers, indicating where to put vertical gaps in the table. These are places where two underlined cells
37
+ are not connected. This is necessary for Excel integration.
35
38
36
39
The `RegressionTable` is a subtype of the `AbstractMatrix{String}` type (though this functionality is somewhat experimental).
37
40
Importantly, this implements `getindex` and `setindex!`, which means individual elements of the table can be modified after
@@ -88,18 +91,47 @@ mutable struct RegressionTable{T<:AbstractRenderType} <: AbstractMatrix{String}
88
91
align:: String ,
89
92
breaks= [length (data)],
90
93
colwidths:: Vector{Int} = zeros (Int, length (data[1 ])),
91
- vertical_gaps:: Vector{Int} = Int[]
94
+ vertical_gaps:: Union{Nothing, Vector{Int}} = nothing
92
95
) where {T<: AbstractRenderType }
93
96
if all (colwidths .== 0 )
94
97
colwidths = calc_widths (data)
95
98
end
96
99
update_widths! .(data, Ref (colwidths))
100
+ if vertical_gaps === nothing
101
+ vertical_gaps = find_vertical_gaps (data)
102
+ end
97
103
@assert all (length .(data) .== length (colwidths)) && length (colwidths) == length (align) " Not all the correct length"
98
104
@assert length (data) .>= maximum (breaks) " Breaks must be less than the number of rows"
99
105
new {T} (data,align, T (), breaks, colwidths, vertical_gaps)
100
106
end
101
107
end
102
108
109
+ """
110
+ find_vertical_gaps(data::Vector{DataRow{T}}) where T
111
+
112
+ Finds locations in a vector of `DataRow` objects where there are vertical gaps. A "vertical gap" is a place
113
+ where two underlined cells are not connected. If there is a gap, then there needs to be a space between
114
+ the current column and the next column. This makes it unnecessary to have a final vertical gap since
115
+ the table ends there.
116
+ """
117
+ function find_vertical_gaps (data:: Vector{DataRow{T}} ) where T
118
+ out = Set {Int} ()
119
+ for row in data
120
+ i = 0
121
+ for (j, x) in enumerate (row. data)
122
+ if isa (x, Pair)
123
+ i += length (last (x))
124
+ else
125
+ i += 1
126
+ end
127
+ if row. print_underlines[j] && i < length (row)
128
+ push! (out, i)
129
+ end
130
+ end
131
+ end
132
+ sort (collect (out))
133
+ end
134
+
103
135
Base. size (tab:: RegressionTable ) = (length (data (tab)), length (data (tab)[1 ]))
104
136
Base. size (tab:: RegressionTable , i:: Int ) = size (tab)[i]
105
137
Base. getindex (tab:: RegressionTable , i:: Int , j:: Int ) = data (tab)[i][j]
0 commit comments