summaryrefslogtreecommitdiffhomepage
path: root/examples/image_example.md
blob: f01cfa1b927f6851b66d188b3f2ba0be29d3e211 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
## Description

You could add images. All the options could be added in a do block, so instead of `sheet.add_image(width: 720)` you could say `sheet.add_image { |image| image.width = 720 }`.

## Code

```ruby
require 'axlsx'

p = Axlsx::Package.new
wb = p.workbook

image = File.expand_path('assets/image1.jpeg')

wb.add_worksheet(name: 'Image') do |sheet|
  sheet.add_image(image_src: image, start_at: 'B2', width: 100, height: 100)
  sheet.add_image(image_src: image, start_at: 'E1', end_at: 'G3')
  sheet.add_image(image_src: 'https://via.placeholder.com/150.png', remote: true, start_at: 'E4', end_at: 'G6')
end

p.serialize 'image_example.xlsx'
```

## Output

![Output](images/image_example.png "Output")