Mail Merge with Open Office from C# .NET - c#

I need to be able to mail merge from an ASP.NET web form in C# .net to Open Office. I can connect with OpenOffice and open a file but that is where things stop at the moment. I have a table of mail merge items that need inserting into a document for each client on my system but I can't find anything on the internet that helps me perform the mail merge or even how to set the mail merge up.
If anyone can show me a simple example merging forenames and surnames out of a database table into an Open Office mail merge form using C#, I would be very grateful.

Try looking in the Open Office Forum for Code Snippets. There are a lot of C#-examples and if you don't find something you can use, I would propose to post the question there (if you haven't already).
Documentation about MailMerge-Datasources is here.

You may find AODL ODF Toolkit useful. I use extensively the Java version to manipulate ODTs.

Related

Creating docx OOXML with c#

I was hoping for a good point in the correct direction, as this is something I have never done, and googling is getting me tied in knots.
I want to create a word document (docx) from C# on a ASP.NET MVC application.
Populating a template with something like mail merge would be great.
I have spent day googling this and keep finding archived documentation.
The following examples are from 2012
https://msdn.microsoft.com/en-us/library/office/bb491088.aspx
Because you will generate documents on the server you should avoid Interop for document manipulation. You can use free libraries and SDKs based on OpenXML but this is difficult to learn and error prone.
It probably makes sense to choose one among 3rd party toolkits to get the job done quick and easy. Start by preparing MS Word template documents with placeholders for data. Then you can use c# to load the data for the reports and merge the data with templates to get final documents (docx, pdf, xps or image formats). Here is the code used by one such toolkit needed for merging data from the database with the template to get a pdf document:
IEnumerable<Customer> customers = DataAccess.GetCustomerById(15);
DocumentGenerator dg = new DocumentGenerator(customers);
DocumentGenerationResult result = dg.GenerateDocument("MyTemplate.docx", "MyReport.pdf");
You can also see these examples for more information.
Maybe Templater can be of help..
This is small library you can use to create word document on ASP.NET looking like mail merge...
Try demo http://templater.info/demo

Complex reports from C# programatically into office Word

First of all I want to say hi to the programming community, what I am looking for is a way to generate a report from my Windows Forms Application in word preferably, this report is basically a list of pre-configured days in a tour creation software I am creating.
I have searched everywhere and I cant seem to find information on how to start creating the report, I have all the information saved into a database, I just need to be able to get this information into word and ordered as it should be ordered.
I just want to be pointed in the right direction so I can research on it even further.
The exact thing I want to create is a word file that I wish I could share here so you can actually see what I mean.
Thank you for all your attention and help if possible.
I can point you in the right direction. Word documents are stored in a format called OpenXml which can be created and manipulated without actually using Word directly. That's good because you don't want to deal with code that actually starts an instance of Word and automates it (Interop.) It sort of works but it's not something I recommend dealing with ever.
OpenXml isn't fun either, but it's better. You can create your document "normally" using Word, save it, and then have your application use it as a template, opening a copy, populating some data, and then saving it.
Here's the reference for OpenXml with Word. I'm not saying it's pretty. It's not. The documentation is lacking. This page on adding text isn't linked from the previous page, even though many other topics are.
There are some nuget packages like this one that can help.
I once did a POC that did exactly what you're describing by opening and altering a document used a template using OpenXml. I'll see if I can dig up the code. But this is definitely a good direction to look in if Word is an absolute requirement.
This is a long shot, but can you output in HTML? If you can that's an even easier alternative.
Can you use Excel? That's also OpenXml but there's easier-to-use tools like EPPlus that simplify dealing with it, because it's not just the friendliest thing to work with.
An option that I would suggest is Crystal Reports. You can download the Crystal Reports add-in for Visual Studio for free from here. Crystal Reports is an easy way to perform reporting from various data sources including SQL. There are also a lot of free tutorials online for learning how to use CR. The syntax is a little strange, but it is easy enough to use.
The add-in allows you to create reports for your application and also build applications that can display, print, and export Crystal Reports.
You can export reports to .RTF (Rich Text Format) files. MS Word can open, edit, and convert RTF documents. It does a fairly decent job, but special formatting might take some work. This route is a ton easier than trying to write XML or anything else. I've written several reports designed for export to RTF. My boss runs the report, exports it, then edits it in Word. He loves the reports.
If you are planning on developing a lot of reports, purchasing the full version of Crystal Reports is well worth it. I believe they are on version 2016 currently.
If you do want to deal with automating Word, Microsoft's guide "Automating Applications Using the Office Object Model" Word-specific task content is here: https://msdn.microsoft.com/en-us/library/78whx7s6(v=vs.80).aspx
A larger example: https://support.microsoft.com/en-us/kb/316384
To begin, simply add an assembly reference to your project file for the correct Office Object Library (example: "Microsoft Word ##.0 Object Library"). Note that you must have Office installed to take this approach.
Good luck!

