Click here to Skip to main content
15,917,455 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralHow to convert HTMl Div to word Pin
abjchr12-Feb-15 22:33
abjchr12-Feb-15 22:33 
I need to convert html div content to ms word in below code C# Microsoft.office.interop.word.htmldivision add invalid parameter error occurred.

XML
StringBuilder objStrBuilder = new StringBuilder();

            objStrBuilder.Append("<table>");
            objStrBuilder.Append("<tr>");
            objStrBuilder.Append("<td>");
            objStrBuilder.Append("HP");
            objStrBuilder.Append("<\td>");
            objStrBuilder.Append("<td>");
            objStrBuilder.Append("HP computer");
            objStrBuilder.Append("<\td");
            objStrBuilder.Append("<\tr>");

            objStrBuilder.Append("<tr>");
            objStrBuilder.Append("<td>");
            objStrBuilder.Append("HP Labs");
            objStrBuilder.Append("<\td>");
            objStrBuilder.Append("<td>");
            objStrBuilder.Append("HP computer Joy");
            objStrBuilder.Append("<\td");
            objStrBuilder.Append("<\tr>");
            objStrBuilder.Append("<\table>");
            dic.InnerHtml = objStrBuilder.ToString();
            Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
            word = null;
            try
            {
                object missing = System.Reflection.Missing.Value;
                word = new Microsoft.Office.Interop.Word.Application();
                object template = @"D:\\DS_Template11.dotx";
                word.Documents.Add(Template: ref template);
                word.Visible = true;
                object readOnly = false;

                object filename = "http://localhost:60510/tr/Default.aspx";
                Microsoft.Office.Interop.Word.Document document = word.Documents.Open(ref filename, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);


              //  Microsoft.Office.Interop.Word.Section wordSectio = document.Sections;
                foreach (Microsoft.Office.Interop.Word.Section wordSectin in document.Sections)
                {
                    foreach (Microsoft.Office.Interop.Word.HTMLDivision wordSection in document.HTMLDivisions)
                    {
                        String text = "this is footer";
                        //Get the footer range and add the footer details.
                        Microsoft.Office.Interop.Word.Section s1=document.Sections.Add();                            ;
                        Microsoft.Office.Interop.Word.Paragraph p1 = document.Paragraphs.Add();

                        Microsoft.Office.Interop.Word.Range R1 = p1.Range;
                        Microsoft.Office.Interop.Word.HTMLDivision h1= R1.HTMLDivisions.Add();
                        h1.
                        R1.ContentControls=dic.
                        R1.HTMLDivisions = dic.InnerHtml;
                        //Microsoft.Office.Interop.Word.Range footerRange = wordSection.Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterPrimary].Range;
                        Microsoft.Office.Interop.Word.HTMLDivision para = wordSection.HTMLDivisions.Add(dic.InnerHtml);
                        Range.Fields.Add(Range, Microsoft.Office.Interop.Word.WdFieldType.wdFieldHTMLActiveX);


modified 13-Feb-15 6:16am.

QuestionRe: How to convert HTMl Div to word Pin
Richard MacCutchan12-Feb-15 22:47
mveRichard MacCutchan12-Feb-15 22:47 
AnswerRe: How to convert HTMl Div to word Pin
abjchr12-Feb-15 22:59
abjchr12-Feb-15 22:59 
GeneralRe: How to convert HTMl Div to word Pin
Richard MacCutchan12-Feb-15 23:45
mveRichard MacCutchan12-Feb-15 23:45 
GeneralRe: How to convert HTMl Div to word Pin
abjchr12-Feb-15 23:55
abjchr12-Feb-15 23:55 
GeneralRe: How to convert HTMl Div to word Pin
Richard MacCutchan13-Feb-15 0:11
mveRichard MacCutchan13-Feb-15 0:11 
Questionhow do I insert word, pdf and text to sql database in vb.asp Pin
Shelby12312-Feb-15 14:11
Shelby12312-Feb-15 14:11 
GeneralRe: how do I insert word, pdf and text to sql database in vb.asp Pin
PIEBALDconsult12-Feb-15 14:17
mvePIEBALDconsult12-Feb-15 14:17 
AnswerRe: how do I insert word, pdf and text to sql database in vb.asp Pin
Rollin Shultz12-Feb-15 15:59
Rollin Shultz12-Feb-15 15:59 
Questioniframe is displaying the same document even I am trying to open different documents. Even in byte array is containing different bytes and number of bytes. Pin
VPSingh malhi11-Feb-15 13:58
professionalVPSingh malhi11-Feb-15 13:58 
QuestionMVC Newbie Question - Controller and View - page not found Pin
jkirkerx11-Feb-15 8:17
professionaljkirkerx11-Feb-15 8:17 
Answer[GOT IT] - got that from that Google App Pin
jkirkerx11-Feb-15 11:06
professionaljkirkerx11-Feb-15 11:06 
AnswerRe: MVC Newbie Question - Controller and View - page not found Pin
Afzaal Ahmad Zeeshan12-Feb-15 5:53
professionalAfzaal Ahmad Zeeshan12-Feb-15 5:53 
GeneralRe: MVC Newbie Question - Controller and View - page not found Pin
jkirkerx12-Feb-15 10:45
professionaljkirkerx12-Feb-15 10:45 
AnswerRe: MVC Newbie Question - Controller and View - page not found Pin
Afzaal Ahmad Zeeshan13-Feb-15 0:06
professionalAfzaal Ahmad Zeeshan13-Feb-15 0:06 
GeneralRe: MVC Newbie Question - Controller and View - page not found Pin
jkirkerx13-Feb-15 6:23
professionaljkirkerx13-Feb-15 6:23 
AnswerRe: MVC Newbie Question - Controller and View - page not found Pin
Afzaal Ahmad Zeeshan13-Feb-15 7:02
professionalAfzaal Ahmad Zeeshan13-Feb-15 7:02 
GeneralRe: MVC Newbie Question - Controller and View - page not found Pin
jkirkerx13-Feb-15 7:31
professionaljkirkerx13-Feb-15 7:31 
QuestionHow to retrieve data from a remote desktop database via REST API Pin
IsoftTech11-Feb-15 4:07
IsoftTech11-Feb-15 4:07 
AnswerRe: How to retrieve data from a remote desktop database via REST API Pin
Afzaal Ahmad Zeeshan11-Feb-15 4:49
professionalAfzaal Ahmad Zeeshan11-Feb-15 4:49 
GeneralRe: How to retrieve data from a remote desktop database via REST API Pin
IsoftTech11-Feb-15 23:28
IsoftTech11-Feb-15 23:28 
AnswerRe: How to retrieve data from a remote desktop database via REST API Pin
Afzaal Ahmad Zeeshan12-Feb-15 3:08
professionalAfzaal Ahmad Zeeshan12-Feb-15 3:08 
Questionerror while updating the ms access data base after hosting the site on domain Pin
Member 1100557011-Feb-15 3:35
Member 1100557011-Feb-15 3:35 
AnswerRe: error while updating the ms access data base after hosting the site on domain Pin
Richard Deeming11-Feb-15 4:18
mveRichard Deeming11-Feb-15 4:18 
QuestionJavascript inside updatepanel cannot access server side variable after potback Pin
Moodhi10-Feb-15 11:40
Moodhi10-Feb-15 11:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.