Inserting Images In-line into Excel Spreadsheets - image

Is it possible to insert images into an Excel spreadsheet automatically given a link to the image?

Here's how you do it it in Ruby:
The Worksheet object's Shapes collection includes an AddPicture() method that creates a picture from an existing file and returns a Shape object that represents the new picture. The syntax is:
.AddPicture(Filename, LinkToFile, SaveWithDocument, Left, Top, Width, Height)
All seven arguments are required, but this allows you to specify the position and size of the picture in the method call.
The following code inserts an image into the range of cells from C3 to F5 in the active worksheet:
require 'win32ole'
xl = WIN32OLE.connect('Excel.Application')
ws = xl.ActiveSheet
range = ws.Range('C3:F5')
pic = ws.Shapes.AddPicture( {
'FileName' => 'C:\Pictures\Image1.jpg',
'LinkToFile' => false,
'SaveWithDocument' => true,
'Left' => range.Left,
'Top' => range.Top,
'Width' => range.Width,
'Height' => range.Height
} )

Related

Ruby axlsx pie chart title font size

I'm using the axslx ruby gem to create a spreadsheet with a pie chart. For the most part it is very straightforward and I've had no problems with one exception: I can't figure out how to set the font size for the title in the pie chart. I've read through the documentation and examples and found no mention of it. I'm sure I have overlooked it but if anyone knows how to do that, I would appreciate any help.
thanks!
adding code ... sorry, should have provided this initially
issue_sheet.add_chart(Axlsx::Pie3DChart, start_at: 'I3', end_at: 'S32') do |chart|
chart.add_series data: issue_sheet['G3:G7'], labels: issue_sheet['F3:F7'], colors: ['9467BD','D62828','EF7E12','82BBDD','3AA02B']
chart.title = "Distribution by Severity"
chart.d_lbls.show_val = false
chart.d_lbls.show_percent = true
chart.d_lbls.d_lbl_pos = :outEnd
chart.d_lbls.show_leader_lines = true
end
I did notice something interesting but I'm not sure what it means. If I use a cell reference rather than a string for the chart.title, the font size changes.
chart.title = "Distribution by Severity" # this sets the font size to 16
chart.title = issue_chart['F2'] # this sets the font size to 10
You can make use of sz property provided in this link
item_style = s.add_style :b => false, :sz => 9, :font_name => 'courier'
row = sheet.add_row [item.name, item.price], :style => item_style

Ruby/Tk Paned window 'orient' option will not work with horizontal value

Trying to add a Paned window in Ruby/Tk and I'm getting the following error:
C:/Users/user/Ruby193/lib/ruby/1.9.1/tk.rb:3016:in `_invoke': Attempt to change read-only option (RuntimeError)
whenever I add the orient option to my code like this:
p = Tk::Tile::Paned.new(parent) { orient 'horizontal' }
It seems that 'orient' is read-only (and defaults to 'vertical') for some reason? I noticed a ruby/tk tutorial on the web with a Paned window example and it avoided using the orient option, perhaps because they ran into the same error?
If you paste the following tutorial code into a .rb file and run it (no orient option) it works. Add the orient option similar to the above and it fails.
require 'tk'
require 'tkextlib/tile'
$resultsVar = TkVariable.new
root = TkRoot.new
root.title = "Window"
p = Tk::Tile::Paned.new(root)do
height 110
place('height' => 100, 'width' => 200, 'x' => 10, 'y' => 10)
#orient 'horizontal' # <== uncomment this line to see error
end
f1 = TkFrame.new(p) {
relief 'groove'
borderwidth 3
background "red"
padx 30
pady 30
pack('side' => 'left', 'pady' => 100)
}
f2 = TkFrame.new (p){
relief 'groove'
borderwidth 3
background "yellow"
padx 30
pady 30
pack('side' => 'right', 'pady' => 100)
}
p.add f1 #, nil <== had to remove nil option here because this also caused an error
p.add f2 #, nil
Tk.mainloop
Has anyone else been able to get the 'orient' option to work? I need it to be horizontal, not the default vertical value. I tried looking at tk.rb and following the error trace and it seems to indicate a 'method_missing' issue.
I think the problem is that the property 'orient' can be set but can't be changed. You can create a PanedWindow 'horizontal' if you pass the option at creation time. Like
p = Tk::Tile::Paned.new(root, 'orient' => 'horizontal' )
Forget the 'method_missing' call. Is a trick for dinamically creating the properties of the widgets.

How can I add an image to a table cell using the Axlsx gem?

I'm using the Axlsx gem to create an excel file and I'd like to add an image. I am currently able to add an image but it seems to add the image in a way that makes it float on top of other content.
I'd like it to exist within a cell. Is this possible?
It is an old question but we never know.
There is an answer in this post : Adding image to Excel file generated by Axlsx.?
You can specify the cell from which you want to put the image by using image.start_at
sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
image.width = 7
image.height = 6
image.hyperlink.tooltip = "Labeled Link"
image.start_at 2, 2
end
HTH

Adding image to Excel file generated by Axlsx.?

I am using Axlsx for generating Excel file.
I need to add image to the Excel File. I have used this code :
ws.add_image(:image_src => '../something',:noSelect => true, :noMove => true) do |image|
image.width=1000
image.height=200
image.start_at 0,0
end
where 'ws' is the worksheet.
It adds the required image, but i am not able to set the 'width' & 'height' of the image with this code.
Even if i give width=2000 and height=1000, it does not affect the image in Excel file.
Can anybody tell , what i doing wrong.?
This looks correct to me as well, and is inline with the example in the gem.
wb.add_worksheet(:name => "Image with Hyperlink") do |sheet|
img = File.expand_path('../image1.jpeg', __FILE__)
# specifying the :hyperlink option will add a hyper link to your image.
# #note - Numbers does not support this part of the specification.
sheet.add_image(:image_src => img, :noSelect => true, :noMove => true, :hyperlink=>"http://axlsx.blogspot.com") do |image|
image.width = 7
image.height = 6
image.hyperlink.tooltip = "Labeled Link"
image.start_at 2, 2
end
end
There is a possibility that a bug was introduced in the version you are using.
As we discussed on #axlsx, lets try this against master on github and if it does prove to be a bug in the version you are using, I'll push out a new release.
Best,
randym

How to dispaly small images in select element (form API) in drupal 7

I'd like to know how I can display images in select element in Drupal form API.
The following code shows simple select with two options which are in text format: "-34-", "-36-".
$sizes = array_combine(array(34, 36), array("-34-", "-36-"));
$form['editplayer']['clothes_size_female']['clothes'] = array(
'#type' => 'select',
'#default_value' => 34,
'#options' => $sizes,
);
I tried to place path to images but it considers it as a string. $sizes = array_combine(array(34, 36), array("http://localhost/drupal/renderImage.php?user_id=34", "http://localhost/drupal/renderImage.php?user_id=36"));
There is not a well-supported way to do this using stock HTML select box elements. There are solutions to do it with JavaScript though:
http://www.jankoatwarpspeed.com/post/2009/07/28/reinventing-drop-down-with-css-jquery.aspx
You'd have to write a custom Drupal form element though to have it work with the Form API.

Resources