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?
Date : March 29 2020, 07:55 AM
|