Word 2010 Copy Rich Text Content Control
I am working on a Word 2010 template that links to another word document to copy information from Rich Text Content Controls. I am able to copy values between RTF controls but losing the rich text formatting - only text is copied over.
Any Suggestions on how to copy between rich text controls and still preserve the formatting?
Set sourceCCs = sourceDoc.SelectContentControlsByTag(sourceCCTag)
If Not (IsNull(sourceCCs)) Then
For Each sourceCC In sourceCCs
Set editCCs = editDoc.SelectContentControlsByTag(editCCTag)
If Not (IsNull(editCCs)) Then
For Each editCC In editCCs
If appendText Then
'editCC.Range.Text = editCC.Range.Text & vbCrLf & sourceCC.Range.Text
editCC.Range = editCC.Range & vbCrLf & sourceCC.Range
Else
'editCC.Range.Text = sourceCC.Range.Text
editCC.Range = sourceCC.Range
End If
Next
End If
Next
End If
Thanks in advance
Try something along the lines of:
Set sourceCCs = sourceDoc.SelectContentControlsByTag(sourceCCTag)
If Not (IsNull(sourceCCs)) Then
For Each sourceCC In sourceCCs
Set editCCs = editDoc.SelectContentControlsByTag(editCCTag)
If Not (IsNull(editCCs)) Then
For Each editCC In editCCs
With editCC.Range
If appendText Then
.InsertAfter vbCr
.Collapse wdCollapseEnd
End If
.FormattedText = sourceCC.Range.FormattedText
End With
Next
End If
Next
End If
Cheers
Paul Edstein
[MS MVP - Word]
Similar Messages
-
Hi,
I have a word document with a rich text content control that is mapped to a CustomXml. You can download an example here
http://1drv.ms/1raxoUr
I have looked into the specification ISO/IEC 29500-1:2012 and i understand that the attribute Target for the element Relationship can be set to NULL at times(Empty header and footer in the specification).
Now, i have stumbled on Target being NULL also when inserting a diagram into a word document. For example:
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject"
Target="NULL" TargetMode="External" xmlns="http://schemas.openxmlformats.org/package/2006/relationships" />
Why is Target="NULL" and how should i interpret that Target is null?
Br,
/Peter
PeterHello Peter,
The relationship in question is associated with the externalData element (ISO/IEC 29500-1:2012 §21.2.2.63). For the other two charts in this document, the corresponding relationships are of the other allowable form:
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/package" Target="../embeddings/Microsoft_Excel_Worksheet1.xlsx"/> <Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/package" Target="../embeddings/Microsoft_Excel_Worksheet2.xlsx"/>
For charts 1 and 3 in your document, the data can be edited via the Chart Tools ribbon control. The option to edit data is not available for chart 2. The data used to create chart 2 is the same default spreadsheet data used for chart 1, and in fact the spreadsheet
references are still present in the file format, despite there being no apparent link to a spreadsheet for chart 2.
Thus, it appears that Target="NULL" in this context means that the chart is not associated with an external data source. The specification doesn't have much to say about the semantics of the Target attribute (ISO/IEC 29500-2:2012 §9.3.2.2) beyond
the fact that it be a valid xsd:anyURI, which the string "NULL" is.
It looks like there is some unexpected interaction between the chart and the content control. I don't think the file format is the issue. You will probably need to pursue that behavior from the product perspective via a support incident, if that behavior
is unexpected. If you still have questions about what is seen in the file format, please let me know.
Best regards,
Matt Weber | Microsoft Open Specifications Team -
Word 2013 - Bulleted list inside rich text content control
Hi,
I'm mapping a rich text content control to an xml node within my custom xml.
While i'm in design mode i try to format the text so that it will be a numbered list.
One thing that i noted though was that the numbers are placed outside the content control. This is only my first observation.
The thing is, the rich text(RTF) that is saved within the custom xml is later used to populate a second document. This works great except for one small issue. The numbered list is not showing up within the second document.
Would appreciate any help i can get with this issue.
Br,
/Peter
PeterHi Peter
This is tricky, because...
By default, when you insert a new RichText content control it will not include the paragraph mark for the paragraph it's in. Numbering is a paragraph-level formatting.
If you work in Word, you can see this. Turn on the display of non-printing characters (the backwards P button in the "Home" tab of the Ribbon). Insert a RT content control and observe where the paragraph mark (backwards P) is in relation to the
CC's boundaries. Now press ENTER and observe that the paragraph mark is WITHIN the CC. Apply number formatting and you'll see that it's NOW inside the CC.
You can do this the other way around: apply the numbering then press ENTER. Again, it should now be within the CC.
This behavior is by-design. I would guess that lists the users type would have more than entry, so the numbering will be within the CC range when the custom XML is extracted?
Cindy Meister, VSTO/Word MVP,
my blog -
Automatically inserting rich text content control
I have many word .docx forms which I would like to convert to a form which can be filled in with Reader. The word forms presently would be like ...we [name of parties] desire to enter into...
I would like to have a program which automatically finds the brackets and inserts a rich text content control box and then inserts whatever is within the brackets for the placeholder wording.
Can this be done and if so, is it code in XML or am I totally off my rocker?
ThanksHi Peter,
According to the description, you are using OPCHelper converting the Word document into byte. As far as I know, the OPCHelper is a third-part class, I suggest contact the vendor to get more effective response.
For this issue, did you want to retrieve byte data from the Office package? And based on my understanding, the office document support Open XML format is a zip. We can directly get the data from the zip package via
GZipStream.
Hope it is helpful, and if I misunderstood please feel free to correct me.
Regards & Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Handling RICH TEXT content on BI publisher report
Hello,
I have requirment where I have to handle RICH TEXT content, and show data in report with RICH TEXT formating.
The RICH TEXT content(with tags) is comming from database CLOB column. Here is the sample XML data.
<?xml version="1.0" encoding="UTF-8" ?>
- <DATA_DS>
- <G_1>
<ID>1</ID>
<RICH_TEXT_DATE>'<p' class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-line-height-alt: 1.15pt">'<span' style="FONT-FAMILY: Arial Narrow,sans-serif; mso-bidi-font-family: bold; Tahoma">'<font' size="3">Testing data for rich text '</font'>'</span'>'</p'></RICH_TEXT_DATE>
</G_1>
</DATA_DS>
Report Output should be below with all the formating:-
<p class="MsoNormal" style="MARGIN: 0in 0in 0pt; mso-line-height-alt: 1.15pt"><span style="FONT-FAMILY: Arial Narrow,sans-serif; mso-bidi-font-family: bold; Tahoma"><font size="3">Testing data for rich text</font></span></p> <p></p>So, how to get above output with all formating, Please let me you soultions.
I am using, Oracle BI Publisher desktop version 11.1.1.5
Thanks in advance.
San.https://blogs.oracle.com/xmlpublisher/entry/html_in_xml_support
http://docs.oracle.com/cd/E23943_01/bi.1111/e22254/create_rtf_tmpl.htm#CHDCEEIJ
Rendering HTML Formatted Data in a Report : <BR/> are not being parsed -
How to fix width of plain text content control in Microsoft Word 2010?
I try to make the simplest solution for my custom to modify current Word template without hard code anything except field name.
As you can see above image, normally text field in Word is not fixed width control. So, it may affect document layout. Moreover, I want to add dotted line below all text fields in document template.
Is there any possible solution that end-user can do in normal Microsoft Word 2010 application?
PS. I will fill all controls with data from Microsoft Access.In PDF file, I can easily create fix-size absolute position field inside document template like the following document. In Microsoft Word, I cannot fix even the size of plain text field.
PS. Nobody use table with fixed cell size as normal form (hard copy). I think Microsoft Word is really bad choice for creating any document template by end-user.
Criticizing Word for not doing the same as some other application is hardly relevant. Have you tried word-processing with Adobe Acrobat?
As for your PS, Word tables are ideal for the kind of thing you describe. Your assertion that 'nobody' does so is plain ignorance - it is a common practice. In my previous employment,
many forms were created using Word tables. Before complaining Word is a 'really bad choice', you should learn how to use it.
Cheers
Paul Edstein
[MS MVP - Word] -
How to send a mail with rich text content like using outlook
Hi All. I have a serious problem. When we send the mail from
outlook express or yahoo, we can send the mail with the text appearing
in the mail with bold font , with different colors, underlined etc.
If i type this kind of text in any word processor and mail that content through java mail then the message should be received by the recepient with all that bold,color and underlines etc as it is. Can anybody please help me in this case ASAP.Go to this site and download the htmlArea Javascripts. Embedd them in your HTML and it will turn your normal HTML Text Area into Rich Text Area. Your real code will include all HTML tags. For example if you select some text and make it bold , the real HTML output will look like <B>YOUR TEXT </B>. So i guess your recipient should be able to receive HTML contents.
http://www.interactivetools.com/products/htmlarea/ -
Reading Word attachments (with Rich Text Format) in Mail
I have difficulty opening "Word email attachments" that contain "Rich Text Format" using my ipod touch under the MAIL function. For normal Word documents, I have no issue at all. Can anyone help here? Thank you.
RTF contains alot of extra formatting junk that you need to be aware of, depends what you want to do with the files afte reading them in but JAVA has its own RTF parser standard. Be warned its not full proof.....
import java.io.*;
import java.util.StringTokenizer;
import javax.swing.text.rtf.RTFEditorKit;
import javax.swing.text.Document;
try {
FileInputStream stream = new FileInputStream("C:/Document.rtf");
RTFEditorKit kit = new RTFEditorKit();
Document doc = kit.createDefaultDocument();
kit.read(stream, doc, 0);
String plainText = doc.getText(0, doc.getLength());
BufferedReader br = new BufferedReader(new StringReader(plainText));
String line = br.readLine();
while (line != null) {
StringTokenizer tok = new StringTokenizer(line, " ");
while (tok.hasMoreTokens()) {
System.out.print(tok.nextToken() + " ");
System.out.println();
line = br.readLine();
} catch (Exception ex) {} -
I'm new to VBA and need to better understand the syntax for identifying, accessing control "value" and setting the value from a user form.
My task is this, I have a word document containing the new Content Controls. I need to be able to access each individual control to initialize a UserForm control. I then need to update the "values of the controls on exiting the UserForm. Can someone
proved some simple sample code showing this functionality? I have surmised that the "range" attribute holds the value of the control but I need the textual or logical value of the control.
Thanks.Hi Gunteacher,
My task is this, I have a word document containing the new Content Controls. I need to be able to access each individual control to initialize a UserForm control. I then need to update the "values of the controls on exiting the UserForm.
What's content control you are using? Based on my understanding, we can indentify the content control by its tag and get the value of content control and initialize the control on the userform in the initialize event of userform. For example,
code below is that get the text of rich text content control:
ActiveDocument.ContentControls(1).Range.Text
And here are some helpful links about content control for your reference:
ContentControl Object (Word)
Working with Content Controls
What did you mean "I then need to update the "values of the controls on exiting the UserForm."? Did you mean that when the values of content control is changed, it should update the control on the user form which was open before?
As far as I know, there is no such event suitable for this secnario. If you want content control to support this event, I suggest that you submit the feedback from the "Smile Face" at the top right corner of Word.
Regards & Fei
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click
HERE to participate the survey. -
Hi,
I have a Word 2013 document that I want to open in Word 2010. The problem is this document has a repeating section content control and if I open it in Word 2010, the content control is removed so the data won't be seen. Is there any way programmatically
to save the document in Word 2010 compatible mode? So that I can open in both Word 2013 and 2010. By the way, I'm using C# and OpenXML for this.
Thanks.Hi,
Based on my tested, I created a "Rich Text" content control in Word 2013, and it'll works fine in Word 2010.
As far as I know, in Word 2013, content controls provide three key improvements: improved visualization, support for XML Mapping for Rich Text content controls, and a new content control for repeating content.
Please see the article "What's new with content controls in Word 2013" it may be helpful to you.
If you have any further question about coding/programing, please post your question to MSDN forum.
http://social.msdn.microsoft.com/Forums/en-US/home?forum=worddev&filter=alltypes&sort=lastpostdesc
Regards,
George Zhao
TechNet Community Support -
Insert a Picture into the Picture/Image Content Control using Open XML SDK 2.0
I have created a word template as follows
Here PizzaPicture is a Picture Content Control, PizzaName is a Plain Text Content Control and PizzaDescription is a Rich Text Content Control
I am able to assign text to PizzaName and PizzaDescription Easily but not able to even locate the PizzaPicture. Here is my code
using (WordprocessingDocument document = WordprocessingDocument.Open(@".\test.docx", true)) {
MainDocumentPart mainPart = document.MainDocumentPart;
DocumentFormat.OpenXml.Wordprocessing.Text text = null;
SdtContentBlock pizzaNameBlock = null;
SdtContentBlock pizzaDescriptionBlock = null;
//SdtContentBlock pizzaPictureBlock = null;
List<SdtBlock> sdtList = mainPart.Document.Descendants<SdtBlock>().ToList();
foreach (SdtBlock sdt in sdtList)
Console.WriteLine(sdt.SdtProperties.GetFirstChild<Tag>().Val.Value);
SdtBlock s1 = mainPart.Document.Body.Descendants<SdtBlock>().Where(r => r.SdtProperties.GetFirstChild<Tag>().Val == "PizzaName").Single();
SdtBlock s2 = mainPart.Document.Body.Descendants<SdtBlock>().Where(r => r.SdtProperties.GetFirstChild<Tag>().Val == "PizzaDescription").Single();
SdtBlock s3 = mainPart.Document.Body.Descendants<SdtBlock>().FirstOrDefault(r =>
SdtProperties p = r.Elements<SdtProperties>().FirstOrDefault();
if (p != null)
Console.WriteLine("P is not null");
// Is it a picture content control?
SdtContentPicture pict =
p.Elements<SdtContentPicture>().FirstOrDefault();
if (pict != null) Console.WriteLine("Pict is not null");
// Get the alias.
SdtAlias a = p.Elements<SdtAlias>().FirstOrDefault();
if (pict != null && a.Val == "PizzaPicture")
return true;
return false;
if (s3 == null) {
Console.Write(" s3 is Null");
} else {
Console.WriteLine("s3 not null");
if (s1 != null) {
pizzaNameBlock = s1.Descendants<SdtContentBlock>().FirstOrDefault();
text = pizzaNameBlock.Descendants<DocumentFormat.OpenXml.Wordprocessing.Text>().FirstOrDefault();
// here you can set the current time
text.Text = "Peperoni";
Console.WriteLine(text.Text);
string embed = null;
if (s3 != null)
Drawing dr = s3.Descendants<Drawing>().FirstOrDefault();
if (dr != null)
Blip blip = dr.Descendants<Blip>().FirstOrDefault();
if (blip != null)
embed = blip.Embed;
if (embed != null)
IdPartPair idpp = document.MainDocumentPart.Parts
.Where(pa => pa.RelationshipId == embed).FirstOrDefault();
if (idpp != null)
ImagePart ip = (ImagePart)idpp.OpenXmlPart;
using (FileStream fileStream =
File.Open(@"c:\temp\pepperoni.jpg", FileMode.Open))
ip.FeedData(fileStream);
if (s2 != null) {
pizzaDescriptionBlock = s2.Descendants<SdtContentBlock>().FirstOrDefault();
string altChunkId = "AltChunkId12345";
AlternativeFormatImportPart chunk = mainPart.AddAlternativeFormatImportPart(AlternativeFormatImportPartType.Xhtml, altChunkId);
chunk.FeedData(File.Open(@".\html.txt", FileMode.Open));
AltChunk altChunk = new AltChunk();
altChunk.Id = altChunkId;
////Replace content control with altChunk information
OpenXmlElement parent = pizzaDescriptionBlock.Parent;
parent.InsertAfter(altChunk, pizzaDescriptionBlock);
pizzaDescriptionBlock.Remove();
mainPart.Document.Save();
document.Close();
Here the call mainPart.Document.Descendants<SdtBlock>().ToList(); returns me only 2 items PizzaName, PizzaDescription but
no PizzaPicture.
Secondly the line SdtContentPicture pict = p.Elements<SdtContentPicture>().FirstOrDefault();
returns NULL. So it seems that there is no element of type SdtContentPicture.
What am I doing wrong? I am pretty sure that I have put PizzaPicture as a Picture content control.
My objective is to locate this control in the document and then insert an image into it programmatically.
MSDNStudent Knows not much!Hi,
I'm running some test on your code, and I'll come back as soon as I get some update. But before that, I would recommend you to bind customXMLPart with the content controls via Content Control Tool Kit,
which enables us to bind customXMLPart with CC by dragging and dropping.
After binding, you can change contents of the template via OpenXML SDK easily as the following code:
private void button1_Click(object sender, EventArgs e)
string fileName = @"C:\CCTest.docx";
WordprocessingDocument wordDoc = WordprocessingDocument.Open(fileName, true);
MainDocumentPart mainPart = wordDoc.MainDocumentPart;
CustomXmlPart customPart = mainPart.CustomXmlParts.FirstOrDefault();
//convert image into string
string picName = @"C:\Users\Public\Pictures\Sample Pictures\Desert.jpg";
System.IO.FileStream fileStream = System.IO.File.Open(picName, System.IO.FileMode.Open);
System.IO.BinaryReader br = new System.IO.BinaryReader(fileStream);
byte[] byteArea;
byteArea = br.ReadBytes(System.Convert.ToInt32(fileStream.Length));
string picString = System.Convert.ToBase64String(byteArea);
//Load the XML template
string DataString = Properties.Resources.XMLData;
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(DataString);
//change the value
XmlNodeList xmlNode = xmlDoc.GetElementsByTagName("pizzaPic");
xmlNode[0].InnerText = picString;
xmlNode = xmlDoc.GetElementsByTagName("pizzaName");
xmlNode[0].InnerText = "Pizza Name";
xmlNode = xmlDoc.GetElementsByTagName("pizzaDescription");
xmlNode[0].InnerText = "Pizza Description";
//write the custom xml data into the customxmlpart
System.Xml.XmlTextWriter writer = new System.Xml.XmlTextWriter(customPart.GetStream(System.IO.FileMode.Create), System.Text.Encoding.UTF8);
writer.WriteRaw(xmlDoc.InnerXml);
writer.Flush();
writer.Close();
fileStream.Close();
br.Close();
mainPart.Document.Save();
wordDoc.Close();
and the XML template of the project would something like:
<?xml version="1.0"?>
<Pizza xmlns="http://Test/ContentControls/Pizzas">
<pizzaPic></pizzaPic>
<pizzaName></pizzaName>
<pizzaDescription></pizzaDescription>
</Pizza>
I hope this helps.
Calvin Gao[MSFT]
MSDN Community Support | Feedback to us -
Rich text toolbar missing on a survey list in Sharepoint 2010
Hi ,
I created a Survey list in SP 2010 and added a 'Content Editor' webpart to it. The problem is that there is
no Ribbon available in the Survey List in SP 2010. (While it is available in the a normal list) Why? Is it the default functionality of Sharepoint 2010?
How can I add a rich text toolbar so that while editing the content webpart I can format the text. Is it possible?Hi Yasir,
This behavior is by design. When you add a content editor web part on survey list page, you can only add the plain text.
Have a try to add a rich text control
InputFormTextBox to the overview.aspx page in SharePoint Designer, add the following code to code behind.
<SharePoint:InputFormTextBoxRows="10"MaxLength="1000"id="txtMyRichTextBox"runat="server"RichText="true"RichTextMode="FullHtml"TextMode="MultiLine"
Height="400px"Width="250px"></SharePoint:InputFormTextBox>
For more information, see
http://blog.mastykarz.nl/rich-text-editor-control-sharepoint-2010/
Best Regards.
Kelly Chen
TechNet Community Support -
Convert to word or rich text not right
converted a pdf to word and to rich text but did not copy right
Hi Larry,
I'm not sure what you mean by "did not copy right" but I'm guessing that you're seeing some odd characters and such in the converted file? (I also don't know what version of Acrobat you're using, so I don't have a lot to go on here). But, have you tried changing any of the conversion settings in Acrobat?
Choose File > Save As > Microsoft Word > Word Document.
Click the Settings button next to the conversion format.
Here, you can tell Acrobat to retain flowing text or page layout, include images, and run OCR (optical character recognition), if necessary. If the PDF already contains selectable text, you can try disabling OCR to see if that improves your conversion output.
The quality of the conversion will depend largely on the quality of the PDF file. Do you know how it was created? You can find out by choosing File > Properties and clicking the description tab.
Please write back with a few specifics about the problem and we can go from there.
Best,
Sara -
Rich Text Editor functionality for a DIV tag in a publishing page in SharePoint online
Hi,
We are having a requirement where we need RTE behavior of SharePoint 2013 Rich Html Field for a custom DIV. The scenario goes like this:
1. I have a publishing page
2. I dropped the content editor web part and to that content editor web part I will point to an HTML file that needs to be rendered in that content editor web part
3. I have one DIV in the above mentioned HTML files and I want that div to be editable and I need to RTE options for that DIV.
How to accomplish the above behavior?Hi,
According to your post, my understanding is that you wanted to create html rich text editor for a DIV tag in a publishing page in SharePoint online.
You can create your own Rich Text Editor.
Here are some great blogs for your reference:
An Example to Use HTML Rich Text Editor
Example: Using the Editor's instance
Rich Text Editor control in SharePoint 2010
Regarding SharePoint Online, for quick and accurate answers to your questions, it is recommended that you initial a new thread in Office 365 forum.
Office 365 forum
http://community.office365.com/en-us/forums/default.aspx
Best Regards,
Linda Li
Linda Li
TechNet Community Support -
Converted single line text to multiple and want to have rich text editing in layout
We had a text field in a site that was initially set as single line of text. We needed it to be bigger and also allow formatting. So I added the field into the page layout.
Changing
<SharePointWebControls:TextField id="habitat" FieldName="Habitat" runat="server"/>
to
<SharePointWebControls:NoteField id="habitat" FieldName="Habitat" runat="server"/>
But it doesn't show any rich text editing options and displays the full html tags in the field.
If I open the page in the edit properties screen instead, then the field displays as I want it with the rich text editing options available in the ribbon, and text showing as bolded instead of like this:
<div>This is <strong>the </strong>habitat field.</div>
This is a site using the 2010 Publishing template running in compatibility mode on a 2013 server.
How can I get my page layout to behave the same way as the edit properties screen does?Hi,
Here are two solutions for your reference:
1. We can use the InputFormTextBox control to achieve it.
<SharePoint:InputFormTextBox ID="habitat" RichText="true" RichTextMode="FullHtml" runat="server" TextMode="MultiLine" Rows="20"></SharePoint:InputFormTextBox>
http://blog.qumsieh.ca/2009/01/13/how-to-add-a-rich-text-editor-to-your-custom-application-pages-or-web-parts/
http://blog.mastykarz.nl/rich-text-editor-control-sharepoint-2010/
2. We can use the RichHtmlField control to achieve it.
<PublishingWebControls:RichHtmlField id="habitat" FieldName="Habitat" runat="server"/>
http://msdn.microsoft.com/en-us/library/office/ms561507(v=office.14).aspx
Best Regards
Dennis Guo
TechNet Community Support
Maybe you are looking for
-
Problem with the order of the columns of a ALV
I have a problem with a ALV, variants we keep this ALV does not record the order of the columns Thank you
-
hi all , is there any standard sap script and its print program for billing document (sd). and how to find the standard scripts for a particular requirement. regards reena
-
CAN I CHARGE MY IPOD NANO WITHOUT USING THE APPLE POWER ADAPTER? Can I use any of my many usb wall charging adapters instead?
-
How to use coherence-web with a struts form bean
We are trying to switch to Glassfish 3.1 but when we switch the persistence-type from "replicated" to "coherence-web" our struts applications start failing. The first time we try the application the page loads. But all calls from then on end in err
-
Need a link or doc for ARP. Thanks in advance. Regards, Chandu