Office 2013 Web Apps - Standalone redistributable document

Please consider a case as show in the image below...
I have two different apps (content + navigation) in a same excel sheet that are able to communicate with each other,
Based on this scenario, following are some questions...
1- Is it possible to deliver an excel document (standalone) which contains both of these apps, so that the end user doesn't need to insert these apps from the ribbon toolbar and user could be able to use this document on any machine (without any configurations and involving the app store/network)?
2- Is it possible to automate the process of generating excel documents that contains both of these apps? My purpose of doing this automation is to change the data contained in excel sheets, and user can perform analysis with his data.
Thanks!
Asif
I asked the same question on msdn forums and got some feedback by them, you may follow the link below for details...
http://social.msdn.microsoft.com/Forums/office/en-US/057723f1-cfe5-4f41-9d7a-430cb2f0c4c6/create-a-distributable-excel-document-with-web-apps?forum=appsforoffice&prof=required
Based on these details, my understanding is that Office 2013 web apps don't currently support standalone deployments packaged with local html files. But in future they might think of providing support for disconnected mode web apps in Office 2013.
Your comments are welcome!
Thanks,
Asif

creating word documents from a winforms application

I have a C# winforms application with a sql server backend and want to be able to create word documents from within my application and populate them with basic information like addresses, references etc. I've been browsing online for ideas but am struggling getting started on this subject.
Could someone please point me in the right direction.
As a starting point go to this link Office Development With Visual Studio
then download and install the requested libraries.
The subject is very broad and cannot be answered with precise details.
However just as you have requested, this is a direction:
Create a DOT document and fill it with MergeFields where the data from
SqlServer will be written to.
Add the references to the Office Interop Word library in your project
Declare the required Application and Document instance vars
Read your data from the database and open the DOT file using the Office Word library
Search in the DOT file the relative MergeField and update its text
Save the DOT file as document in your folder.
As you can see, each of these steps worth questions by itself. So you have a lot of work to do
What you need to look for are Report Designers , where you can edit them from code and export in many formats including word , pdf etc.
you can look for Crystal Reports , Devexpress XtraReports and also there are many that are free .

Display Excel 2007 Document in Browser using COM

I want to display and edit MS Excel File from client side using ActiveX COM object. The user would be allowed to edit the file and save it to local PC. Then It can be uploaded to remote server.
So, can you give me some example of displaying Word, Excel, Powerpoint etc document in Internet Explorer 8.0 using COM. I could not find such ocx files for that purpose . Can you help me finding it.
Thanks
Maksud
I think those controls would violate the MS Office distribution or EULA licensing agreements with Microsoft. Since an ActiveX control that emulates Word, Excel, PowerPoint would potentially give unlimited and anonymous users access to the software without paying for it. There's other Microsoft technologies that allow you to leverage the end-user's MS Offices licenses that allow them to save back to the web server. I think WebDAV used to be used (http://technet.microsoft.com/en-us/library/cc781730%28WS.10%29.aspx), I don't know what's out there now, but I'm sure there's a solution.
I wonder if the use of Google Docs would solve these issues. I'm pretty sure there's a way to leverage some sort of mix of Google Docs and the associated APIs to do something akin to what you are trying to do. I admit this isn't quite a perfect match for your goals.
This sounds like a use case that Office Live Workspace was created for. It's free, it's collaborative, and it allows you to determine sharing permissions.

Categories