Programmatically setting text style in 4D Write Pro (4D v17 R5) - 4d-database

I'm trying to programmatically set two text styles inside an also programmatically created 4D Write Pro document, but the last style set is the only one assumed for the whole document.
I have created a new 4D Write Pro document (wpDoc), created a range for the whole document ($range), and used "WP Set Attributes" to format the text.
C_OBJECT(wpDoc;$range)
wpDoc:=WP New
$range:=WP Text range(wpDoc;wk start text;wk end text)
// Style 1
WP SET ATTRIBUTES($range;wk font;"DIN-Bold")
WP SET ATTRIBUTES($range;wk font size;"12pt")
WP SET TEXT($range;"Name: ";wk append)
// Style 2
WP SET ATTRIBUTES($range;wk font;"DIN-Regular")
WP SET ATTRIBUTES($range;wk font size;"10pt")
WP SET TEXT($range;[Companies]Name;wk append)
WP PRINT(wpDoc)
it should look like:
Name: Sample Company name
but it shows like:
Name (plain text): Sample Company name (plain text)

Since your range is growing with the text you are appending, you need to alter your range. The following code worked for me.
You should confirm that your font exists otherwise the attributes command will have no effect (FONT LIST). I switched to a font that I know my system has.
'WP Text range' is not valid in the version I am using (perhaps you have an older version. I am using v17.3). My code uses 'WP Create range'.
C_OBJECT(wpDoc;$range)
wpDoc:=WP New
$range:=WP Create range(wpDoc;wk start text;wk end text)
// Style 1
WP SET TEXT($range;"Name: ";wk append)
WP SET ATTRIBUTES($range;wk font;"Book Antiqua Bold")
WP SET ATTRIBUTES($range;wk font size;"12pt")
// Style 2
$range:=WP Create range(wpDoc;7;wk end text)
WP SET TEXT($range;[Companies]Name;wk append)
WP SET ATTRIBUTES($range;wk font;"Book Antiqua")
SET PRINT PREVIEW(True)
WP PRINT(wpDoc)

Related

in python-docx, I try to read the font size, but I get None

My task is to check several docx documents for font properties, like font name, size, boldness, italic etc. I do not want to change anything, just validate if there are correct values.
I created a small test document, with text "Foo-bar" and I have updated the font name to Garamond from the default, but have not changed the font size.
Now I am able to read the font name from the document, but when I try to read the font size, I get None.
from docx import Document
from docx.enum.text import WD_ALIGN_PARAGRAPH
def check_para_props(doc, paralist, ffamily, fsize, paligin):
pargs = doc.paragraphs
for i in paralist:
para = pargs[i]
print(i, para.text)
for run in para.runs:
print(run.font.name, run.font.size)
worddoc = Document('Foo-bar.docx')
# pass the document, the paragraphs list which should be tested
# and the expected values
check_para_props(worddoc, (0, ), 'Garamond', 11, WD_ALIGN_PARAGRAPH.JUSTIFY)
Output:
0 Foo-bar
Garamond **None**
I assume, there is some default values in docx for the unchanged values, like font-size, but have not found, how could I read them from the document. In python-docx documentation I have not found an API call for it: https://python-docx.readthedocs.io/en/latest/index.html
I have checked the style section, which is readable, but I don't think, this is set there.
Checked API documentation: https://python-docx.readthedocs.io/en/latest/index.html
Word is able to export document in XML format, but still I have doubts how to read the font size.
In that article, I read the about the inheritance of the properties: https://www.toptal.com/xml/an-informal-introduction-to-docx
It tells, to get the end result of a character’s properties you should:
Use default run/paragraph properties
Append run/paragraph style properties
Append local run/paragraph properties
Append result run properties over paragraph properties
Ok, still how may I read the default properties using python-docx?
Please advise!
Thank you in advance!

Docs Inserted Image always before all text

