Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sat Oct 27, 2012 12:39 am

I just downloaded your trial Spire.Doc and I am evaluating mail merge functionality. I am also trying the Aspose library too before I purchase anything but so far your library is going to be the one we purcahse if all evaluates well. So far the mail merge is very simple in your library. I just have one small issue that I am hoping you can help me resolve. I am calling the mailmerge function which only takes an array of strings. One of my MergeFields in my word document is a placeholder for an image and I really don't want to have to create a ton of sperate word documents for every image I have (various brands images and lines of business US and Europe). What is the best way to merge an image object in a word document that has a mergefield for image placeholder?

sebastian.metchikian
 
Posts: 3
Joined: Fri Oct 26, 2012 11:35 pm

Mon Oct 29, 2012 10:55 am

Hi,

Thanks for your inquiry. We have attached a demo for you.
In the demo:
1. Define some mailmerge field for image, for example: Image:Photo
2. In you data for merging, there is the image name and path for the MailMergeField, please see the element Photo in the Orders.xml file.
3. Load the image during maile merging:
Code: Select all
            document.MailMerge.MergeImageField += (obj, field) =>
            {
                string filePath = field.FieldValue as string;
                if (!String.IsNullOrEmpty(filePath))
                {
                    field.Image = Image.FromFile(String.Format(@"..\..\{0}", filePath));
                }
            };

If you still have any problem, please tell us.
Harry
Technical Support / Developer,
e-iceblue Support Team
User avatar

harry.support
 
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm

Mon Oct 29, 2012 8:06 pm

That worked perfectly.
Thank you.

If you don't mind I have another question:

I am writing software that allows our business users (non-technical) to be able to modify word documents as mail merge templates (business users are very familiar with word and is easy for them to use) and then I convert them to html for the body of emails and I also convert them to PDFs for attachments to emails. I have been using regular word libraries but we are having some type of memory problems because the garbage collector is not cleaning up properly using word automation.
So have said that, what I have done is replace my word automation code with your spire.word library.
The PDF looks great but the html does not look so good. I attached an image of the original word document and I also attached an image of the html email. It looks like the line spacing wrong and it also looks like indented lines are not working properly.
My goal is to not have the business users (non-technical) be constrained by technical rules when formatting their word template. Basically I want them to be able to draft a word document however they want it to look and I want that document to be rendered the same in HTML. Now I know that there will be occasional issue because HTML is different than a word document but within reason. Tabs and line spacing shouldn’t have to be an issue. The old word automation code rendered the HTML perfectly fine.
What are your thoughts about this and am I doing something wrong in my code?
Here is the code I am using:
public static void MergeWordTemplate(string WordTemplate, Dictionary<string, object> FieldValues, SaveTypes SaveType, string SavedFileName)
{
var document = new Spire.Doc.Document(WordTemplate);
document.MailMerge.Execute(FieldValues.GetDateRow());
switch (SaveType)
{
case SaveTypes.Html:
document.SaveToFile(SavedFileName, Spire.Doc.FileFormat.Html);
break;
case SaveTypes.PDF:
document.SaveToFile(SavedFileName, Spire.Doc.FileFormat.PDF);
break;
}
}

sebastian.metchikian
 
Posts: 3
Joined: Fri Oct 26, 2012 11:35 pm

Tue Oct 30, 2012 2:08 am

Hi,

Thanks for your inquiry.
We can not work out a solution only with below information you provided, could you provide your original word template for us? So that we can reproduce your problem, and give you a solution as soon as possible. Thanks.

Best regards,
Amy
E-iceblue support
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Oct 30, 2012 8:38 pm

I found out what was going wrong. The css is being seperated into a seperate file. Do you know of a way of including the css inside the html document via potentially a function argoument? If not that is ok because I can write code to inject the css myself.

I can move forward with recomending this library to my boss so that we can move forward with purchsing this product. Thank you for all your help and quick responsed. Thanks again.

sebastian.metchikian
 
Posts: 3
Joined: Fri Oct 26, 2012 11:35 pm

Wed Oct 31, 2012 2:40 am

Hi,

About your requirement, we provide you below sample code. If you have any problem, please feel free to contact us.
Code: Select all
            document.HtmlExportOptions.CssStyleSheetType = CssStyleSheetType.Internal;
            document.SaveToFile("sample.html",FileFormat.Html);


Best regards,
Amy
E-iceblue support
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Thu Nov 29, 2012 1:54 am

Hello,

We are wondering whether your problem has been resolved. If you still have the problem or you encounter others problems, please feel free to contact us.

Best regards,
Amy
E-iceblue support
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc