Copying PowerPoints Notes Pane to Word Gives Inconsistent Font Sizes - ms-word

I have a Word VSTO addin which copies the Notes page for each slide in a PowerPoint file into a Word document. There are only certain lines in the Notes pane that I need. My code loops thru each slide, looks for any notes, then checks for the tags and copies the text between the start and end tags. It is important to maintain the formatting in the Notes page. However, when pasting into Word, the font copies over, but the size changes. For instance, the font in PowerPoint might be Times New Roman 12, but in Word it will sometimes randomly change to Times New Roman 14. It appears that even if pasting a single range of text, the font may change between paragraphs. Also, certain blocks of text in Word will have the Normal style, but others will have Normal (Web), which affects line spacing.
I tried using a method to retain original source formatting (commented out below), but that sometimes will create bullets before the text, besides changing the font size.
Anyone have an idea how to resolve this?
The abbreviated example code is below.
Dim notesRng, fndRng, endRng, copyRng as PowerPoint.TextRange
dim iStart, charLen as Integer
For i As Integer = 0 To pwrPointApp.ActivePresentation.Slides.Count - 1
oSlide = pwrPointApp.ActivePresentation.Slides(i)
If oSlide.NotesPage.Shapes.Placeholders(2).TextFrame.TextRange.Text.Length > 0 Then
notesRng = oSlide.NotesPage.Shapes.Placeholders(2).TextFrame.TextRange
fndRange = notesRng.Find(FindWhat:="START:")
If Not fndRange is Nothing then
iStart = notesRng.Text.IndexOf("START:") + 6 ' puts the start just after the colon:
endRng = notesRng.Find(FindWhat:="END:", After:=iStart)
If Not endRng is Nothing Then
charLen = notesRng.Text.IndexOf("END:", iStart) - iStart
copyRng = oSlide.NotesPage.Shapes.Placeholder(2).TextFrame.TextRange.Characters(iStart, charLen)
If Not copyRng is Nothing then
copyRng.Copy
ThisAddIn.WordApp.Selection.Paste()
'ThisAddIn.WordApp.Selection.PasteAndFormat(Word.WdRecoveryType.wdFormatOriginalFormatting)
ThisAddin.WordApp.Selection.Collapse()
End If
End If
End If
End If
Next I

Related

Aspose.Words - Format a single word in a paragraph

I'm new to Aspose.Words for .Net, and working on recreating some documents for a customer. I need to make a single word in a paragraph bold and underlined. I'm trying to achieve this by creating separate paragraph runs for the text before the bold word, the bold word itself, and the text after. Then I'm formatting the bold word's run and appending everything to the paragraph. This seems overly complicated. Is there a simple way to achieve this from within DocumentBuilder.WriteLn("some text")?
I kept working at it, and achieved the desired result by using DocumentBuilder.Write() instead of DocumentBuilder.Writeln():
builder.Write("The start of the paragraph ");
builder.Font.Bold = true;
builder.Font.Underline = Underline.Single;
builder.Write("underlined bolded text");
builder.Font.Bold = false;
builder.Font.Underline = Underline.None;
builder.Write(" the end of the paragraph.");

How to add phonetic guides to all the texts at once?

I have an essay with roughly 1000 Chinese words. I want to add phonetic guide (Pin Yin) on top of each Chinese word.
Therefore, in MS Words, I use Phonetic Guide. However, Phonetic Guide only allows me to create Pin Yin for 20 to 30 words each time. I tried to look for a function which allows me to add phonetic guides for all the words at once, but I cannot find an answer online.
I also want to make the phonetic guide font bigger and create more space between the Chinese text and the Pin Yin.
Can any expert give me some lights?
Not familiar with this area, but the starting point is that you can invoke the Phonetic Guide dialog box and get it to create the pinyin for the selection. For example
Sub testInsertPhoneticGuide()
Call insertPhoneticGuide(Selection.Range)
End Sub
Sub insertPhoneticGuide(r As Word.Range)
Dim d As Word.Dialog
Dim lng As Long
Dim lngChars As Long
Dim r1 As Word.Range
Dim r2 As Word.Range
On Error Resume Next
Set d = Word.Dialogs(wdDialogPhoneticGuide)
Set r1 = r.Duplicate
r1.TextRetrievalMode.IncludeFieldCodes = False
For lng = Len(r1.Text) To 1 Step -1
Set r2 = r1.Characters(lng)
' Do not insert pinyin for any range that
' contains a field (this will prevent the code from re-inserting
' pinyin, but you can change the way this works if you like)
If r2.Fields.Count = 0 Then
r2.Select
d.Show 1
' Error 6031 says there's no text to pinyin
If Err.Number = 6031 Then
Err.Clear
Else
On Error GoTo 0
End If
End If
Next
Set r2 = Nothing
Set r1 = Nothing
Set d = Nothing
End Sub
As far as I can tell, there is no way to specify the font and size/position parameters in the dialog box. They are not "sticky". But the Phonetic guide replaces each suitable character by an { EQ } field that contains the pinyin and the original character. The EQ looks somehting like this:
{ EQ \* jc2 \* "Font:SimSun" \* hps11 \o\ad(\s\up 10(fā),发) }
so as long as you want the same font, size and positioning, you should be able to display all the field codes and use Word Find/Replace to modify those values in every EQ field (or you could add code to modify the values for each character that you pinyin.
NB, there is also a PhoneticGuide() member of Word's Range object that lets you specify the pinyin text and the positioning parameters. However, to use that you would have to get the pinyin text somehow - the only way I know within Word is actually to use the Phonetic Guide dialog to insert it, but I imagine the necessary info for each character is available on the web.
In case anybody comes to this question again, after searching for a solution for a while I managed to add pinyin to my entire Chinese document by using the following two tools:
1) Open Office
2) The OO Pinyin Guide Extension for Open Office.
Hope this helps : )

How to bold the text in TOC, but not the dot leader not the page number?

I have created a table of contents (TOC) to my Microsoft Office Word 2013 document using different types of headings linked to the TOC. When I try to modify my TOC 1 style so that only the text inside that TOC paragraph would be bolded, it makes the whole paragraph bolded. What I want to achieve is this:
ONLY THE TEXT HERE IS BOLDED................................1
rather than bolding the dot leader lines nor the page number like this
THE WHOLE PARAGRAPH IS BOLDED.........................1
I can do this manually, but everytime I update my TOC, all these changes go away (everything is bolded/not bolded again). How can I bold only only the text (not dot leaders or page number) inside TOC-style?
Fields throw away edits when updated - there's little you can do to change this. There is a * MergeFormat switch that can be added to field codes in order to retain formatting. The major drawback, however, is that it "remembers" formatting by character location. So if the text changes (gets shorter or longer) the formatting "goes crazy". Therefore, I don't think that will help you.
So all you can really do is re-apply the formatting after each TOC update. The fastest way to do that is using code (a macro, for example).
Here's a macro that works in a quick test on my system. It searches for each TAB character in the TableOfContents. Then, based on the additional information from the OP that only the second tab should be recognized, uses a second range to check whether the position AFTER the tab is within one centimeter of the right margin.
If that's the case, it repositions the find-target Range from that point back towards the beginning of the paragraph, then applies the formatting.
Note 1: You can change the "cushion" used to determine the distance to the right margin by changing the formula assigned to PageNumLimit.
Note 2: I defined a STYLE named Toc1_Text and use that, rather than formatting with BOLD directly. Doesn't really matter, but it feels "cleaner" to me than direct formatting :-)
Sub FormatTextInTOC()
Dim rngFind As word.Range, rngFound As word.Range
Dim bFound As Boolean
Dim toc As word.TableOfContents
Dim infoH As Double, pageNumLimit As Double
Set toc = ActiveDocument.TablesOfContents(1)
toc.Update
Set rngFind = toc.Range
pageNumLimit = rngFind.Sections(1).PageSetup.RightMargin _
- CentimetersToPoints(1)
With rngFind.Find
.ClearFormatting
.Text = vbTab
.Style = word.WdBuiltinStyle.wdStyleTOC1
Do
bFound = .Execute
If bFound Then
Set rngFound = rngFind.Duplicate
'rngFound.Select
rngFound.Collapse wdCollapseEnd
infoH = rngFound.Information(_
wdHorizontalPositionRelativeToTextBoundary)
If infoH >= pageNumLimit Then
'rngFind.Select
rngFind.Collapse wdCollapseStart
rngFind.MoveStart wdParagraph, -1
rngFind.Style = "Toc1_Text"
rngFind.Start = rngFind.Paragraphs(1).Range.End
'rngFind.Select
End If
End If
Loop While bFound
End With
End Sub

In Applescript, finding only bold words in TextEdit causes app to hang

just trying to find a vanilla applescript way of setting a variable to all bold words of a document. I've looked for ways using Applescript in Word, Pages & TextEdit and TextEdit seems to be the only one (could be wrong, though).
The good news is that the following script works but the bad news is if the document is over 2 pages with let's say ~50 bolded words, TextEdit hangs.
Any other ways to get bolded words using Applescript?
tell application "TextEdit"
return words of text of document 1 where font contains "Bold"
end tell
Thanks
It may be that TextEdit is being unreasonably slow. I just used the following code for a document with 3600 words, with some random bold words interspersed throughout. It took way too long. I'd look into using different scriptable app, like Tex-Edit Plus (still goin' strong, still great).
The reason I used both "Black" and "Bold" is that some fonts use a "Black" variant instead of "Bold" when you make the text Bold (at least in TextEdit). Just to be clear, the following code works, but it is painfully slow. It may be that your code, if you waited long enough, works, too. :-( BUT keep reading :-)
tell application "TextEdit"
tell document 1
set thisManyRuns to count of attribute run of text of it
repeat with r from 1 to thisManyRuns
if font of attribute run r of text of it contains "Black" then
--do stuff
set color of attribute run r of text of it to {35555, 0, 0}
end if
if font of attribute run r of text of it contains "Bold" then
--do stuff
set color of attribute run r of text of it to {35555, 0, 0}
end if
end repeat
end tell
end tell
I just ran this text in Tex-Edit Plus and it completed in about two seconds:
tell application "Tex-Edit Plus"
tell document 1
set thisManyRuns to count of style run of text of it
repeat with r from 1 to thisManyRuns
set thisStyle to style of style run r of text of it
if on styles of thisStyle contains bold then
--do stuff
set color of style run r of text of it to {0, 35555, 0}
end if
end repeat
end tell
end tell
... so you might want to switch to that. Just a caveat that I had to put the style into the thisStyle variable before querying for the on styles property -- it would not work if I tried to do that in one line. I was working with an rtf file.

DataDynamics.ActiveReports replacing text during runtime changes original format

I'm almost left with no time but facing a problem with DataDynamics.ActiveReports.
I have to replace some text for 500 reports so automating the task through code at run time.
The major problem I'm facing is on replacing text the original bold wont changes to normal font. center justified text will be left justified also Arial Narrow text changes to Arial.
Is there any way to replace text without disturbing the original format.
Here is the piece of code:
var textBox = (DataDynamics.ActiveReports.RichTextBox)reportSection.Controls[controlIdx];
if (textBox.Text.Contains("Babu"))
{
MessageBox.Show(textBox.Text);
var modifiedtext = (DataDynamics.ActiveReports.RichTextBox)reportSection.Controls[controlIdx];
modifiedtext.Text = modifiedtext.Text.Replace("Babu", "Mannu");
MessageBox.Show(modifiedtext.Text);
}
The modified report has a format different than the original. How to fix this issue??
its richtext, not plain text.
every rich text has a formatting associated with it.
try editing the original rtf that you are loading into the rtb control. This is what I would recommend.
Or, another approach could be to use richtextbox.rtf.replac instead of richtextbox.text.
At what time of the report processing are you doing this?