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
Related
I have just come across Enaml for python GUI programming. I only used PySide2 once before for a simple calculator GUI mockup, so I'm new to both Qt and Enaml. Forgive my ignorance ;)
Essentially, I want to have a regular grid of Field or other elements, with fixed, square sizes. After going over some of the examples, I came up with:
from enaml.layout.api import grid
from enaml.widgets.api import Window, Container, Field
enamldef DigitField(Field):
# The fields will contain a single digit for testing.
mask = 'D'
max_length = 1
# These don't have any effect?
hug_width = 'required'
hug_height = 'required'
enamldef Main(Window):
Container:
constraints = [
grid(
[f11, f12],
[f21, f22],
),
]
DigitField: f11:
text = '1'
DigitField: f12:
text = '1'
DigitField: f21:
text = '1'
DigitField: f22:
text = '1'
But the hug_width and hug_height don't seem to work. I then tried manually setting f11.width == 50, for example, inside the constraints, but the kiwisolver shouts at me about unresolvable constraints. I tried everything I could find from the examples about setting width values, but stuff that works for vbox doesn't seem to play with grid.
Any ideas? Also, if someone has a full app made with Enaml, that is open source, I would love to take a look. The docs are OK but some more advanced examples would be awesome.
Well, I think I have found a way to make it work. hug_width restricts width to the field content plus some default padding (from the Qt toolkit). Instead, using resist_width = 'ignore' I was able to completely remove the padding. The grid can be generated using a manual or an automatic method.
The manual method:
from enaml.layout.api import grid
from enaml.widgets.api import Window, Container, Field
enamldef DigitField(Field):
# The fields will contain a single digit for testing.
mask = 'D'
max_length = 1
resist_width = 'ignore'
resist_height = 'ignore'
enamldef Main(Window):
Container:
constraints = [
grid(
[f11, f12],
[f21, f22],
),
f11.width == f11.height,
f12.width == f12.height,
]
DigitField: f11:
text = '1'
DigitField: f12:
text = '1'
DigitField: f21:
text = '1'
DigitField: f22:
text = '1'
This is too WET and scales horribly, so instead we have...
The factory method:
from itertools import zip_longest
from enaml.core.api import Include
from enaml.layout.api import align, grid, factory
from enaml.widgets.api import Window, Container, Field
enamldef DigitField(Field):
mask = 'D'
max_length = 1
resist_width = 'ignore'
resist_height = 'ignore'
def generate_grid(container, num_cols):
rows = []
widgets = container.visible_widgets()
row_iters = (iter(widgets),) * num_cols
rows = list(zip_longest(*row_iters))
return [grid(*rows), align('width', *widgets)]
enamldef Main(Window):
Container:
Container:
constraints << [factory(generate_grid, 3)]
Include:
objects << [DigitField(text=str(1)) for i in range(9)]
I have nested the Container because there will probably be other things in the main window as well, and Enaml windows require a single master Container.
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.
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
I am trying to change the values of an Excel (actually PowerPoint) chart.
I tried doing this by passing an array but it doesn't seem to work.
Although as mentioned on this page it should work...: http://msdn.microsoft.com/en-us/library/office/ff746833.aspx
So how does my code looks like at the moment:
require 'win32ole'
mspp_app = WIN32OLE.new("Powerpoint.Application")
mspp = mspp_app.Presentations.Open(pathToFile)
slide = mspp.Slides(1)
shapes = slide.shapes
chartshape = shapes(3) #the chart happens to be shape n°3
chart = chartshape.chart
# now get the seriescollection
sc = chart.SeriesCollection
sc3 = sc.Item(3)
values = sc3.values #returns the current values as an array example: [1.0, 1.0, 5.0, 2.0]
# now set the values
sc3.values = [2.0, 2.0, 5.0, 1.0] # returns no error
# see if the values are set
values = sc3.values # returns an empty Array []
Anyone tried this before?
For manipulating the diagram data you have to change the underlying worksheet:
ws = myChart.Chart.ChartData.Workbook.Worksheets(1)
ws.Range("A2").Value = "Coffee"
ws.Range("A3").Value = "Soda"
ws.Range("A4").Value = "Tea"
ws.Range("A5").Value = "Water"
ws.Range("B1").Value = "Amount" # used as label for legend
ws.Range("B2").Value = "1000"
ws.Range("B3").Value = "2500"
ws.Range("B4").Value = "4000"
ws.Range("B5").Value = "3000"
It is important to change the SourceData-Range if dimension has changed. Take care of the different notion known from Excel: "=Tabelle1!A1:B5" instead of "A1:B5".
For english office version change "Tabelle1" to "Sheet1"
myChart.Chart.SetSourceData("=Tabelle1!A1:B5")
myChart.Chart.ChartData.Workbook.Close
Don't forget to close the worksheet afterwards.
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