Infopath Multi Textbox and OpenXML to generate word document
Hi,
I'm reading multiple InfoPath Textbox (set to display multiple lines) using OpenXML and generating a word document based on a template collecting data from InfoPath. I'm using following code, the code gives error in
AddMultiLineText at Paragraph p = sdt.GetFirstChild<SdtContentBlock>().GetFirstChild<Paragraph>();
The code actually works when I use only one Multi Textbox but fails if its more than one. I'm quite new to Infopath and OpenXML, I would appreciate some help ASAP as its holding me in my project:
Event Receiver
public override void ItemAdded(SPItemEventProperties properties)
try
this.EventFiringEnabled = false;
string siteUrl = properties.WebUrl;
SPListItem item = properties.ListItem;
SPWeb web = properties.Web;
SPList lib = web.Lists["DocLib"];
SPFile file = lib.RootFolder.Files["template.docx"];
string generatedDoc = "";
if (file != null)
byte[] templateBytes = file.OpenBinary();
using (MemoryStream ms = new MemoryStream())
ms.Write(templateBytes, 0, (int)templateBytes.Length);
byte[] convertedDocBytes = ConvertInfoPathToWord(ms, item.File);
generatedDoc = item["LinkFilename"].ToString().Replace("xml", "docx");
SPFile newFile =
lib.RootFolder.Files.Add(generatedDoc, convertedDocBytes, true);
ms.Close();
private byte[] ConvertInfoPathToWord(MemoryStream ms, SPFile file)
byte[] bytes = file.OpenBinary();
using (MemoryStream msInternal = new MemoryStream(bytes))
XmlDocument doc = new XmlDocument();
doc.Load(msInternal);
XPathNavigator root = doc.CreateNavigator();
root.MoveToFollowing(XPathNodeType.Element);
string ns = root.GetNamespace("my");
XmlNamespaceManager nsMgr = new XmlNamespaceManager(new NameTable());
nsMgr.AddNamespace("my", ns);
string multiLineText1 = root.SelectSingleNode(
"/my:myFields/my:field1", nsMgr).Value;
string multiLineText2 = root.SelectSingleNode(
"/my:myFields/my:field2", nsMgr).Value;
using (WordprocessingDocument myDoc =
WordprocessingDocument.Open(ms, true))
MainDocumentPart mainPart = myDoc.MainDocumentPart;
List<OpenXmlElement> sdtList = InfoPathToWord.GetContentControl(
mainPart.Document, "multilinetext1");
InfoPathToWord.AddMultiLineText(multiLineText1, ref sdtList);
List<OpenXmlElement> sdtList = InfoPathToWord.GetContentControl(
mainPart.Document, "multilinetext2");
InfoPathToWord.AddMultiLineText(multiLineText2, ref sdtList);
myDoc.Close();
msInternal.Close();
return ms.ToArray();
public static List<OpenXmlElement> GetContentControl(
Document doc, string name)
List<OpenXmlElement> list = new List<OpenXmlElement>();
List<SdtBlock> sdtList = doc.Descendants<SdtBlock>()
.Where(s => name.Contains(s.SdtProperties.GetFirstChild<SdtAlias>()
.Val.Value)).ToList();
if (sdtList.Count == 0)
List<SdtRun> sdtRunList = doc.Descendants<SdtRun>()
.Where(s => name.Contains(s.SdtProperties.GetFirstChild<SdtAlias>()
.Val.Value)).ToList();
foreach (SdtRun sdt in sdtRunList)
list.Add(sdt);
else
foreach (SdtBlock sdt in sdtList)
list.Add(sdt);
return list;
public static void AddMultiLineText(
string multiLineText, ref List<OpenXmlElement> sdtList)
string[] lines = multiLineText.Split(new char[] { '\n' });
if (sdtList.Count != 0)
foreach (OpenXmlElement sdt in sdtList)
for (int i = 0; i < lines.Length; i++)
Paragraph p =
sdt.GetFirstChild<SdtContentBlock>().GetFirstChild<Paragraph>(); //this ERRORS
if (i == 0)
InfoPathToWord.WriteText(lines[i], ref p);
else
Paragraph pNext = sdt.AppendChild((Paragraph)p.Clone());
InfoPathToWord.WriteText(lines[i], ref pNext);
Additional Info: multiLineText1 and multiLineText2 are "Plain Text Content Control" in the word template used to create the word document.
Similar Messages
-
Using and Apex developed system and generating word documents
Started a new development project. We looked at using Apex for the system but ran up against a road block because the customer needs to generate word documents that they can edit and print. Does anyone know if Apex can handle this? Any suggestions on were to look for more information.
Hi Dawn,
Yes you can certainly do that, take a look at this quick overview -
http://www.oracle.com/technology/products/database/application_express/html/configure_printing.html
It refers specifically to PDF printing, however with BI Publisher you can output in Word Document format too.
Hope this helps,
John.
Blog: http://jes.blogs.shellprompt.net
Work: http://www.apex-evangelists.com
Author of Pro Application Express: http://tinyurl.com/3gu7cd
REWARDS: Please remember to mark helpful or correct posts on the forum, not just for my answers but for everyone! -
Early watch alert - problem with generating word document
Hello experts,
since last week I am not able to generate word documents of early watch reports. I have access to 4 different solution manager installations (of customers) where the generation was working without problems but stops since last week.
SAP gui starts word and the standard word sheet is loaded (SAP early watch start page) but without putting data into the sheet. At the same time I get an error message in the sap gui saying:
Error during download; read details in long text
Long text:
Message no. DSVAS824
Diagnosis
The application was unable to write a file to a local directory.
Procedure
Often the maximum length of 128 characters for the entire file name, which is defined internally, is exceeded. To avoid this problem, you can change the setting.
To do this, open Microsoft® Word.
For English interfaces, choose Tools->Options->File Locations->User templates.
For German interfaces, choose Extras->Optionen->Speicherort für Dateien->Benutzervorlagen.
Recommendation: Use directory names with a maximum of 60 characters (For example C:Program FilesMicrosoft OfficeTemplates)
I have already maintained the path in word options (we use Word 2007). My colleagues have the same problems.
Any ideas or hints? Thank you in advance.
BR, BastiHi all,
SAP is aware of this problem and is working on a fix.
For a ***temporary workaround**
run se38
RAGS_DSWP_SERV_CONTENT_RESET
(De-Activate content until 26.05.2011 07:28:06
Execute
This will allow you to open the report on a temporary basis. -
How to generate Word document from JSP ?
Hi,
I want to generate Word documnet from JSP. I am using Neva objects to generate Word document. Now my problem is Word doc generation code works alright as a Java application but when I place that piece of code in a JSP bean it throws an exception. The reason seems to be unavailibility of DLLs and other files of Neva in Tomcat environment. I do not want to use other complex packages like JIntegra, I would prefer any freeware solution. There is not much info. about Word document generation on POI project in Jakarta site.
Could anyone suggest way out ? Any Java examples doing the same would be of great help.
Thanks,
AkashHi Saurabh,
Thanks for the reply.
I have tried that too. Problem with that solution is that if you have used CSS in your JSP code MS word does not understand it and generates word doc which is not the same as HTML which JSP otherwise would have generated.
Akash -
Regarding "Generate Word document"
Hi,
I have one layout of xml publisher. In the layout I have made the page setup as
Margins:
Top - 0.3 Bottom - 0.3
Left - 0.5 Right - 0.5
and in Layout tab I have
Header - 0.3 Footer - 0.3
I have attached this layout in the Templates tab of XML Publisher responsibility.
But when I am trying to Generate Word Document of my report, The layout and margins gets distorted.
The Margins change to
Top - 0.42 Bottom - 0.4
Left - 0.46 Right - 0.46
and in Layout tab I have
Header - 0.5 Footer - 0.5
Please help me out how can I control the header and footer of my report. Your ideas are welcome at [email protected]
Thanks.
Edited by: user5427917 on Nov 7, 2008 12:27 PMHow are you generating the Word documents, manually? I haven't used it, but it looks like docx4j might be good library for building the documents. General documentation can be found [here|http://dev.plutext.org/trac/docx4j/wiki], description of [Java API|http://dev.plutext.org/docx4j/javadoc-2.2.2/] and here's the [download|http://dev.plutext.org/docx4j/].
Cheers, harald -
I have a office addins which works seamlessly in excel, powerpoint and outlook except in word . We have a option to create a word documents using the templates in a dialog which is opened from addin. And we have an option to set the work area for
our webapplication either to use filestorage or sharepoint storage.
Again the same addin works perfectly with filestorage cache but the same doesn't work with sharepoint storage. the problem is when we create the new documents using the templates it produces the new word document, once it is created and opened, the parent
word document and the intermediate dialog window should get close but instead it hangs both of them. when i try to close it explicitly it says word has stopped working.
Issue is with sharepoint 2010+Sharepoint storage and the same is not working with sharepoint 2013 as well as it by default uses sharepoint storage.
I have posted in the VSTO forum before but I haven't got the response yet. please help me this is a major and critical issue for us.
PS: irrespective of OS its not working.
code to produce a file
function ProduceFile(strFileUrl) {
var obj = new ActiveXObject('SharePoint.OpenDocuments.3');
obj.EditDocument(strFileUrl);Hi ShilpaSheshadri,
if this is a quite urgent, i may suggest to open a ticket directly, so that we can have a remote session to check this up. http://support.microsoft.com
i checked some forum such as:
http://social.msdn.microsoft.com/Forums/vstudio/en-US/e2c801c0-6120-432c-97d5-8d59a43ce7f3/thisaddinstartup-is-not-executed-when-open-ms-word-template-using-vsto-from-sharepoint-2010?forum=vsto
perhaps you can also try to use other workaround,
http://blog.qumsieh.ca/2012/11/05/link-to-a-document-opens-in-read-only-mode/
to check, please have a check if this issue was also shown in other client machine or other client browser version.
Regards,
Aries
Microsoft Online Community Support
Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread. -
How do I begin with a template and then import a Word document?
I know I can open a word document in pages (I do this all the time). But I have a specific template and I want the word document I open to take up the designed elements of the template. How do I do that?
George
You can import the styles from another document:
+Menu > Format > Import Styles…+
but it will come down to what you need to retain from what.
You can not import layout or elements, so you will have to work out which holds most of what you want and import the styles from one and apply that or copy and paste into the document that contains most of the work.
Don't forget you can use the thumbnails to copy across whole pages/sections.
This is where Pages extremely weak and poorly thought through layout methods fall down. You will not be able to apply the master pages and master page layouts, to existing work, that you can in other DTP software.
Peter -
How to save and work with a Word document stored in the Oracle 8i Database?
Hi,
If you have any experience with saving and working with a Word document (stored in 8i) from Forms 6.0, then please let me know how.
Thanks ...
Peter Nielsenhi
i had worked storing word documents in oracle8i.tell me what exactly u want to know.
null -
How do I download and work on a Word document?
How do I download and work on a Word document?
Download from where? The internet or ?
Second, in order to work on a Windows file, you need software that will be able to do it - I'm sure there are more - this is one: Pages (iWork) or install a Windows version. -
Insert and activate a phone number in a generated word document
Hey guys,
I would like to add a phone number to a word document that I generate using the mso api.
In word, when one writes (Tel:00493298402938) and new line, the phone number is activated automatically.
While trying to record the corresponding macro and check the VBA code, it doesn't show the same behavior and the phone number is interpreted as a normal text.
Any helpful source code in VBA, C# or C++ is welcome.
Thanks!Hi Cindy,
It worked. I added a lync addin in word. and used:
HyperlinkPtr Add (
IDispatch * Anchor,
VARIANT * Address = &vtMissing,
VARIANT * SubAddress = &vtMissing,
VARIANT * ScreenTip = &vtMissing,
VARIANT * TextToDisplay = &vtMissing,
VARIANT * Target = &vtMissing );
with the second parameter "tel:002123049034" instead of just the phone number. -
Auto-generating word documents from word templates
How would one go about generating a word document based off of a word template (.dot)? For example, I have a simple JSP form which has a field "Last Name". When submitted, the "Last Name" is plugged into a corresponding bookmark in a .dot file. Then the .dot file is saved as a .doc file and presented to the user for download. So, breaking it down:
1. User fills out a jsp form with "Last Name" and hits the submit button
2. The submit button triggers a routine to:
a. open a .dot file on the server (static location)
b. find the bookmark where the last name should be plugged in
c. plugs the value of last name
d. saves the .dot as a word document
e. presents to the user for download
Has anyone done a similar thing before? Any pointers?There's a lot of templating projects around that are usable in Java. I'm not aware of any that use closed proprietary technology like Word and I wouldn't base my design on that either. If you're stuck with that idea then I don't have any suggestions.
-
Generated Word document from Robohelp HTML
Hi Everyone,
I have two questions regarding the word document i have
generated from RH HTML.
First, in my Word document which i have generated from RH
HTML my footer is not displaying the one i have used in online
help.
Second, the hyperlinks i have in my online help, they are
also not displaying in the Word document.
I would appreciate if anybody who knows the answer to it and
can please let me know.
ThanksHeaders and footers are not transferred across.
Hyperlinks are only available in RH6 or better.
Take a look at the topic on Printed Documentation on my site. -
Blank pages in generated Word document
I am using RoboHelp and I have created a document similar to
others that I have created. I generate printed documentation to
Microsoft Word, and it seems to have extra blank pages scattered
throughout the document. When I edit it with Word, I see these
Section Breaks that are in there. I have to delete those and then
re-format my page breaks to get it to work right. This is a real
pain to do especially if I have to make updates to the document
(which I know I will have to do). Any ideas as to why this is
happening all of a sudden? There is really nothing unusual about
this document but perhaps I am missing an option or something is
extra that shouldn't be there.
Thanks for any help!
EvelynI think a read through this should help. See also the
associated Print Issues topic.
Click
here. -
How to click a label and pop up a Word Document
hi!
i know this question has been asked many times...i did a search...but got alot of stuff that were either too much for me to read...or too tough for me...
i hope i can GEt some help here!
i am in a rush..thats why i opted to post it here instead.
question is:
i have a JLABel. hwo to create a link that once i click on it... a MS word DOC will open??
i already have the doc. file made...but need to link it to the label..such that once its clicked, the doc is opened...
thanks alot!!!A very important message about problem solving: Divide and conquer.
Stop thinking "clicking a label and open a word document".
Think
- "Clicking a label, and do something"
- "open a word document from a java program".
Go on, and think
- "How do I make my program notice when a specific label gets clicked"
- "What external command will open a word document?"
- "How do I run an external command from a java application?"
Look at the hints you've got. Read the documentation for the classes and methods you've been pointed towards. Look them up in the index in a good book. Read the tutorial. Write code. Experiment. Maybe come back here if you get stuck on something specific. -
Copy and paste from a word document to calendar?
hello, I'm just wondering if anyone knows if it is possible to store/view a word document on an iphone as well as be able to copy text from that doc & paste it to a calendar event? thanks!
dpetersman wrote:
Thanks for your reply!
im curious tho, i saw an instructional video about how to copy and paste on the iphone. it said to hold down on the begining of the text area you'd like to copy to "zoom" then tap the screen with a second finger. then repeat at the end of the text area. Was this incorrect? Also, you mentioned you can save via e-mail, the files i need to access are e-mailed to me as a .doc attachment weekly. if i simply saye the file in e-mail would i be able to view & access it at another time? The copy & paste thing isn't the end of the world, but being able to view these files is a feature i can't do without.
thank you again for your input!
That was either a hypothetical implementation from a fan or just a fake rumor.
Maybe you are looking for
-
Help me-Export HDV to WHATEVER looks like utter garbage!
Hi, I'm currently on FCP Studio 2, latest software updates, Tiger, PowerMac Dual Core G5. I'm editing HDV 1080/50i material. Like all HDV, there's a few spots where you can see chroma noise but overall the footage looks quite good. Now, what I used t
-
I have a problem relating to IM-WM inconsistency of stock. When looking into the issue, i could find that the material document posted with 923 movement type (removal of excess stk.) at the IM level which is for stock adjustment, was not updating the
-
Synching Notes with MobileMe?
I have been trying to set up Note app synch between my girlfriend's iPhone(3Gs) and iPad. Phone is updated to 4.2.1, iPad is new. Here's the problem: In General>Mail,Contacts,Calendars, I select her MobileMe account, and then select Notes ON. No Defa
-
Hi All, I want to know if IDOC processing support the parameter which BAPI processing consider ? Regards, Ranjita
-
IPSec Password discarded in 3.0
Ever since the 3.0 upgrade any IPSec VPN configuration created with a username and password seems to discard the password which is saved into the configuration at the first connection attempt i.e. I create a new VPN config, save it with a username an