i am trying to add a table to a presentation using python-pptx with a specific dimensions
i created a slide layout from power-point which contains the table placeholder in the area i want and loaded it using python-pptx.
slide_layout
but regardless of the placeholder dimensions, the table itself after creation is exceeding the placeholder are.
mainly it is dependent on the number of rows as per the documentation "The table's height is determined by the number of rows."
shape_id, name, height = self.shape_id, self.name, Emu(rows * 370840)
i tried to update the placeholder.py file manually and change the row height but the same output appears.
shape_id, name, height = self.shape_id, self.name, Emu(rows * 18429)
the table is insisting on exceeding the placeholder area as per the below image
output
below is my code, any clues ?
from pptx import Presentation
# the presentation including the table placeholder
prs = Presentation('Presentation2.pptx')
slide1 = prs.slides.add_slide(prs.slide_layouts[11])
table_placeholder = slide1.shapes[0]
shape = table_placeholder.insert_table(rows=22,cols=2)
prs.save('test.pptx')
Tables in PowerPoint expand vertically to accommodate new rows; that's just the way they work. You will need to do any resizing yourself, which you may find is a challenging problem. This isn't the same kind of problem when a user is creating a table in the application because they will just make adjustments for fit until it looks best for their purposes.
You'll need to adjust font-size and row-height and perhaps other attributes like column-width etc. based on your application and whatever heuristics you can resolve, perhaps related to the row count and length of text in certain cells and so on.
A table placeholder really just gives a starting position and width.
Related
I have a QGridLayout instance in a window, to which I dynamically add a series of widgets, depending on which values are checked on another QListView instance.
For each checked item in the list, I add a slider and two labels (for value and name), on a row of the layout, in positions 0, 1, 2.
for index in range(self.model.rowCount()):
if self.model.item(index).checkState():
slid = QSlider(Qt.Horizontal)
sl_val_lbl = QLabel("--")
sl_val_lbl.setMaximumWidth(150) #(a)
#sl_val_lbl.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding) #(b)
sl_name_lbl = QLabel(self.model.item(index).text())
#sl_name_lbl.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Expanding)
self.sliders.addWidget(slid,index,0)
slid.setMaximumWidth(200)
self.sliders.addWidget(sl_val_lbl,index,1)
self.sliders.addWidget(sl_name_lbl,index,2)
self.sliders_dict[sl_name_lbl.text()] = (slid,sl_val_lbl,sl_name_lbl)
Now, the issue I have is that some of the values the label takes, are actually pretty long strings.
My first solution was (a), i.e. set a certain size for the label. Of course, this may or may not work depending on the actual size of the text to be rendered, and when said text is only few chars long as in the case with floats, this is not a very clean solution.
I then went on trying (b), i.e. setting the expanding policy of the Qlabel to Expanding. This works fine for the label itself, however it goes to overlap with the next Qlabel in the Layout (column 2), covering its value.
In other words, I was expecting the underlying layout structure to stretch with the contained Widgets, which is not happening.
How to obtain the desired effect of having the size of the column in the layout to follow/adapt to that of the contained widgets?
Is there any way to use react-virtualized's CellMeasurer with a maximum column width which then made the height expand?
For example, I may have an id field in column one of the grid. This would never grow too large, but I want to size it based on the largest value. Then in column two I have a text field that I am not too sure how large it will be. If it turns out that all of my current data set has a small value in column two, I'd like to size based on the largest value. If it happens to have some larger text (over a certain width) I'd like to use that maximum width, and then expand the row's height to accommodate the lines text.
From what I can see in the docs and code, this type of feature isn't supported. If this is the case, I think my best method would be implementing my own CellMeasurer with a slightly more complex _measure function. Does this sound like the proper course of action?
You should be able to do this by adding a style constraint to your rendered cell. CellMeasurer just measures what the browser reports- and CSS controls the browser's max width.
React might freeze the style object too so use spread rather than directly modifying:
style={{
...style,
maxWidth: 300
}}
I am having some tremendous trouble with formatting shipping labels using RDLC. The conundrum entails formatting the HEIGHT of my report so that the report will grow as needed (for detail items), but it will only grow within the remaining space of a 4"x3.33" shipping label (3.33" is the height).
The shipping labels I am creating are grouped on a main grouping (the recipient), with a detail of the items going to the recipient as a list of items. In this case, the "recipient" is a piece of heavy machinery, and the detail is a list of maintenance parts for that particular machine.
The data set consists of rows of data, where each row is a part, and contains the machine's name. I group on the machine's name, and in the detail, the parts are listed. There is no problem in this regard, and I have made similar reports (such as a packing list type of report), with these groupings, with no problems at all.
The problem I am having is that I can't seem to force the size of the table to max out at 3.33" tall. If the label is less than that, the next instance (the next machine) begins printing immediately after, without skipping down to where the next label is on the sheet. If I put in a gap, the gap is repeated for each detail item...
What I need is to know how to "wrap" the entire tablix table, such that it has a MAXIMUM height of 3.33", a MINIMUM height of 3.33", but within those boundaries, the detail list will grow or shrink to display all of the detail items.
I have split the overall report to match the specifications of the labels I am using (standard 4x3.33 shipping labels)
Margins: 0.15625in, 0.15625in, 0.5in, 0.5in
Columns: 2, with a 0.1875in spacer
Total page size: 8.5in x 11in
Here is what I have in the designer (very basic)
And here is what the result of that is...
Note that there is no 2nd column for some reason... and each instance is butted up against each other vertically even though there is a 3.33" "play area" in the designer.
How do I make this thing give me what I need?
I was able to solve the problem by separating the data in to "all those machines that have orders in this orderID", and using that to create a simple list that is defined as 3.33" high for each item. Within that, I had to create a subreport, pass in the parameter of the MachineID, generate the data of all parts for that OrderID under that MachineID, and list them.
This is the final result:
I am developing a crystal report and data is also coming fine but I am unable to format the fields in the same, just like a comment field must be multiline but when I select the "can Grow" in Format object section, the display is vague.
Can Grow with a value zero stands for the display will grow to multiple lines till it is displayed fully.
As the grow can happen multiple lines, you can adjust the width of the item so that it will not overlap with other item.
What should You do:
Set can grow property to zero
Resize the item (for which you set cangrow 0) so that it will not overlap the item of the next column.
We are using infragistics ultragrid to present data to the user. if the user modifies the width of a column, I need to be able to tell if the data is truncated so that I can adjust the output properly when exporting the data into pdf. We want to truncate the data when exporting to other formats to match what the user sees after the column width adjustment.
Thanks,
Currie
Whether the text is cut off or not is done automatically when drawing the string so you would need to get the available space and the string and then determine how much of it fits into the space when drawn.
Within the CellExporting event of the UltraDocumentExporter, you can get the text and the size with the following:
Size size = e.GridRow.GetCellSizeResolved(e.GridColumn);
string text = e.GridRow.GetCellText(e.GridColumn);
You can also change the value that is being exported by setting e.ExportValue to the string that you want to put in the PDF document.
What remains to be done is to determine the amount of characters that fit into the rectangle and the following should help you with that:
How to determine maximum number of characters given a fixed width font and a maximum width in pixels