I'm using python-docx to populate a word template that I have
The problem is that, I want to apply a particular style to a table I have
The table exists already
and I'm just extending it like this:
document = Document(path_to_my_docx)
table = document.tables[0]
row = table.add_row()
row.cells[0].text = "amrouna "
But when I add the row, it outputs this
the row containing amrouna is the row I added
I read in the python docx documentation, that styles won't apply unless they already exist in the document
which is the case here, isn't it ? because my table is already styled before I even load/modify it
Does anyone know how to either:
keep the style from changing when adding a row
Apply the same style to the table once everything is finished
If you replace the text of the cell object, it will override any styling applied to the table/row/cell/etc. What I found out after much struggle w/ something similar, is that you have to replace the text of the run within the paragraph, within the cell.
row.cells[0].paragraphs[0].runs[0].text = "amrouna "
This will preserve the styling from my limited experience... Hopefully it works for you as well.
Related
I have a Word doc in which I'm inserting links to an Excel file. For single Excel cells I can use Paste Special>Paste Link>Unformatted Text to link to just the cell contents. However, sometimes I want to link multiple cells laid out as a table in Word.
If I copy the cell range I want and then use Paste>Link & Use Destination Styles or Paste>Link & Keep Source Formatting, a line break gets inserted above the table, which I do not want but can't get rid of as it's part of the linked field. If I use the unformatted text option, I lose the basic table layout. None of the Paste Special options seem to work for this.
The only workaround I can think of is to link as unformatted text each cell in the table individually, but with sometimes hundreds of cells, that's not really an option. Help! What can I do?
(One reason I am having trouble with the line break above is that I'm trying to use Insert Caption with the tables thus linked, but when I do, the resultant caption gets incorporated into the linked field, and so when I update fields, the caption disappears since it's not in Excel... workarounds for that would help too.)
I am using Microsoft Office Professional Plus 2016.
[EDIT: Example here!]
Word doc:
Linked Excel sheet (Cells A1:C3):
If I highlight some or all of the table and Update Link, the caption disappears:
And when my cursor is at the line break above the table, the table fields highlight as that line break is somehow considered part of the linked field:
I think you just need to add a space before the line break to make sure the caption is not within the linked field. Look at difference between the two example below:
Cursor is now placed just before the line break. The values are highlighted, indicating that the linked field is selected:
Now there's a space between the cursor and the line break. The values are not highlighted, so you can safely insert a captino here:
I am using tabulator 4.8.4. I have tabulator defined with customer sort using sorter function in column. Sorting is applied properly during first load. When i add new row custom sorting is not applied.
table.addData([{
orderNO: order.orderId,
},false]);
It will be either inserted in the top or bottom based on the boolean value passed. I have to call below method to apply sort for newly added row
table.setSort(table.getSorters());
Now the problem is when ever new row added table focus is moving to the top. Its very difficult to navigate rows mean while additional row is coming in. Every time row added foucs is moving to the top. I tried to get the current scroll position before adding new row
scrollVertical:function(top){
position = top;
console.log('position'+top);
}
But i did not find the way to set focus to this position after table redrwan. Please suggest and let me know am i doing anything wrong here
The addRow or addData functions are specifically designed not to re-sort the table when a new row is added as this would be a very jarring experience for the user.
If you need to do this then i suggest that you use the addRow function and then call the scrollTo function on the new row to scroll it into view after the sort is finished
table.addRow({orderNO: order.orderId})
.then((row) => {
table.setSort(table.getSorters());
row.scollTo();
});
I'd like to create a PropertyGrid alike using dgrid (and dojo). As far as I can see, a single column may only contain a single editor type. Is there any workaround to have different editor controls for different cells in the same row?
The Editor mixin seems to create a single cached editor control per row, but maybe there is something I have missed.
Thanks a lot!
There is no mixin available to achieve the functionality that you have described. But, you could do one of the two things.
1) Instead of using editor, you could use the renderCell function in the columns to return different inputs/widgets depending on the column value/row data. In this case you would need handle the events and update the store.
2) If you still want to use editor, there is a workaround. by using dojo/aspect. You would need to listen to the insertRow method of the grid. And update the cell with appropriate widgets for the cell element. Below is the snippet for the same.
aspect.after(grid, "insertRow", lang.hitch(this, 'updateRowWidgets'));
function updateRowWidgets(rowElement){
var cell = grid.cell(rowElement, <columnid>);
var rowdata = cell.row.data;
var rowWidget = .... //Create your widget according to row data.
cell.element.widget = rowWidget;
return rowElement; // remember to return this.
}
Hope this was helpful.
UPDATE: The second option would work only with editOn, as the widget will be shown/added to grid after the editOn event, and you would be able to switch the widget before that happens. Otherwise the widgets would be added to the grid before insertRow is completed.
I have a report I am doing with SSRS 2008 with some rows that have multiple elements inside them. On the preview the row automatically expands to support the extra elements but however when I export the report to Excel it appears only as a single row with just the one element displayed, although all the elements are there when I double click the row or manually expand it.
I've checked everything...Can grow is set to true and the properties on the text box allows it's height to increase however it seems to ignore these.
Here it is in the preview
http://tinypic.com/r/b4wbdg/8
In Excel
http://tinypic.com/r/r084g3/8
Sorry about the links to the pictures and not in this question
Both CanGrow and CanShrink properties should be set to false. There is nothing like CanGrow and CanShrink in Excel. By setting them to false it will display the height as it is. Otherwise it will set the height to a default value.
This worked for me. Check this Row height not preserved when exporting to Excel thread for more suggestions.
Came across this (again) recently and thought I'd share my take...
Whether Excel correctly renders the height has to do with merged columns. Take note of your column alignments throughout all objects on the page. Any objects not tied to the data table itself (or embedded inside the data table) must be aligned with the columns of the table in question, at least for the cells that need to wrap text. If there is any overlap causing the table columns to be split and the cells of wrapped text to be re-merged, Excel will not recognize the row height by either setting the CanGrow to True or snapping the row to fit within Excel.
In the original post, the user mentioned rows with multiple elements inside of them. It is possible that those elements caused the column to split for the surrounding subtotals or adjacent groups with wrapped text.
Setting the CanGrow to False will simply prevent any automatic sizing of the row height by default for both the web view and Excel export, so I don't know if that's the ideal solution to this problem.
Both CanGrow and CanShrink properties should be set to false
This must be done for all cells in the row of the Tablix!!
Otherwise the data is not properly exported.
reduce the widths of the rows and it fixed my problem
I remove the header of the report, and all works perfectly.
I have other reports and I see now that if I remove the textboxes that are included on the sheet when exporting to excel, then the row heights in excel are sized properly.
I know this is an old question but I've been struggling with it. My issue was that I had a second field in a column where I inserted a placeholder underneath the field in the column. When exporting to Excel I wanted it to be tall enough that the second field would show underneath the main field in the column.
To get it to work for me, I inserted a blank column next to it and made it just wide enough for a single character. Then I click and hit enter several times to force it to be multiple lines. When I export, I have a blank column but otherwise it worked for me.
I have a list box where I am trying to get the datafrom the people view in names.nsf.
The first column of the people view is computed and shows Last Name , First Name.
The code below works fine for my list box values but it does not take into consideration the value in the Filter By Column Value. Basiclly the code below acts like the Filter By Column value property does not exist. I know the Filter by Column value property is working because I replaced a repeat control on the page with a computed field and the repeat control is displaying the value excepected but the list box is displaying values from the first document in the view.
Thoughts I had to fix this are:
Use getAllDocumentsByKey to just search the people view but when I do that I lose the column values and I would need to recompute the value, something that I would like to avoid if possible incase the column formula changes.
Use FTSearch but what I really need to do is search that first column only and I am not aware of search operator that searchs a column only. Is there such a thing?
Another thought would be to somehow use the values of a repeat control, as the values for my list box, but I am guessing that this is not possible. I sort of thinking something with a scope varibale but I have not worked that out yet.
A repeat control works. How can I get my code to loop through the doeuments the same way a repeat control does?
And as a side question, is there anyway to tie a pager to a datasource as oppsed to a repeat control.
BTW What I currently do is to build a list box using a few computed fields and a repeat control but what I really want to do is to use a regular xpages list box control.
Here is the code:
var doc:NotesDocument = view1.getFirstDocument();
while (doc != null && count<10)
{
var tmpDoc:NotesDocument = view1.getNextDocument(doc)
ret.push(doc.getColumnValues()[1]);
doc.recycle();
count++;
doc = tmpDoc;
}
Try to use getAllEntriesByKey. This will give You access to column values (through ColumnValue property of view entry).