Add Footnotes with a Word Extension - asp.net

I want to create an extension that runs on Mac and Windows. The extension should insert footnotes at the position of the cursor. As far as I know, Office.js doesn't have a suitable interface for this. I found this in the .NET API Browser (https://learn.microsoft.com/de-de/dotnet/api/microsoft.office.interop.word.footnote?view=word-pia):
public Microsoft.Office.Interop.Word.Footnote Add (Microsoft.Office.Interop.Word.Range Range, ref object Reference, ref object Text);
But the Net Framework cannot be used on Mac. Do you have another solution to my problem?

Office.js can be used to insert footnotes into a Word document. Currently, there is no Footnotes API that would make this easy, but we can still use the Ooxml APIs to insert footnotes into the document.
Here is an example gist that uses Ooxml to replace the current selection in the document with a sample text and sample footnote. I tried my best to separate out the relevant parts of the Ooxml in case you want to modify the code to incorporate multiple texts and footnotes:
Insert footnotes using Ooxml
You can use ScriptLab to import the above gist and play around with the sample.
An Office Add-in solution using Office.js can be used on Mac, along with on Windows, and on Web.

Related

DOORS: Insert OLE with explicit type (aka Show PDF as editable information)

I can insert MS Word files as OLE into a DOORS object, both manually and via DXL, but PDFs (and EPS as well) behave different: it is difficult to make those not appear as icon.
I able to insert a PDF file (showing some graphics) as OLE manually only by using the dialogue's Create New radio button with specifying the type explicitly as Adobe Acrobat Document (without the Display As Icon option). All is well in this case.
Using the radio button Create from File button leads to the same undesired behaviour as using the DXL function insertOle() to insert the object: the result is displayed as icon only.
if (oleInsert(current, "c:\\temp\\27.pdf", false))
print "Successfully embedded document\n"
else
print "Problem trying to embed document\n"
Gives me:
Double-clicking the icon opens the associated application (Acrobat Reader) and shows the embedded PDF properly. However, the OLE properties dialogue displays the type Package. Manual insertion as described above creates an OLE object with the type Adobe Acrobat Document (as specified while creating it).
Inserting a Word document via DXL instead of the PDF makes the embedded document being rendered properly -- apparently the type is determined automatically and correctly:
Apparently, I am not able to (but would have to) specify the OLE type when inserting the PDF.
I am aware of a similar problem at the IBM forum, but the code from there did not even update existing OLE objects but left my objects without any OLE content! Another thread addresses that problem too, but does not provide a detailed solution.
There are two things I would check that would cause a different result for you and your colleague:
Check if they have a full 'edit' version of Adobe Acrobat installed. Since OLE is a Microsoft standard, having Full Acrobat instead of just the Viewer installed may register components with Windows that allow the OLE to display properly for them.
If they do not have Full Acrobat installed, then perhaps they have a different version of the Viewer or a 3rd party PDF viewer that you do not have on your machine.
The DXL reference manual specifically states that An OLE package is created if a file has no associated applications that support OLE. So your system is not recognizing the association, but your colleague's is.
The root cause is still unknown, but the problem was solved eventually. My Windows user account was deleted and created from the scratch. Now it works.
Another colleague has the same problem -- maybe we will take the time and try to isolate file / setting which contained the cause.

Generate Word (docx) Files with from Templates (dotx) on Server Application

I'm currently working on a project where I have to transfer an existing VB program into a Server Application using ASP.NET.
While I had success doing that there's one thing that I'm struggeling with:
The VB Program was using Microsoft Word Interop to generate Excel files and fill Word Templates with data. While i managed to be able to generate the files locally with Interop I can't get it to work for somebody that is accessing the Application from a client.
I also tried using OpenXML to solve my problem but somehow it always said that the file is corrupt after I tried to fill the bookmarks.
In the end the user shoud be able to download the Word document filled with the necessary data.
What would be the best solution for this problem?
If you have mostly the same document structure, you can prepare the whole document in Word. Set placeholders in the document like {Placeholder1} {Placeholder2}, parse the XML and Replace the Placeholders with your text, so you must not generate the whole document structure. Only Replace the Placeholders with your text.

How to feed Word 2010 (.docx) documents/templates with data from MySQL database?

What would be the best approach to replace placeholders in a .docx document (Word 2010) with data coming from a MySQL database?
Can I just open the file using a server side language and do a string replace per each placeholder?
Is there any existing tool/library available?
Thanks
Disclosure: I work for Invantive.
Using Invantive Composition (http://www.invantive.com/products/invantive-composition) you can fill Word documents (letters, legal pleadings, insurancy policies) with data from a database (IBM DB2, Oracle, MySQL, Teradata and SQL Server) and then fully change the contents at will manually. It is intended for real Microsoft Word end-users (both the guys that make the template and the ones that use it) that access the databases through a central webservice and models with queries. Invantive Composition allows nested repeating groups of data and lay-out. Integrates into Microsoft Word using click once.
In the past, I personally have also been using JasperReports (http://community.jaspersoft.com/project/jasperreports-library) to generate letters using the RTF output target of JasperReports. It is free and works fine as long as you do not want to edit the output more than a few words and have Java/SQL development skills. Just as Invantive Composition it works fine for large numbers of different reports.
As long as you can control the environment completely, you can also consider using RTF as intermediate language (not for end-users, only real developers). Save document as RTF, replace parts of the text you need to be replacable, write a webservice that accepts the parameter and dumps back the resulting RTF. Takes some time to generate more complex tables (tables are obviously something invented by the human race after the RTF specification was written :-) This approach only works with very limited number of templates and when you have sufficient developer time available to get it up and running and stabilized.
As an independent reviewer, I have also seen cases where XML templates were used, but the results were not as good as with JasperReports.
**Disclosure: I lead the docx4j project **
There are heaps of existing tools/libraries available!
Yes, you can just do a string replace, but that is a brittle approach, since Word may have split the string across runs.
You can use MERGEFIELDs, or content control data binding.
docx4j supports all three approaches, but content control data binding is the most powerful.
ContentControlsMergeXML
MERGEFIELDs
VariableReplace
One thing to consider especially is "repeats". If you want say a row of a table in Word, for each matching row in your MySQL table, then you need a way to make this happen.
docx4j does this with a "repeat" content control around the table row; whichever solution you choose, I'd make sure up front that it can handle repeats.
If you want to use PHP the most complete available solution is PHPDocX.
You may check in the tutorial how to substitute placeholder variables by data coming from any data source (like a MySQL DB).
In particular, you may populate table rows with an indefinite number of entries and you may delete whole blocks of the Word document depending on the data fed to the application or build dynamical Word charts.
You may check the available DEMO for a simple but quite illustrative example (its inner workings are explained in the tutorial section).
You can use open Open XML SDK and replace your placeholders like this.
Disclosure: I lead the docxgenjs project
I think you shouldn't have to code everything by yourself, that's why I created a Mustache-like templating engine for docx
Demo:
http://javascript-ninja.fr/docxgenjs/examples/demo.html
Repo
https://github.com/edi9999/docxgenjs
It is JS-based and works client and server side.
Yes, you can use server side language to do it.
Check on apache POI.
http://poi.apache.org
Hello I read the above esp the comments and Ivantive looks impressive - but the solution I needed was much simpler. Use Selection.Range.InsertDatabase in Word to fetch records from an access database or excel spreadsheet or even just another word document. With the access solution you can choose the layout of the records to fetch and have it fetch just particular recordds based on a field (eg ID). Google the words above and it'll take you to MS guidance and an example VB script. Worked well in just a few mins. Now looking for VB script that asks the person what ID they want from the dbase and we're done.
it uses docx templates that have merge fields with java objects (the objects have the information you load from mysql or any other source). The xdoc report is an project for java language, the home page of the project is https://code.google.com/p/xdocreport/.
*Disclosure: I create the templ4docx project *
Hello
You can use templ4docx java library, which is on maven central repository, so you can just add it to your maven dependencies:
<dependency>
<groupId>pl.jsolve</groupId>
<artifactId>templ4docx</artifactId>
<version>2.0.0</version>
</dependency>
Example usage:
Docx docx = new Docx("E:\\template.docx");
Variables variables = new Variables();
variables.addTextVariable(new TextVariable("${firstName}", "John"));
variables.addTextVariable(new TextVariable("${lastName}", "Sky"));
docx.fillTemplate(variables);
docx.save("E:\\filledTemplate.docx");
More details you can find here: http://jsolve.github.io/java/templ4docx/

Reading a MS Word file in Qt

How can I read a Word (.doc) file in Qt? I want the text to appear formatted exactly like the Word document without any loss.
Take a look at this Microsoft Knowledge Base article, it describes where the documentation for the ActiveX objects can be found. ActiveX Widgets can be accesed from Qt via the QAxWidget, queries are issued using QAxBase::querySubObject().
Edit: And take a look at this answer. It adds some code samples to my answer.

Problem using Interop Range.Find when range contains table

I'm trying to write a word add-in (with C#) that searches a document for all occurrences of certain pieces of text and makes some changes to the sections of text it finds.
I've created a loop that uses Range.Find to get all of the ranges in the document that contain a piece of text and the use the range objects it returns to do the manipulation later. A problem comes up when there is a table in the document, though.
In my first attempt at this, I just kept creating a new range, from the end of my last found occurrence to the end of the document and then searching again in that new range until it returns no found values. When I did this with a document containing a table, it just got stuck inside the table and created an infinite loop.
Then, I found this article: http://www.codeproject.com/KB/office/wordaddinpart1.aspx, and when using the Find function the article describes, it successfully continues on through a table, but unfortunately doesn't successfully grab all of the values within that table, which I need it to do.
Does anyone have any advice about getting around this problem? I've seen a couple people talk about having this problem, but no solutions.
I would suggest using the OpenXml SDK for this. The Office interop is a relic. Here's an article that explains how to use the OpenXml SDK to search a Word document:
http://msdn.microsoft.com/en-us/library/bb508261.aspx
Here's an SO question that discusses how to replace an image in a Word document using the OpenXml SDK:
Replace image in word doc using OpenXML

Resources