logo
down
shadow

create word document with html content in c#


create word document with html content in c#

Content Index :

create word document with html content in c#
Tag : chash , By : Stephen Dewar
Date : December 01 2020, 04:55 PM


Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

I want Convert a Html page with all its content i.e. images like .png,.gif to ms word document with the same look and fe


Tag : chash , By : ponchopilate
Date : March 29 2020, 07:55 AM
This might help you here is the Code which any one can use to convert the html page and get the Images also..
 const string filename = "C:/Temp/test.docx";
        Response.ContentEncoding = System.Text.Encoding.UTF7;
        System.Text.StringBuilder SB = new System.Text.StringBuilder();
        System.IO.StringWriter SW = new System.IO.StringWriter();
        System.Web.UI.HtmlTextWriter htmlTW = new System.Web.UI.HtmlTextWriter(SW);
        tbl.RenderControl(htmlTW);
       string strBody = "<html>" +
        "<body>" + "<div><b>" + htmlTW.InnerWriter.ToString() + "</b></div>" +
          "</body>" +
         "</html>";
        string html = strBody;

        if (File.Exists(filename)) File.Delete(filename);

        using (MemoryStream generatedDocument = new MemoryStream())
        {
            using (WordprocessingDocument package = WordprocessingDocument.Create(generatedDocument, WordprocessingDocumentType.Document))
            {
                MainDocumentPart mainPart = package.MainDocumentPart;
                if (mainPart == null)
                {
                    mainPart = package.AddMainDocumentPart();
                    new Document(new Body()).Save(mainPart);
                }

                HtmlConverter converter = new HtmlConverter(mainPart);
                converter.BaseImageUrl = new Uri("http://localhost:portnumber/");
                Body body = mainPart.Document.Body;

                var paragraphs = converter.Parse(html);
                for (int i = 0; i < paragraphs.Count; i++)
                {
                    body.Append(paragraphs[i]);
                }

                mainPart.Document.Save();
            }

            File.WriteAllBytes(filename, generatedDocument.ToArray());
        }

        System.Diagnostics.Process.Start(filename);

how to create a word document with all the content of several others with phpword


Tag : php , By : user181445
Date : March 29 2020, 07:55 AM
hop of those help? A pull request that was accepted June 30 suggests the following.
Loops sections of one document and inserts it in another.
$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addText('Lorem ipsum');

// Load another document
$phpWord2 = \PhpOffice\PhpWord\IOFactory::load('lorem.docx');

// Add sections to the first document
foreach ($phpWord2->getSections() as $section) {
    $phpWord->addExistingSection($section);
}
<?php
    $documents = ['doc1.docx', 'doc2.docx', 'doc3.docx', 'doc4.docx'];
    $lastDoc = end($documents);

    $mainDoc = new \PhpOffice\PhpWord\PhpWord();

    foreach($documents as $document) {
        $appendDoc = \PhpOffice\PhpWord\IOFactory::load($document);
        foreach ($appendDoc->getSections() as $section) {
            $mainDoc->addExistingSection($section);
        }

        // Add page break after every appended doc except the last one
        if($document != $lastDoc) {
            $section = $mainDoc->addSection();
            $section->addPageBreak();
        }
    }

How to get HTML content of Microsoft Word document?


Tag : jquery , By : user179271
Date : March 29 2020, 07:55 AM
I hope this helps you . The fundamental issue here is that you get the HTML with a method call, you don't load stuff like this, its implicit, but you want to make sure you sync before getting the values :)
this is how it works check sample below:
Word.run(function (context) {
        var myHTML  = context.document.body.getHtml();
    
        return context.sync()
            .then(function() {
                console.log(myHTML.value);
            });
    });

Write HTML content to word document using C#


Tag : chash , By : Fenix Drakken
Date : March 29 2020, 07:55 AM

How can I create a Toc(Table of Content) for a document in Word using office.js?


Tag : development , By : ikey
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Printing from a .NET Service
  • Capture MouseDown event for .NET TextBox
  • How do I generate WPF controls through code
  • Linq to objects - select first object
  • Visual Studio - new "default" property values for inherited controls
  • Anyone know a good workaround for the lack of an enum generic constraint?
  • Is the C# static constructor thread safe?
  • What is the difference between String and string in C#?
  • Multicore Text File Parsing
  • Invalid Resource File
  • Getting DirectoryNotFoundException when trying to Connect to Device with CoreCon API
  • How to wait for thread complete before continuing?
  • Is String.Format as efficient as StringBuilder
  • ASP.NET Web Service Results, Proxy Classes and Type Conversion
  • sgen.exe fails during build
  • In C#, why can't a List<string> object be stored in a List<object> variable
  • C# loop - break vs. continue
  • How to access .Net element on Master page from a Content page?
  • Why are unsigned int's not CLS compliant?
  • Why is Array.Length an int, and not an uint
  • How do I make event callbacks into my win forms thread safe?
  • Genealogy Tree Control
  • WCF Service - Backward compatibility issue
  • Binary patch-generation in C#
  • Tab Escape Character?
  • When do Request.Params and Request.Form differ?
  • The imported project "C:\Microsoft.CSharp.targets" was not found
  • Numeric Data Entry in WPF
  • Print a Winform/visual element
  • C# logic order and compiler behavior
  • When to use an extension method with lambda over LINQtoObjects to filter a collection?
  • How to make a button appear as if it is pressed?
  • C# and Arrow Keys
  • How do you resolve a domain name to an IP address with .NET/C#?
  • Should the folders in a solution match the namespace?
  • How can I evaluate C# code dynamically?
  • CSharpCodeProvider Compilation Performance
  • How can I create Prototype Methods (like JavaScript) in C#.Net?
  • DataTable Loop Performance Comparison
  • CSV string handling
  • What is the best way to do unit testing for ASP.NET 2.0 web pages?
  • High availability
  • What to use for Messaging with C#
  • Accessing a Dictionary.Keys Key through a numeric index
  • ConfigurationManager.AppSettings Performance Concerns
  • What Are Some Good .NET Profilers?
  • Is this a good way to determine OS Architecture?
  • How to create a tree-view preferences dialog type of interface in C#?
  • Searching directories for tons of files?
  • Can I have a method returning IEnumerator<T> and use it in a foreach loop?
  • Why can't I have abstract static methods in C#?
  • Displaying ad content from Respose.WriteFile()/ Response.ContentType
  • Convert integers to written numbers
  • Absolute path back to web-relative path
  • How can we generate getters and setters in Visual Studio?
  • Bringing Window to the Front in C# using Win32 API
  • Possible to "spin off" several GUI threads? (Not halting the system at Application.Run)
  • Reading a C/C++ data structure in C# from a byte array
  • How should I translate from screen space coordinates to image space coordinates in a WinForms PictureBox?
  • Setting Objects to Null/Nothing after use in .NET
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com