MS Word mailmerge like functionality to allow export to Word document from ASP.Net Web application - asp.net

I have requirement where I need to allow users to upload a Word document with place holders for certain fields which can be found in the database. This will be their template. For example the place holders might be prepended with ## or something. For example
Dear ##Title ##Lastname
They then can grab a record and hit export to Word document. This will then let them choose the template. They can select the template and then click continue. I will then get the template and replace the ##Title with the title field in the database for the selected record. I am not sure where to start or what components I need to do this.
From my initial investigation it seems that I can do this with the new open XML standard for Office 2007. So perhaps I should read in the template and save all the contents to a db table somewhere. Then when the use wants to export I get the contents again and then do a search and replace for the ## placeholders and link them properly. Then save the document to the output stream again which will then bring up the save dialog on their browser.
I am using ASP.Net MVC and am in a hosted environment. I was also maybe contemplating dynamically creating a new View type and dynamically creating new views when the user uploads a template. Not sure that this approach will work though.
Is this a good approach?
What tools should I be looking at?
Any other suggestions?

This is similar to an approach we took for inserting data into word documents and then returning them to the user. We opened the .docx file (it's a zip file so easy to extract) extracted the document (in the word folder called document.xml), did the replace and then put the document back into the .docx file and returned it to the user.
An issue we hit were that word inserted tags at strange places, especially things like spell/grammar errors, so we needed to be careful when we did the search/replace.
We decided not to store the fields from the document in a database to allow the documents to be easily updated.
We used dotnetzip component for opening the .docx files
Something we also did was to combine several documents into a single large document to save on the number of downloads. If I remember we used the open xml toolkit to do this merging. The website has also got loads of other information that may be of use.

Check out Scott Guthries blog post about the new view engine code named "Razor" coming out real shortly from Microsoft. In the comments there is talk about it being able to be used in mail merge scenarios like you talk about with ASP.NET MVC views.

Related

Drupal 7 webform output in excel

I look for a solution for my client:
Problem:
At this moment people can download on a website an excel file, they put information in and send the excel file back by email to the company. A shorter way would be using a webform, less steps for the visitor - possibility to check if all the information is put in (correctly) - possibility to give information about the data that the visitor has to put in.
Installing/working with webforms i can.
But the information received by the company need to be in a excel file, because a other computerprogram import this information and can only read a excel file.
Question:
Which solution do you see for my problem. I want to offer my client a solution so at the end he will receive and excel file like they do right now. His website will be a drupal 7 with the webform installed.
Is there a possibility to output the information from a filled in webform in a excell file?
Any tips/links are welcome!
If there is a freelancer that can do this job, they may also contact me.
Thanks for reading and answers/tips/suggestions.
Kristof
kristof#firstthings.be
You can use PHPExcel on your custom created form submit process.
Use hook_form_alter for your webform
Add your custom function to #submit array
Use PHPExcel

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 assign a code to each document of Alfresco

I want to assign a small code string to each document after it is uploaded in alfresco. Something like: '2012/314-39414'.
The code will be generated by a rule that depends on the user that uploaded the document, the time the document is uploaded and a unique number which will be incremented after each document upload.
Can I have help to implement this in Alfresco?
Use OnCreateNodePolicy (java code) to do this the cleanest way.
Search the net or Alfresco forums to look for examples or you could download the SDK and lookup current code which uses it.

How can I use an XML file to select dyanmic templates for an ASP.net Repeater?

I am developing an application that has a repeater that will use dynamic templates for each row based on the underlying DataItem (in this case a product). What I would like to do is have some sort of XML file that will store which templates are to be used with which templates, and then use a default template if there is not one specified for the product. My product catalog does not contain a particularly large number of products, but having to open and parse an XML file for each row would almost certainly have adverse performance effects. What I would like to do is have the ASP.net engine compile the entries in the XML file into some sort of global collection that can easily be accessed when needed. Ideally, the application would be able to determine when I have made changes to the file and would automatically recompile the collection and restart the application if necessary. If my understanding is correct, this is already how the engine deals with the web.config file.
Does anyone know if an approach like this is possible, and how I might be able to accomplish it?
Thanks,
Mike
Well you could likely open and parse the XML file on each page load without any significantly adverse performance issues. Toss the result in a page-level collection and for each repeater row, read from that. This will at least prevent you from having to manage a global collection with a file change update dependency.
I do use XML in similar ways, albeit for mostly non-critical company Intranet type applications, so I'd certainly say your approach isn't too awful. :) In my specific cases, I have ultimately put the XML in a global application level object, with the trade off being that I have to manually restart the application to re-load the XML, should it change.
If you do want to tackle your ideal scenario, I would look to store the XML templates in the Cache object and set up a CacheDependency on the XML file.

In ASP.NET what is the best way to convert a PDF file to HTML?

What my users will do is select a PDF document on their machine, upload it to my website, where I will convert into an HTML document for display on the website. The document will be stored in a database after conversion.
What's the best way to convert a PDF to HTML?
I have been handed a requirement where a user would create a "news" story as a pdf and then would upload it to the sever, where it will be converted to HTML and displayed on the website.
Any document creation software that can save documents as PDF can save them as HTML. I'm assuming the issue is that your users will be creating rich documents (lots of embedded images), which results in multiple files, and your requirements stem from a desire to make uploading these documents as simple as possible to the user.
There are numerous conversion packages that can probably do this for you, however when you're talking about rich content, you are talking about text plus images. Those images have to be stored somewhere and served somehow, and whatever conversion method you use will require you to examine all image sources to make sure they point to valid locations on your server.
I would like to suggest an alternate way of doing this that you can take to your team: Implement one of the many blog APIs for publishing content. There are free and commercial software packages that use these APIs to publish content directly to a website, such as Windows Live Writer and Microsoft Word. Your users can simply create their content and upload it directly to your website without having to publish it as PDF first then upload it. So the process becomes much smoother for your users, and you get the posts in a form that doesn't require you spend thousands of dollars on developing or buying conversion code.
The two most common APIs are the MetaWeblog API and the Movable Type API. Both are very simple and easy to implement. I think this way would be a MUCH better alternative than what you're thinking about doing.
I don't think converting a PDF to an HTML string is necessarily the best idea, especially if you want to export it back as PDF. PDF files often contain binary elements such as images, so you may be best to convert it to ASCII via an encoding, such as Base64. That way you will have an ASCII string you can save into a text field in the DB and then convert it back out. Could you expand more on the main requirement?
My recommendation would be to not do it that way IF POSSIBLE (but we all know what managers are like) so...
I would recommend that you stay away from converting the PDF to/from HTML (because unless you can find a commercial solution it will be nigh on impossible) and instead do as has already been mentioned and store it as an encoded Base64 string, or BLOB or some other binary format in the database, and then display it to the user with some sort of PDF view plugin for the browser.
All it took was a simple google search for "PDF to HTML": http://www.gnostice.com/pdf2manyOverview_x.asp. I'm sure there are others.
So while it's 'possible', you may want to explain to your manager that this isn't the best content management solution.
Why not use the iTextSharp to read the PDF content? Then You could save both the binary PDF and the text content to the database. You could then let users search the content and download the PDF.
You should look into DynamicPDF. They have a converter (currently Beta) out for serving exactly this purpose. We have used their products with great success (especially for dumping Reporting Services reports directly to PDF).
Ref: http://www.dynamicpdf.com/

Resources