Skip to content

Commit b5e42fd

Browse files
authored
Merge pull request #9 from jaakkor2/refactor
Move functions from src/LibXLSXWriter.jl to src/helpers.jl and src/lxw.jl
2 parents ac5d5c4 + 53797f9 commit b5e42fd

File tree

4 files changed

+107
-115
lines changed

4 files changed

+107
-115
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "LibXLSXWriter"
22
uuid = "d9c5391f-cdb8-42e0-9032-91a2542ec5a4"
33
authors = ["Jaakko Ruohio [email protected]"]
4-
version = "0.1.3-DEV"
4+
version = "0.1.3"
55

66
[deps]
77
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"

src/LibXLSXWriter.jl

Lines changed: 2 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -12,113 +12,8 @@ end
1212
string_copy_free = Base.unsafe_string
1313

1414
include("generated/libxlsxwriter_api.jl")
15-
16-
# helpers to create Cstring from String
17-
Cs(mystring) = isempty(mystring) ? C_NULL : Base.unsafe_convert(Cstring, mystring)
18-
Cs_(mystring) = Base.unsafe_convert(Cstring, mystring)
19-
macro Cs_str(str); Base.unsafe_convert(Cstring, str); end
20-
function Cs(list::Vector{String})
21-
ptrs = Base.unsafe_convert.(Cstring, list)
22-
push!(ptrs, C_NULL)
23-
Base.unsafe_convert(Ptr{Cstring}, ptrs)
24-
end
25-
26-
27-
lxw_button_options(; caption="", _macro="", description="", width=LXW_DEF_COL_WIDTH_PIXELS, height=LXW_DEF_ROW_HEIGHT_PIXELS, x_scale=1.0, y_scale=1.0, x_offset=0, y_offset=0) =
28-
Ref(lxw_button_options(Cs(caption), Cs(_macro), Cs(description), width, height, x_scale, y_scale, x_offset, y_offset))
29-
30-
function lxw_chart_data_label(; value="", hide=0x0, font=C_NULL, line=C_NULL, fill=C_NULL, pattern=C_NULL)
31-
Ref(lxw_chart_data_label(
32-
Cs(value),
33-
hide,
34-
Base.unsafe_convert(Ptr{lxw_chart_font}, font),
35-
Base.unsafe_convert(Ptr{lxw_chart_line}, line),
36-
Base.unsafe_convert(Ptr{lxw_chart_fill}, fill),
37-
Base.unsafe_convert(Ptr{lxw_chart_pattern}, pattern)
38-
))
39-
end
40-
41-
lxw_chart_fill(; color=0x0, none=0x0, transparency=0x0) = Ref(lxw_chart_fill(color, none, transparency))
42-
43-
lxw_chart_font(; name="Arial", size=11.0, bold=0x0, italic=0x0, underline=0x0, rotation=0, color=LXW_COLOR_BLACK, pitch_family=0x0, charset=0x0, baseline=0) =
44-
Ref(lxw_chart_font(Cs(name), size, bold, italic, underline, rotation, color, pitch_family, charset, baseline))
45-
46-
lxw_chart_line(; color=0x0, none=0x0, width=0.0, dash_type=0x0, transparency=0x0) = Ref(lxw_chart_line(color, none, width, dash_type, transparency))
47-
48-
lxw_chart_options(; x_offset=0, y_offset=0, x_scale=1.0, y_scale=1.0, object_position=0x0, description="", decorative=0x0) =
49-
Ref(lxw_chart_options(x_offset, y_offset, x_scale, y_scale, object_position, Cs(description), decorative))
50-
51-
lxw_chart_pattern(; fg_color=0x0, bg_color=0x0, type=LXW_PATTERN_NONE) = Ref(lxw_chart_pattern(fg_color, bg_color, type))
52-
53-
function lxw_chart_point(; line=C_NULL, fill=C_NULL, pattern=C_NULL)
54-
Ref(lxw_chart_point(
55-
Base.unsafe_convert(Ptr{lxw_chart_line}, line),
56-
Base.unsafe_convert(Ptr{lxw_chart_fill}, fill),
57-
Base.unsafe_convert(Ptr{lxw_chart_pattern}, pattern)
58-
))
59-
end
60-
61-
lxw_comment_options(; visible=0x0, author="", width=0, height=0, x_scale=1.0, y_scale=1.0, color=LXW_COLOR_UNSET, font_name="", font_size=8, font_family=0x2, start_row=0x0, start_col=0x0, x_offset=15, y_offset=10) =
62-
Ref(lxw_comment_options(visible, Cs(author), width, height, x_scale, y_scale, color, Cs(font_name), font_size, font_family, start_row, start_col, x_offset, y_offset))
63-
64-
lxw_data_validation(; validate=0x0, criteria=0x0, ignore_blank=0x0, show_input=0x0, show_error=0x0, error_type=0x0, dropdown=0x0, value_number=0.0, value_formula="",
65-
value_list=String[], value_datetime=lxw_datetime(), minimum_number=0.0, minimum_formula="", minimum_datetime=lxw_datetime(), maximum_number=0.0,
66-
maximum_formula="", maximum_datetime=lxw_datetime(), input_title="", input_message="", error_title="", error_message="") =
67-
Ref(lxw_data_validation(validate, criteria, ignore_blank, show_input, show_error, error_type, dropdown, value_number, Cs_(value_formula),
68-
Cs(value_list),
69-
value_datetime.x, minimum_number, Cs_(minimum_formula), minimum_datetime.x, maximum_number,
70-
Cs_(maximum_formula), maximum_datetime.x, Cs_(input_title), Cs_(input_message), Cs_(error_title), Cs_(error_message)))
71-
72-
lxw_datetime(; year=0, month=0, day=0, hour=0, min=0, sec=0) = Ref(lxw_datetime(year, month, day, hour, min, sec))
73-
74-
lxw_doc_properties(; title="", subject="", author="", manager="", company="", category="", keywords="", comments="", status="", hyperlink_base="", created=0) =
75-
Ref(lxw_doc_properties(Cs(title), Cs(subject), Cs(author), Cs(manager), Cs(company), Cs(category), Cs(keywords), Cs(comments), Cs(status), Cs(hyperlink_base), created))
76-
77-
lxw_filter_rule(; criteria=0x0, value_string="", value=0.0) = Ref(lxw_filter_rule(criteria, Cs(value_string), value))
78-
79-
lxw_header_footer_options(; margin=0.0, image_left="", image_center="", image_right="") =
80-
Ref(lxw_header_footer_options(margin, Cs(image_left), Cs(image_center), Cs(image_right)))
81-
82-
function lxw_image_options(; x_offset=0, y_offset=0, x_scale=1.0, y_scale=1.0, object_position=0x0, description="", decorative=0x0, url="", tip="", cell_format=C_NULL)
83-
Ref(lxw_image_options(Int32(x_offset), Int32(y_offset), Float64(x_scale), Float64(y_scale), object_position, Cs_(description), decorative, Cs_(url), Cs_(tip),
84-
Base.unsafe_convert(Ptr{lxw_format}, cell_format)
85-
))
86-
end
87-
88-
lxw_rich_string_tuple(; format=C_NULL, string="") =
89-
Ref(lxw_rich_string_tuple(Base.unsafe_convert(Ptr{lxw_format}, format), Cs(string)))
90-
91-
lxw_row_col_options(; hidden=0x0, level=0x0, collapsed=0x0) = Ref(lxw_row_col_options(hidden, level, collapsed))
92-
93-
# utility.h
94-
CELL(cell) = lxw_name_to_row(cell), lxw_name_to_col(cell)
95-
COLS(cols) = lxw_name_to_col(cols), lxw_name_to_col_2(cols)
96-
RANGE(range) = lxw_name_to_row(range), lxw_name_to_col(range), lxw_name_to_row_2(range), lxw_name_to_col_2(range)
97-
98-
# helpers for CELL
99-
worksheet_data_validation_cell(worksheet, cell::Tuple{UInt32, UInt16}, validation) = worksheet_data_validation_cell(worksheet, cell..., validation)
100-
worksheet_embed_image(worksheet, cell::Tuple{UInt32, UInt16}, filename) = worksheet_embed_image(worksheet, cell..., filename)
101-
worksheet_embed_image_buffer(worksheet, cell::Tuple{UInt32, UInt16}, image_buffer, image_size) = worksheet_embed_image_buffer(worksheet, cell..., image_buffer, image_size)
102-
worksheet_insert_chart(worksheet, cell::Tuple{UInt32, UInt16}, chart) = worksheet_insert_chart(worksheet, cell..., chart)
103-
worksheet_insert_chart_opt(worksheet, cell::Tuple{UInt32, UInt16}, chart, options) = worksheet_insert_chart_opt(worksheet, cell..., chart, options)
104-
worksheet_insert_image(worksheet, cell::Tuple{UInt32, UInt16}, filename) = worksheet_insert_image(worksheet, cell..., filename)
105-
worksheet_insert_image_buffer(worksheet, cell::Tuple{UInt32, UInt16}, image_buffer, image_size) = worksheet_insert_image_buffer(worksheet, cell..., image_buffer, image_size)
106-
worksheet_insert_image_buffer_opt(worksheet, cell::Tuple{UInt32, UInt16}, image_buffer, image_size, options) = worksheet_insert_image_buffer_opt(worksheet, cell..., image_buffer, image_size, options)
107-
worksheet_write_comment(worksheet, cell::Tuple{UInt32, UInt16}, string) = worksheet_write_comment(worksheet, cell..., string)
108-
worksheet_write_comment_opt(worksheet, cell::Tuple{UInt32, UInt16}, string, options) = worksheet_write_comment_opt(worksheet, cell..., string, options)
109-
worksheet_write_datetime(worksheet, cell::Tuple{UInt32, UInt16}, datetime, format) = worksheet_write_datetime(worksheet, cell..., datetime, format)
110-
worksheet_write_dynamic_formula(worksheet, cell::Tuple{UInt32, UInt16}, formula, format) = worksheet_write_dynamic_formula(worksheet, cell..., formula, format)
111-
worksheet_write_formula(worksheet, cell::Tuple{UInt32, UInt16}, formula, format) = worksheet_write_formula(worksheet, cell..., formula, format)
112-
worksheet_write_number(worksheet, cell::Tuple{UInt32, UInt16}, number, format) = worksheet_write_number(worksheet, cell..., number, format)
113-
worksheet_write_rich_string(worksheet, cell::Tuple{UInt32, UInt16}, rich_string, format) = worksheet_write_rich_string(worksheet, cell..., rich_string, format)
114-
worksheet_write_string(worksheet, cell::Tuple{UInt32, UInt16}, string, format) = worksheet_write_string(worksheet, cell..., string, format)
115-
worksheet_write_url(worksheet, cell::Tuple{UInt32, UInt16}, url, format) = worksheet_write_url(worksheet, cell..., url, format)
116-
117-
# helper for RANGE
118-
worksheet_write_array_formula(worksheet, range::Tuple{UInt32, UInt16, UInt32, UInt16}, formula, format) = worksheet_write_array_formula(worksheet, range..., formula, format)
119-
120-
# helper for COLS
121-
worksheet_set_column(worksheet, column::Tuple{UInt16, UInt16}, width, format) = worksheet_set_column(worksheet, column..., width, format)
15+
include("helpers.jl")
16+
include("lxw.jl")
12217

12318
#= 1153 identifiers
12419
for n in names(@__MODULE__; all=true)
@@ -128,11 +23,4 @@ for n in names(@__MODULE__; all=true)
12823
end
12924
=#
13025

131-
function debug_list(list)
132-
@ccall libxlsxwriter._validation_list_to_csv(
133-
list::Ptr{Cstring},
134-
)::Cstring
135-
end
136-
137-
13826
end

src/helpers.jl

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# helpers to create Cstring from String
2+
Cs(mystring) = isempty(mystring) ? C_NULL : Base.unsafe_convert(Cstring, mystring)
3+
Cs_(mystring) = Base.unsafe_convert(Cstring, mystring)
4+
macro Cs_str(str); Base.unsafe_convert(Cstring, str); end
5+
function Cs(list::Vector{String})
6+
ptrs = Base.unsafe_convert.(Cstring, list)
7+
push!(ptrs, C_NULL)
8+
Base.unsafe_convert(Ptr{Cstring}, ptrs)
9+
end
10+
11+
# utility.h
12+
CELL(cell) = lxw_name_to_row(cell), lxw_name_to_col(cell)
13+
COLS(cols) = lxw_name_to_col(cols), lxw_name_to_col_2(cols)
14+
RANGE(range) = lxw_name_to_row(range), lxw_name_to_col(range), lxw_name_to_row_2(range), lxw_name_to_col_2(range)
15+
16+
# helpers for CELL
17+
worksheet_data_validation_cell(worksheet, cell::Tuple{UInt32, UInt16}, validation) = worksheet_data_validation_cell(worksheet, cell..., validation)
18+
worksheet_embed_image(worksheet, cell::Tuple{UInt32, UInt16}, filename) = worksheet_embed_image(worksheet, cell..., filename)
19+
worksheet_embed_image_buffer(worksheet, cell::Tuple{UInt32, UInt16}, image_buffer, image_size) = worksheet_embed_image_buffer(worksheet, cell..., image_buffer, image_size)
20+
worksheet_insert_chart(worksheet, cell::Tuple{UInt32, UInt16}, chart) = worksheet_insert_chart(worksheet, cell..., chart)
21+
worksheet_insert_chart_opt(worksheet, cell::Tuple{UInt32, UInt16}, chart, options) = worksheet_insert_chart_opt(worksheet, cell..., chart, options)
22+
worksheet_insert_image(worksheet, cell::Tuple{UInt32, UInt16}, filename) = worksheet_insert_image(worksheet, cell..., filename)
23+
worksheet_insert_image_buffer(worksheet, cell::Tuple{UInt32, UInt16}, image_buffer, image_size) = worksheet_insert_image_buffer(worksheet, cell..., image_buffer, image_size)
24+
worksheet_insert_image_buffer_opt(worksheet, cell::Tuple{UInt32, UInt16}, image_buffer, image_size, options) = worksheet_insert_image_buffer_opt(worksheet, cell..., image_buffer, image_size, options)
25+
worksheet_write_comment(worksheet, cell::Tuple{UInt32, UInt16}, string) = worksheet_write_comment(worksheet, cell..., string)
26+
worksheet_write_comment_opt(worksheet, cell::Tuple{UInt32, UInt16}, string, options) = worksheet_write_comment_opt(worksheet, cell..., string, options)
27+
worksheet_write_datetime(worksheet, cell::Tuple{UInt32, UInt16}, datetime, format) = worksheet_write_datetime(worksheet, cell..., datetime, format)
28+
worksheet_write_dynamic_formula(worksheet, cell::Tuple{UInt32, UInt16}, formula, format) = worksheet_write_dynamic_formula(worksheet, cell..., formula, format)
29+
worksheet_write_formula(worksheet, cell::Tuple{UInt32, UInt16}, formula, format) = worksheet_write_formula(worksheet, cell..., formula, format)
30+
worksheet_write_number(worksheet, cell::Tuple{UInt32, UInt16}, number, format) = worksheet_write_number(worksheet, cell..., number, format)
31+
worksheet_write_rich_string(worksheet, cell::Tuple{UInt32, UInt16}, rich_string, format) = worksheet_write_rich_string(worksheet, cell..., rich_string, format)
32+
worksheet_write_string(worksheet, cell::Tuple{UInt32, UInt16}, string, format) = worksheet_write_string(worksheet, cell..., string, format)
33+
worksheet_write_url(worksheet, cell::Tuple{UInt32, UInt16}, url, format) = worksheet_write_url(worksheet, cell..., url, format)
34+
35+
# helper for RANGE
36+
worksheet_write_array_formula(worksheet, range::Tuple{UInt32, UInt16, UInt32, UInt16}, formula, format) = worksheet_write_array_formula(worksheet, range..., formula, format)
37+
38+
# helper for COLS
39+
worksheet_set_column(worksheet, column::Tuple{UInt16, UInt16}, width, format) = worksheet_set_column(worksheet, column..., width, format)

src/lxw.jl

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
lxw_button_options(; caption="", _macro="", description="", width=LXW_DEF_COL_WIDTH_PIXELS, height=LXW_DEF_ROW_HEIGHT_PIXELS, x_scale=1.0, y_scale=1.0, x_offset=0, y_offset=0) =
2+
Ref(lxw_button_options(Cs(caption), Cs(_macro), Cs(description), width, height, x_scale, y_scale, x_offset, y_offset))
3+
4+
function lxw_chart_data_label(; value="", hide=0x0, font=C_NULL, line=C_NULL, fill=C_NULL, pattern=C_NULL)
5+
Ref(lxw_chart_data_label(
6+
Cs(value),
7+
hide,
8+
Base.unsafe_convert(Ptr{lxw_chart_font}, font),
9+
Base.unsafe_convert(Ptr{lxw_chart_line}, line),
10+
Base.unsafe_convert(Ptr{lxw_chart_fill}, fill),
11+
Base.unsafe_convert(Ptr{lxw_chart_pattern}, pattern)
12+
))
13+
end
14+
15+
lxw_chart_fill(; color=0x0, none=0x0, transparency=0x0) = Ref(lxw_chart_fill(color, none, transparency))
16+
17+
lxw_chart_font(; name="Arial", size=11.0, bold=0x0, italic=0x0, underline=0x0, rotation=0, color=LXW_COLOR_BLACK, pitch_family=0x0, charset=0x0, baseline=0) =
18+
Ref(lxw_chart_font(Cs(name), size, bold, italic, underline, rotation, color, pitch_family, charset, baseline))
19+
20+
lxw_chart_line(; color=0x0, none=0x0, width=0.0, dash_type=0x0, transparency=0x0) = Ref(lxw_chart_line(color, none, width, dash_type, transparency))
21+
22+
lxw_chart_options(; x_offset=0, y_offset=0, x_scale=1.0, y_scale=1.0, object_position=0x0, description="", decorative=0x0) =
23+
Ref(lxw_chart_options(x_offset, y_offset, x_scale, y_scale, object_position, Cs(description), decorative))
24+
25+
lxw_chart_pattern(; fg_color=0x0, bg_color=0x0, type=LXW_PATTERN_NONE) = Ref(lxw_chart_pattern(fg_color, bg_color, type))
26+
27+
function lxw_chart_point(; line=C_NULL, fill=C_NULL, pattern=C_NULL)
28+
Ref(lxw_chart_point(
29+
Base.unsafe_convert(Ptr{lxw_chart_line}, line),
30+
Base.unsafe_convert(Ptr{lxw_chart_fill}, fill),
31+
Base.unsafe_convert(Ptr{lxw_chart_pattern}, pattern)
32+
))
33+
end
34+
35+
lxw_comment_options(; visible=0x0, author="", width=0, height=0, x_scale=1.0, y_scale=1.0, color=LXW_COLOR_UNSET, font_name="", font_size=8, font_family=0x2, start_row=0x0, start_col=0x0, x_offset=15, y_offset=10) =
36+
Ref(lxw_comment_options(visible, Cs(author), width, height, x_scale, y_scale, color, Cs(font_name), font_size, font_family, start_row, start_col, x_offset, y_offset))
37+
38+
lxw_data_validation(; validate=0x0, criteria=0x0, ignore_blank=0x0, show_input=0x0, show_error=0x0, error_type=0x0, dropdown=0x0, value_number=0.0, value_formula="",
39+
value_list=String[], value_datetime=lxw_datetime(), minimum_number=0.0, minimum_formula="", minimum_datetime=lxw_datetime(), maximum_number=0.0,
40+
maximum_formula="", maximum_datetime=lxw_datetime(), input_title="", input_message="", error_title="", error_message="") =
41+
Ref(lxw_data_validation(validate, criteria, ignore_blank, show_input, show_error, error_type, dropdown, value_number, Cs_(value_formula),
42+
Cs(value_list),
43+
value_datetime.x, minimum_number, Cs_(minimum_formula), minimum_datetime.x, maximum_number,
44+
Cs_(maximum_formula), maximum_datetime.x, Cs_(input_title), Cs_(input_message), Cs_(error_title), Cs_(error_message)))
45+
46+
lxw_datetime(; year=0, month=0, day=0, hour=0, min=0, sec=0) = Ref(lxw_datetime(year, month, day, hour, min, sec))
47+
48+
lxw_doc_properties(; title="", subject="", author="", manager="", company="", category="", keywords="", comments="", status="", hyperlink_base="", created=0) =
49+
Ref(lxw_doc_properties(Cs(title), Cs(subject), Cs(author), Cs(manager), Cs(company), Cs(category), Cs(keywords), Cs(comments), Cs(status), Cs(hyperlink_base), created))
50+
51+
lxw_filter_rule(; criteria=0x0, value_string="", value=0.0) = Ref(lxw_filter_rule(criteria, Cs(value_string), value))
52+
53+
lxw_header_footer_options(; margin=0.0, image_left="", image_center="", image_right="") =
54+
Ref(lxw_header_footer_options(margin, Cs(image_left), Cs(image_center), Cs(image_right)))
55+
56+
function lxw_image_options(; x_offset=0, y_offset=0, x_scale=1.0, y_scale=1.0, object_position=0x0, description="", decorative=0x0, url="", tip="", cell_format=C_NULL)
57+
Ref(lxw_image_options(Int32(x_offset), Int32(y_offset), Float64(x_scale), Float64(y_scale), object_position, Cs_(description), decorative, Cs_(url), Cs_(tip),
58+
Base.unsafe_convert(Ptr{lxw_format}, cell_format)
59+
))
60+
end
61+
62+
lxw_rich_string_tuple(; format=C_NULL, string="") =
63+
Ref(lxw_rich_string_tuple(Base.unsafe_convert(Ptr{lxw_format}, format), Cs(string)))
64+
65+
lxw_row_col_options(; hidden=0x0, level=0x0, collapsed=0x0) = Ref(lxw_row_col_options(hidden, level, collapsed))

0 commit comments

Comments
 (0)