简体   繁体   中英

How to edit and print a word or pdf document using C#.net?

I have a huge collection of database of my customers in MS access. I have made a custom mail (print mail) formats. In each format, I've generated separate fields for each dynamic field.

Example:

 __________________
|                  | 
|                  |
|      LOGO        |
|      IMAGE       |
|                  |
 __________________

=====================================================

Dear %customername%,
      Your age is %age%. bla bla bla..

Thank you!

I want to programtically detect %customername% field and fill it with each name from the database and finally print it.

How can i accomplish this without using any external libraries in C#.net?

You need the String.Replace Method

string customername = "Paul Jones";
completeText = completeText.Replace("%customername%", customername);

@Carspar's answer is the simplest method that would work, although one would probably not use string if you have to do a lot of replacements of a large amount of text. Another built-in library that may be of interest is using Razor library from ASP.NET MVC 3. There are some external libraries built on top if you don't mind use 3rd party assemblies. http://razorengine.codeplex.com/

Look into microsoft reporting services SSRS, that is exactly what you need. Microsoft provides a free .NET library for SSRS: http://msdn.microsoft.com/en-us/library/ms159106.aspx

Detecting any variable field that starts and ends with % can be done using a regular expression. With regular expressions you can easily find the name within the % block.

Regular expression information

Having the name you can match that to a database field and replace the value using string.Replace() or the regex.Replace() functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM