How to use tabletop by python-docx - python-docx

I'm new to python-docx and I want to align both left indent and right indent in one line. But I cannot find an example to show how to do it. Could someone help me?
I want to add one line for company and job title, like "Google Engineer", I want "Google" to be aligned to left indent and "Engineer" to right indent in one line. How can I do this in python-docx by add tabstop in paragraph_format?

yes, you can resolve that exactly by adding tab stops.
If you look at the picture bellow, firstly you'll need to calculate where to a add tab stop. If you want to make Engineer aligned to the right within the same line(paragraph), then you need to calculate endpoint based on page width and left/right margins.
Then once you have that, it's important that you set WD_TAB_ALIGNMENT.RIGHT while adding tab stop, which is going to make sure that content is right-aligned and that it "sticks" to the right side.
Here's example code for your case:
import docx
doc = docx.Document()
p = doc.add_paragraph('Google\tEngineer') # tab will trigger tabstop
sec = doc.sections[0]
# finding end_point for the content
margin_end = docx.shared.Inches(
sec.page_width.inches - (sec.left_margin.inches + sec.right_margin.inches))
tab_stops = p.paragraph_format.tab_stops
# adding new tab stop, to the end point, and making sure that it's `RIGHT` aligned.
tab_stops.add_tab_stop(margin_end, docx.enum.text.WD_TAB_ALIGNMENT.RIGHT)
doc.save("test.docx")

Related

Close tags dropping below highlighted line

I have minimal experience with HTML script so this may all go horribly wrong here.
Alright so I have a very simple yet very time consuming task of taking complete papers and converting them into HTML script. I'm using Sublime Text 3 with Emmet plugin.
Basically,
This is the first header
This is the first paragraph that needs to be tagged
This is the second header
This is the second paragraph that needs to be tagged
So super simple I need to put header tags on the headers and paragraph tags on the paragraphs.
What I have been doing is holding Ctrl and manually highlighting the desired text as it is all rather random. Problem is that takes forever to manually highlight the text like that.
I am aware of other ways to highlight such as Ctrl + L for the line. Problem is my close tags end up under the highlighted line.
Example:
<h2>This is the first header
</h2><p>This is the first paragraph that needs to be tagged
</p>
It's not a big deal but it makes the code harder to go through later and really chaotic.
The same problem persists if I click the corresponding number of the line.
Seeing as I have hundreds of pages to enter and even more headers, paragraphs, and pictures to properly tag; I'm looking for a solution to the tag dropping below the line or a faster method to entering text.
So, is there a fast method for entering text from a word document to Sublime text and quickly get the corresponding tags? e.g. <h2>,<h3>,<p>,<ul>,<li> and so on.
Any help will save my sanity, thanks.
When you select a line with CtrlL, it automatically selects the entire line, and moves the cursor down to the first position on the following line. There are two ways around this. The first is to place the cursor in the first position on the line you want to select, then just hit ShiftEnd and the line will be selected, with the cursor now sitting in the last position on that same line. Alternatively, use CtrlL, then hit Shift← (left arrow) to move the cursor from the first position on the next line to the last position on the selected line. Either way, you can now hit the key combo in Emmet for inserting a tag pair, and you're all set.

ST2 -- split_selection_into_lines -- left side of block

Is it possible to split_selection_into_lines at the left side of the block, instead of the right?
It would be nice to select several lines (in one fell swoop) and then type something that will precede each line. I have been using the command+left-click for the left-hand margin, but it is difficult to know whether each line has actually been selected because each line is vertically aligned (e.g., flush-left) -- it is also time consuming to select each line manually.
A simple way is to just find-replace, and replace a delimiter with "\n [text that precedes this line]"
After selecting "split_selection_into_lines" (ctrl+shift+l), the keyboard shortcut command+left-arrow moves multiple cursors the left side of the highlighted block.
Alternatively, holding down the option(alt) key and holding down the left click on the mouse lets the user select everything within a vertical line that is defined by moving the mouse up or down.
https://tutsplus.com/lesson/multiple-cursors-and-incremental-search/

Separate label from textbox