Making a simple app script that puts images and Text into a Google Doc separated by 2 Columns, for whatever reason, no matter the way I try it the images are always above the text (Inline) in the Doc, even though they should be layered (Inline),
//Replace QR Code
let qrText = editLocalBody.findText("{{qrCode}}");
let setImagePlace = qrText.getElement().asText().replaceText("{{qrCode}}", "");
let qrCodeImage = setImagePlace.getParent().asParagraph().insertInlineImage(0, qrCodeBlob);
From what I've seen this should insert an image wherever the text was previously located, but when it runs this it's always in the wrong spot, somehow above the text it was suppost to be in!
//Edit - To Show The Progression Of What Is Suppose To Happen And What Actually Happens:
I'm making QR Code badges for a propriety system that runs integrated tightly with Google, so I'm using appscript to get an entry from a google form containing an amount of badges (With relevent data) and autofill a Google Doc Accordingly.
// Loop Start
I fill my template with a text line that has key words in it I can select and replace later, with a keyword it can use to insert another this (This Part Works)
I first edit (findText("{{qrCode}}");) the QR Code, replacing (.replaceText) the keyword for it to nothing ("")
I then get the parent of the piece of code I ran above, which is a block of text (I think all the text in the Doc, I think this is where the issue lies, it puts it above the text because it's just one 'paragraph' or not multiple 'bodies' of text, if I could separate this I think it would work!) As a paragraph, and insert An Inline Image at Child Index (0, of the image ,qrCodeBlob)
I've debugged this script quite a bit, so I know It's that final line that inserting images fails, it sees all the text as 'one'.
// I want this (In Descending Order, each it's own full line):
Image
Text
Image
Text
//What It Gives Me (In Descending Order, each it's own full line):
Image
Image
Text
Text
let qrCodeImage = setImagePlace.getParent().asParagraph().insertInlineImage(0, qrCodeBlob);

Extraction - only numbers from address

The address of Japan is written in many sites as 〒000 - 0000.
From this, I would like to extract only numbers using imacros.
In other words, I want to remove 〒 and -.
I want to copy the extracted data, save it on the clipboard and paste it in another place.
Thank you.
(chrome 70.0.3538.102, Win10_x64)
Posting as a separate Solution, as the Input from the Extract is now "a bit" different and changes the Syntax in 'EVAL()' quite a bit, even if I tried to reuse a bit the same Syntax with the same Commands like in Answer_#1. (And that gives a 2nd Code Example...)
SET !EXTRACT "〒 000-0000"
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.substr(2); y=x.split('-'); z=y[0]+y[1]; z;")
SET !CLIPBOARD {{!VAR1}}
PROMPT EXTRACT:<SP>_{{!EXTRACT}}_<BR>Numbers:<SP>_{{!VAR1}}_
(Tested on iMacros for FF v8.8.2, Pale Moon v26.3.3 (=FF47), Win10_x64.)
And again, there would be more than 10 different ways to implement the same Functionality to get the same Result...
"Nice" to select the 'Chrome' + 'Firefox' Forum Tags but more useful would be if you had mentioned your FCI for both Browsers..., but the following Implementation for example should work in both Browsers for all iMacros Versions:
SET !EXTRACT "〒000 - 0000"
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.substr(1); y=x.split(' '); z=y[0]+y[2]; z;")
SET !CLIPBOARD {{!VAR1}}
PROMPT EXTRACT:<SP>_{{!EXTRACT}}_<BR>Numbers:<SP>_{{!VAR1}}_
(Tested on iMacros for FF v8.8.2, Pale Moon v26.3.3 (=FF47), Win10_x64.)
"for example" => as you could implement the Functionality that you want in more than 10 ways using all kinds of different Combinations with other JS String Methods...
(I didn't include the Content of '{{!CLIPBOARD}}' in the 'PROMPT' as this is not supported on CR, but a 'Paste' from your OS Clipboard in 'Notepad' for example should still work...)

Access VBA Create Word header with text and position picture

Having trouble getting access vba to set a word document's header properly. I've got this.
oDoc.PageSetup.DifferentFirstPageHeaderFooter = True
oDoc.Sections(1).Headers(wdHeaderFooterFirstPage).Range.InlineShapes.AddPicture "C:\Users\mr.helpless\Pictures\doody.jpg"
oDoc.Sections(1).Headers(wdHeaderFooterFirstPage).Range.Text = "hello there"
oDoc.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = "whooo hooo!"
What happens right now is the text will replace the picture for the first page (subsequent pages are fine).
I need to have the picture and text - and I need to offset the picture to the left about half an inch while text is centered with normal margins.
Any idea how to go about it? Basically I need to set a document letterhead with a logo.
Update
Dim myText As String
myText = "hello there"
With oDoc.Sections(1).Headers(wdHeaderFooterFirstPage)
.Shapes.AddPicture Filename:="C:\Users\mr.helpless\Pictures\doody.jpg", LinkToFile:=False, SaveWithDocument:=True
.Range.Collapse
.Range.InsertAfter (myText)
.Range.Font.Name = "Helvetica"
.Range.Font.Size = 8
.Range.Font.Bold = True
.Range.Paragraphs.Alignment = wdAlignParagraphCenter
End With
I've got half of it done, now I just need to position the image to -.5 to margin.
Completed Solution
Just add "Left:=-35" to the picture like such (or whatever value works)
.Shapes.AddPicture Filename:="C:\Users\mr.helpless\Pictures\doody.jpg", LinkToFile:=False, SaveWithDocument:=True, Left:=-35
Have you tried recording a macro in Word that does the rough reposition - then bring the code over to Access and edit it for the correct object and size?
All of it is updated in the original thread. it took using the .Range Collapse to add in text along with the image and it took putting Left:=(value) to move it where I needed it.

Need solution regarding imacros !DATASOURCE_LINE issue

I have a csv file containing info for tv-series and each tv-series has its own macro. I can get all info without any problems using {{!COL1}} etc.
But I need some help on the scenario below.
tv-series.csv
Game of Thrones, 2011, Season 2
The Walking Dead, 2015, Season 5
etc.
If I want to get the title of a tv-series I will simply use {{!COL1}}, and for year {{!COL2}}
But I sometimes add new tv-series and the order of them compeletly changes in csv file. Then I have to modify all line #s in all macros manually.
Is there a way to determine the line number based on the firt column (e.g. Game of Thrones)? The info will not change, just the line numbers of them will change. Sorry for my terrible English, I hope I could tell my problem and need some advice.
My code so far
VERSION BUILD=8910303 RECORDER=FX
TAB T=1
SET !DATASOURCE tv-series.csv
SET !DATASOURCE_LINE 2 => This # should change based on first column
TAG POS=1 TYPE=TEXTFIELD FORM=NAME:title ATTR=ID:titlebox CONTENT={{!COL1}}
Use the command 'EVAL' and 'switch'-clause. As an example:
...
SET !DATASOURCE tv-series.csv
SET !DATASOURCE_LINE 1
SET lineNumber EVAL("switch ('{{!COL1}}') {case 'Game of Thrones': s = 2; break; case 'Something Else': s = 5; break; /* etc. */}")
SET !DATASOURCE_LINE {{lineNumber}}
...