Python: Is there a way I can add a footnote to word document? - python-2.7

I have tried the following with python-docx:
section = self.document.sections[0]
footer = section._sectPr.footer
footer.text = "I am here"
I couldn't find a clear footer/header directions in docx documentations. Is there a work around to cover this gap?

The work around is:
Create a document with python-docx.
Change the name to 'init.docx'
Comment any adding-new-style code
Open 'init.docx'
Delete everything
Save it.
Add footnote/Headers to 'init.docx'
Change self.document = Document('') to self.document = Document('init.docx').

Related

Extract Hyperlinks Google Apps Script

For a long time the following code did work perfectly to extract hyperlinks from a text using regex-expression:
var text = "this is a http://google.de link!";
var link = text.match("(?:(?:https?|ftp|file):\/\/|www\.|ftp\.)(?:\([-A-Z0-9+üäö&##/%=~_|$?!:,.]*\)|[-A-Z0-9+üäö&##/%=~_|$?!:,.])*(?:\([-A-Z0-9+üäö&##/%=~_|$?!:,.]*\)|[A-Z0-9+üäö&##/%=~_|$])", "gi");
The result should be "http://google.de" for the variable link. But it doesn't work anymore. I deem Google has changed something in GAS!?
Can you please tell me, which expression I can use to extract hyperlinks from a string?

Aspose.PDF How Replace replace text on PDF page to all upper case

I am trying to replace text on a specific page to upper case using Aspose.PDF for .Net. If anyone can provide any help that would be great. Thank you.
My name is Tilal Ahmad and I am a developer evangelist at Aspose.
You may use the documentation link for searching and replacing text on a specific page of the PDF document. You should call the Accept method for specific page index as suggested at the bottom of the documentation. Furthermore, for replacing text with uppercase you can use ToUpper() method of String object as follows.
....
textFragment.Text = textFragment.Text.ToUpper();
....
Edit: A sample code to change text case on a specific PDF page
//open document
Document pdfDocument = new Document(myDir + "testAspose.pdf");
//create TextAbsorber object to find all instances of the input search phrase
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("");
//accept the absorber for all the pages
pdfDocument.Pages[2].Accept(textFragmentAbsorber);
//get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
//loop through the fragments
foreach (TextFragment textFragment in textFragmentCollection)
{
//update text and other properties
textFragment.Text = textFragment.Text.ToUpper();
}
pdfDocument.Save(myDir+"replacetext_output.pdf");

ActiveQt: Activate an already open word document

I am trying to write to an open word document using activeQt. I am trying to activate my word document, but i cant get it to work.
I can do this in VBA very easily:
Documents("my.doc").Activate
but not in Qt, this is what i have tried:
wordApplication = new QAxObject("Word.Application");
doc = wordApplication->querySubObject("Documents()","my.doc");
doc->dynamicCall("Activate()");
Documents() is supposed to contain all the open word documents, but for me it is empty for some reason.
I found the solution to my problem, by using the setControl function with the UUID for word I was able to access a word document that was already opened.
QAxObject* wordApplication;
QAxObject* doc;
wordApplication = new QAxObject(this);
wordApplication->setControl(("{000209FF-0000-0000-C000-000000000046}&"));
doc = wordApplication->querySubObject("Documents()","my.doc");

How to get a table cell in aspose slides?

I see this sample:
http://www.aspose.com/docs/display/slidesnet/Creating+a+Table+from+Scratch
...and when I try to use it, I see that the library has changed (I guess) and it needs me to do sth like that:
int lIndex = pSld.Shapes.AddTable(pUppLeftPoint.X, pUppLeftPoint.Y, pColumnWidths, pRowWidths);
TableEx lTable = (TableEx)pSld.Shapes[lIndex];
(I can only cast to TableEx and not to Table)
But I cannot find how to get the cell's TextFrame. The site says :
TextFrame tf = table.GetCell(0, 0).TextFrame;
But I have nothing like this...
Am I missing sth?
Any ideas?
EDIT :
I found out that my code is for PPTX and the site's code for PPT:
http://www.aspose.com/community/forums/thread/453613/facing-performance-issue-due-to-addtable-method-of-pptx.aspx
But, again, how do you get the cell's contents in PPTX?
Ha! I got it!
There's an indexer:
lTable[i,j]

Does Qt Linguist offer the ability to add new entries to the editable .ts file?

I didn't find a way to do this - only to edit the translations to the existing fields.
If there is no way to achieve this - how should this be done (somehow automatically, because right now I was manually adding
<message>
<source>x</source>
<translation>xx</translation>
</message>
blocks to my .ts file and I assume that's not the correct way.
No, that's not the correct way :) Use tr() in the code to mark strings for translation.
For example
label->setText( tr("Error") );
The you run lupdate for your project to extract them to a .ts. See here for more details.
Or do you need to translate strings that are not in the source code?
I just wrote a python script to insert new entries
into the .ts file for a homegrown parser using ElementTree. It doesnt make the code pretty
when it adds it, but I believe it works just fine (so far):
from xml.etree import ElementTree as ET
tree = ET.parse(infile)
doc = tree.getroot()
for e in tree.getiterator()
if e.tag == "context":
for child in e.getchildren():
if child.tag == "name" and child.text == target:
elem = ET.SubElement(e, "message")
src = ET.SubElement(elem, "source")
src.text = newtext
trans = ET.SubElement(elem, "translation")
trans.text = "THE_TRANSLATION"
tree.write(outfile)
Where infile is the .ts file, outfile may be the same as infile or different.
target is the context you are looking for to add a new message into,
and newtext is of course the new source text.