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.

Thu Feb 25, 2016 4:16 pm

1. Do we have an option to insert html using mail merge. This feature is provided in Aspose - (Aspose provide this facility: how-to-insert-html-using-mailmerge

2. We are getting Null Reference Exception when using Paragraph.AppendHtml(). Can we get help in that?

3. Do we have an option to get word count for PDF and Excel ?

We are in final phase of evaluating the spire.net for our applications. This information will be very useful in determining the way to go.

A quick response is much appreciated !!

mturumella
 
Posts: 21
Joined: Fri Jan 22, 2016 2:28 am

Fri Feb 26, 2016 9:06 am

Hi,

Thanks for your posting.
Please try the following solution to insert Html using MailMerge.
Code: Select all
 static void MailMergeForHTML()
        {
            Document doc = new Document();
            doc.LoadFromFile("..\\..\\sample.docx");
            string[] filedNames = { "HtmlField"};

            string htmlfile = "..\\..\\1.html";
            StreamReader sr = File.OpenText(htmlfile);
            string htmltext = sr.ReadToEnd();
            sr.Close();

            string[] filedValues = { htmltext };

            doc.MailMerge.MergeField += new MergeFieldEventHandler(MailMerge_MergeField);
            doc.MailMerge.Execute(filedNames, filedValues);
            doc.SaveToFile("result.docx",FileFormat.Docx2010);
            System.Diagnostics.Process.Start("result.docx");
        }

        static void MailMerge_MergeField(object sender, MergeFieldEventArgs args)
        {
         
            if ( args.FieldName.StartsWith("Html"))
            {
                args.CurrentMergeField.OwnerParagraph.AppendHTML(args.FieldValue as string);
                args.Text = "";
            }
        }


Sorry that we have no options to directly get word count of PDF or Excel. But, for PDF, you can use page.ExtractText() method to get all text of PDF and then calculate the word count of the text.
Sample code:
Code: Select all
static void GetWordCountFromPDF()
        {
             PdfDocument doc = new PdfDocument();
             doc.LoadFromFile("..\\..\\Test.pdf");
             StringBuilder sb = new StringBuilder();
            foreach(PdfPageBase page in doc.Pages)
            {
                sb.Append(page.ExtractText());

            }
         
            int count = GetWordCountFromString(sb.ToString());
        }
        static int GetWordCountFromString(string text)
        {
            if (string.IsNullOrEmpty(text))
                return 0;

            //Count the words
            return System.Text.RegularExpressions.Regex.Matches(text, "\\S+").Count;
        }


For Excel, you can use sheet.SaveToFile("ExceltoTxt.txt", " ", Encoding.UTF8) method to convert Excel to text and then calculate the word count of the text.
http://www.e-iceblue.com/Tutorials/Spir ... B.NET.html


Best Regards,
Amy
E-iceblue support team
User avatar

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

Fri Feb 26, 2016 2:29 pm

Thank you we will check and get back to you. Do you have any plans to include the word count feature for PDF and Excel in future releases ?

mturumella
 
Posts: 21
Joined: Fri Jan 22, 2016 2:28 am

Mon Feb 29, 2016 1:36 am

Hi,

Thanks for your response.
Sorry that at present we have no plan to include word count feature for PDF and Excel. We may have the plan to add it in the future, anyhow, we will tell you when it is supported in the future.

Best Regards,
Amy
E-iceblue support team
User avatar

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

Return to Spire.Doc