Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion docs/src/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,33 @@ XLSX.setBorder(s, "F112,F113"; allsides = ["style" => "thin", "color" => "black"
XLSX.setBorder(s, "B112:B114,D112:D115"; outside = ["style" => "thin", "color" => "black"])

XLSX.writexlsx("myNewTemplate.xlsx", f, overwrite=true)
```
```

## Adding a plot image

Use Julia functionality to create a chart based upon data from a spreadsheet and then add that chart
(as a static image) back into the worksheet.

![image|320x500](./images/Add_image_1.png)

```julia
using CairoMakie, XLSX

f=opentemplate("Example_add_chart.xlsx")
table = XLSX.gettable(f[1])
x = 1:length(table.data[1])

fig = Figure()
ax = Axis(fig[1, 1], xticks=(x, table.data[1]))
barplot!(ax, x, table.data[2])

# Write PNG to IOBuffer
io = IOBuffer()
show(io, MIME("image/png"), fig)

XLSX.addImage(f[1], "D2:H12", io)

XLSX.writexlsx("Example_add_chart_out.xlsx", f, overwrite=true)
```

![image|320x500](./images/Add_image_2.png)
Binary file added docs/src/images/Add_image_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/src/images/Add_image_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions src/images.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,8 @@ Supported formats (auto-detected): PNG, JPEG, GIF.

# Keyword Arguments

- `size`: provide the desired size of the image as a tuple of integers: `(width_px, height_px)`. Actual size
will snap to the nearest actual cell boundaries. If `nothing` (default), the image's native pixel size is used.
Ignored if `ref` is a cell range.
- `size`: provide the desired size of the image as a tuple of integers: `(width_px, height_px)`. If `nothing` (default),
the image's native pixel size is used. Ignored if `ref` is a cell range. Actual size will snap to the nearest cell boundaries.

# Return Value

Expand Down
1 change: 1 addition & 0 deletions src/table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ XLSXFile("blank.xlsx") containing 1 Worksheet

"""
function XLSXFile(table)
Tables.istable(table) || throw(XLSXError("Input must be a Tables.jl compatible table."))
isempty(Tables.rows(table)) && throw(XLSXError("Cannot create XLSXFile from an empty table."))
xf = newxlsx()
writetable!(xf[1], table)
Expand Down
Loading