Is there a way to separate a label from a textbox?
I found that this is supposed to work :
Select the controls
Arrange tab
Remove layout
But the remove layout button is always disabled... Probably cause it's only when you use the tabular or stacked option
Is there any other way to do it, or am I doing something wrong?
Please, don't tell me that I have to copy/paste the label and delete the original one.
Thank you
To move a text box (or any control) independently from its label is to click and drag the control using the large grey box in the top left of the control. This allows you complete freedom of placement between the control and label.
Remove layout only works if you use either tabular or stacked.
Use the square at the top right to move them separately, and select only the label to delete the label.
Just select the one you want to use only, and it can be controlled separately. Also: width, height, top, and left in the properties tab are your friends.
Use remove layout if you can select that little cross.
Use the align buttons to tidy up this mess.
I do not use Access much so I find letting Access create all the labels is quicker, when separating the label from the data I use the following method.
Click the label
Ctrl+C to copy label
Delete to remove label
Ctrl+V to paste label back to form
Drag from top left to roughly the location you want
If you have a column of labels then do the cut/copy/paste/reposition for all of them first, then use the method Fionnuala shows to align all to right.
If the labels are too far to the left or right the use the cursor keys to move.
Again use Fionnuala method to align the rows.
If you find they do not align as expected then Ctrl+Z to step back.
If Remove Layout is not available, select Stacked, which will make Remove Layout available, and then select Remove Layout.
This also keeps things where they are, so less re-aligning afterwards.
I think I've got the right answer. Select the Label and send click "Send to back" on Arrange Tab. Label will be detached. Now move it anywhere as required.

SSRS Border around a group fails at end of page

I would like to put a border around each entire group. I have found an expression online to help with this, but it has one flaw. When the group extends to a new page, the bottom border of the last item, and the top border for the first item on the next page do not appear.
Code for top border
=Iif(Fields!ROWNUM.Value = First(Fields!ROWNUM.Value, "EVENT"),"Solid",nothing)
Code for bottom border.
=Iif(Fields!ROWNUM.Value = Last(Fields!ROWNUM.Value, "EVENT"),"Solid",nothing)
based on the logic of this expression, I can completely understand why it does this, but I want to know if there is any way to solve this. Unfortunately inserting a page break between instances of the group is not an option, some of these groups are large and would leave pages almost entirely blank. I believe that you cannot use the global variable page number outside of the header/footer. Is there a "Page break" variable that i can use to say before or after page break?.
Any ideas would be great! thanks

How to keep List contents on the first page? (SSRS 2005 - PDF Export)

I've got the following report setup:
1. Letterhead (not in the header, since i only want it on the first page)
2. List control with some data
when i export the report to PDF, and the contents of the List are less that one full page - my letterhead is displayed on the first page (the rest of the page is empty) and the List content gets moved to the second page.
if the List grows over 1 page - reports is showing up just fine (Letterhead and portion of the list on the first page - the rest on the second page)
It looks like it tries to keep the list on 1 page as long as its contents fit on the page - but when you add the letterhead to the contents it overflows the page, and the list gets bumped down to the next page.
Is there any way to keep the list on the first page regardless of its size.
Putting the letterhead in the list is my last resort, I'd like to hear some other solutions.
uploaded a sample .rdl to illustrate the problem
got rid of the list for simplicity, the problem seems to be with a textbox wanting to show up on 1 page
p.s. see this question for more details
What is the source of your text? Is it coming from a dataset? If so, Add a paragraph id in it, set your table to group on the paragraph id and show only the group header. In the group, add a bottom padding value of say 5. The table will handle the paragraph breaks for you, and if it grows more the a page it will handle it for you. Make sure that keep together is set to false. The paragraph id will be used to sort the dataset by id ascending.
sorry I didn't notice your comment at the end. The only other thing that i can think of is to shift your list up closer to the header and eliminate all empty space at the end. Also, make sure the KeepTogether option in the list is set to false. This way it will break up your list rather than move it to the next page.
you can put both the letterhead and the list inside a rectangle so they are always grouped together.
Reporting services also tries to keep the relative spaces you have in the designer, so if you list is aligned to the bottom of the page and there is a space form the header; it will keep the space on top and align everything to the bottom of the page.