I've created an xml template for a report. A user is supposed to be able to add information to personalise this report to their own needs by a program im creating in C#
How can I edit the contents of an entity then from what a user puts into a textbox and then display this on word?
There's a ton of information on the net about creating Word documents using XML and C#. There are lots of possibilities.
Microsoft publishes something they call the "Open XML Format SDK" that helps with this.
Try this search.
This page provides a bunch of "how to" articles summarizing how to fiddle with Word documents using XML and C#.
Related
I am trying to make a word document in an asp.Net MVC application using OpenXML template document .
The main challenges for me are
How can i create a word document as an OpenXML template? In my word
document i have some paragraphs of texts and in every paragraphs i
have to fill information from data base like in word file there are
instances of text like
etc and these should be filled with actual data. But
i dont know how can i convert a normal word document as a OpenXML
template file .
How can i fill the values with data from db ? If i have a model say WordModel in hand with filled values of properties FirstName TotalAmount AmountUnit TotalCopies etc then how can i fill the details to template and allow user to download the file ?
What you want to do is called Mail Merge and means populating word documents that act as templates with your application data. There are some existing (commercial) solutions out there, but if you want to do it yourself using Open XML SDK, you need to set up some kind of tagging mechanism that you will use to tag certain parts of document where you want the data/text from the database should be placed. For Word documents you have the following options: Bookmarks, Content Controls, Merge Fields, or special text (<% FirstName %>). I would personally go with Content Controls as they offer the best user experience and they are pretty easy to parse and replace. So the templates would be ordinary word documents containing these tags and then you could use Open XML SDK to parse these templates, search the tags in them and replace them with your application data according to the tag's name/code/title. This a very abstract, high level picture of a mail merge processor. Of course system like this is not easy to implement and also note that using Open XML requires some learning. There was a similar question answered, but you can probably find many more - just google.
I have following data in variables
1) Patient Name,Age,Sex,Referred by Doctor.
2) TestName,Parameters(As an array) and its results
There are some variables which will be computed using formulas.
I need to send data to printer in the following format
http://www.orthoclinical.com/en-us/Documents/Sample%20lab%20report.pdf
Please point me how to implement the same.
PS: 1) I cant display data directly from Database. There are many derived parameters which will be calculated using formulas.
2)I'm newbie to C# and printing application. Please help me with pseudocode/code
have a look at itextsharp. This is a server side pdf library that uses a document object model to allow you to add your text and styling in a pretty easy manner.
main features:
itext is an open source library that allows you to create and manipulate PDF documents.
It enables developers looking to enhance web- and other applications with dynamic PDF document generation and/or manipulation.
iText is available in Java as well as in .Net and Android.
usages:
Serve PDF to a browser
Generate dynamic documents from XML files or databases
Use PDF's many interactive features
Add bookmarks, page numbers, watermarks, etc.
Split, concatenate, and manipulate PDF pages
Automate filling out of PDF forms
Add digital signatures to a PDF file
available via nuget: Install-Package iTextSharp
I am working on an application that has a requirement for me to create a document, populated with data captured in my WPF application, for attaching to an email and sending to insurance company.
My client has been performing this by sending an editable PDF document to clients then proof reading upon receipt of completed form and manually attaching to email.
I initially thought of creating a word document laid out same format as existing and automating word using find/replace on placeholders such as etc...
However it would be great if I could populate the existing PDF docs wouldn't it.... Anyone know if possible?
Thanks.
You can use PDFsharp/MigraDoc to edit pdf-files. Parsing the existing document and inserting text/images is simple enough, but I don't know if there is any support for actual placeholders.
EDIT: Found this approach, using iTextSharp and form fields: Using itextsharp (or any c# pdf library), how to open a PDF, replace some text, and save it again?
I have a .doc document. In this document i have some blanks for data. For example:
"car_id" is the best car in "car_country".
I need to open this doc file and change this blanks ("car_id", "car_country") to data from some object.
How to do this?
I would use DocumentFormat.OpenXml.dll. You can find it here. OpenXMLSDKv2.msi will add assembly. You will just need to add reference to DocumentFormat.OpenXml. And the OpenXMLSDKTool.msi will install a usefull tool that will display xml structure of .docx (for example) document.
This web page has some very good samples of Word automation using C#. Specifically, look at section 6 in the web page for a Mail Merge example.
http://www.c-sharpcorner.com/UploadFile/amrish_deep/WordAutomation05102007223934PM/WordAutomation.aspx
Okay, here is what i want to do..
A user will run a query and return 3 pieces of data (really more but for this example lets say 3.. such as name, city, state).
The user will then be prompted with a list of 1 or more documents that are basically word merge documents. Does not have to be word but needs to be something standard.
Once they pic the document, we need to merge the data with the document and would then like to have a PDF displayed back to the user so they can print or save.
So, looking for ideas on what would be a suggested format to store the merge documents in as well as how to do the merge and create the PDF via ASP C#.
Thanks!
firstly ... stop thinking "doc" as standard cause .. it is not.
PDF is much more standard than doc and using any online viewer it is easy to provide access to it's content
now...
for manipulating PDF files fore free u have a very nice C# Library called iTextSharp