Can word open html

IN THIS TASK

  • SUMMARY

    • Create Your HTML Document

    • Add Text and Hyperlinks to Your HTML Document

    • Add an Image to Your HTML Document

    • Open an HTML Document in Word

  • REFERENCES

This article provides a step-by-step guide to how to create an HTML document, including items such as typing text and adding images and hyperlinks to your HTML document.

Create Your HTML Document

Use one of the following two methods to create your new HTML document.

Method 1

  1. Start Microsoft Word.

  2. In the New Document task pane, click Blank Web Page under New.

  3. On the File menu, click Save.

    NOTE: The Save as type box defaults to Web Page (*.htm; *.html).

  4. In the File name box, type the file name that you want for your document, and then click Save.

Method 2

  1. Start Microsoft Word.

  2. Create a new blank document.

  3. On the File menu, click Save as Web Page.

  4. In the File name box, type the file name that you want for your document, and then click Save.

Add Text and Hyperlinks to Your HTML Document

  1. Open the HTML document that you created earlier in this article. To do this, follow these steps:

    1. On the File menu, click Open.

    2. Browse to the location that you saved your article to, in the «Create Your HTML Document» section of this article.

    3. Select the file and then click Open.

  2. Type the following text into the document:

    You can use Microsoft Word to create HTML documents as easily as you can create normal Word documents.

  3. To create a hyperlink, select the words «Microsoft Word» in the text that you typed.

  4. On the Insert menu, click Hyperlink.

  5. In the Insert Hyperlink dialog box, type http://www.microsoft.com/word in the Address box, and then click OK.

  6. Save your changes to the document.

Add an Image to Your HTML Document

  1. Place your insertion point where you want to place an image in your document.

  2. On the Insert menu, point to Picture, and then click ClipArt.

  3. In the Insert ClipArt task pane, click Search.

    NOTE: If you click Search without typing anything into the Search Text box, the search result will display all of the currently available images on your system.

  4. In the Results section, select the image that you want to insert into the page.

  5. Save your changes and then close the document.

Open an HTML Document in Word

Do one of the following.

If the New Document task pane is still displayed:

In the New Document task pane, select the document under Open a document. This opens the document directly.

-or-

If the New Document task pane is not displayed:

  1. On the File menu, click Open.

  2. In the Open dialog box, locate the HTML document that you created earlier, and then select it.

  3. Click Open.

REFERENCES

For more information about HTML support in Word 2002, follow these steps:

  1. Open Microsoft Word 2002.

  2. On the Help menu, click Microsoft Word Help.

  3. Click the Answer Wizard tab.

  4. Type HTML in the What would you like to do? box, and then click Search.

  5. Related topics will be displayed. Click any item to display the information.

Summary

Need more help?

Want more options?

Explore subscription benefits, browse training courses, learn how to secure your device, and more.

Communities help you ask and answer questions, give feedback, and hear from experts with rich knowledge.

I would like to open an HTML file in MS Word 2007 directly so I can use some of its search and replace features. I don’t care about the file’s encoding and will not actually use the final thing as HTML (I’m going to be extracting interesting parts). I want to see raw HTML. When I open the document, instead Word renders everything.

I am hoping someone knows how to do this from within Word without having to resort to copying and pasting or modifying the file to change the html tags to no longer look like html (such as {html> or something). I have been hit by this multiple times over the years and wish that I could fix the problem instead of always be forced to find a workaround.

Is there some option or setting, or something in the Open dialog that can change Word’s behavior?

asked Dec 29, 2012 at 1:03

ErikE's user avatar

ErikEErikE

2641 gold badge6 silver badges17 bronze badges

2

You can turn off automatic file-type conversions in Word, and instead it will ask you what type of file you’re trying to open, at which point you can pick Text.

To turn it off (or rather turn on Confirmation of conversion):

  1. Open the Word Options. (Word 2007: click the Office button and then click Word Options. Word 2010: display the File tab of the ribbon and then click Options)
  2. At the left side of the dialog box click Advanced.
  3. Scroll through the options until you see the General section.
  4. Make sure the Confirm File Format Conversion On Open check box is selected.
  5. Click on OK.

If you never want to open rendered HTML in Word again, you can also uninstall the HTML Filter by running Office Setup and de-selecting it form the installed options.

Alternatively and probably easiest: Use something else for the task, like a good Plain Text editor. I personally use and suggest Notepad++.

answered Dec 29, 2012 at 1:18

Ƭᴇcʜιᴇ007's user avatar

Ƭᴇcʜιᴇ007Ƭᴇcʜιᴇ007

111k19 gold badges199 silver badges264 bronze badges

0

Go to your html file and right click on it open with it in word do the editing and click on save…(note file format conversion should be disabled)

answered Oct 31, 2015 at 4:09

Shafiq Ahmad's user avatar

2

Can you open HTML files in Word?

Open an HTML Document in Word In the Open dialog box, locate the HTML document that you created earlier, and then select it. Click Open.

How do I open HTML and CSS files?

In your html write: and keep the style. css and the html file in the same folder. Just open the html file with any browser (double-click).

Can I use CSS in Word?

You can use Microsoft Word to attach cascading style sheets (CSS) to your web pages. Cascading style sheets are text files which control the formatting of web pages. There work just like templates. From the Tools menu, click Templates and Add-ins.

How do I insert HTML into a Word document?

Questions and answers

  1. From the Insert tab, Text section, choose Object.
  2. Then choose Text From File.
  3. Use the file type selector in the Insert File dialog box, choose All Web Pages to locate the HTML file.
  4. A Convert File box will be displayed, choose Other encoding,
  5. click OK.

Where we can run HTML code?

Any file containing HTML code is saved using the extension “. HTML”. All modern browsers — such as Google Chrome, Safari and Mozilla Firefox — recognize this format and can open these files, so all you need to do to run an HTML file is open it in your Web browser of choice.

How do I make font darker in Chrome?

Hit “Colors” in the left toolbar. Scroll down, and under “Choose your default app mode,” select “Dark.” Chrome will turn dark immediately.

Why can’t I see certain fonts on Instagram?

If you want to access the new fonts, you’ll be able to do so pretty easily: Make sure your Instagram app has the latest update. If you have access to the new fonts, you’ll see ten different text options. If not, you’ll only see the original five: Modern, Classic, Neon, and Strong, and Typewriter.

How do I fix font not supported?

How To Fix “Font Not Supported” Error On Samsung Devices?

  1. Step 1: Download The APK of Font For Flipfonts. If you cannot find a good font to install then here are some fonts which look cool.
  2. Step 2: Installing & Backing Up Downloaded Font.
  3. Step 3: Uninstall The Font APK.
  4. Step 4: Restoring Font To Make It Work.
  5. Step 5: Applying Font.

Why is zFont not working on my phone?

It may be down and stopping you from updating the zFont 3 – Custom Font Installer [No ROOT] app. Confirm that you have enough storage space in your phone to download updates. If you don’t have enough storage space, it can be blocking the app updates.

Updated: 08/31/2020 by

View source code

Microsoft Word supports the ability to save any document as a web page. However, there is no way to view the source code in the most recent versions of Microsoft Word.

Microsoft Word 2007, 2010, and later

As mentioned above, there is no way to view the source code of an HTML document in the most recent versions of Microsoft Word. However, if you open the document in any browser, you can view the source using the browser.

  • How to view the HTML source code of a web page.

While viewing the source code is possible in a browser, to make code changes, we suggest using a text editor or an HTML editor. Not only is it easier to create and modify an HTML file, your source code looks more clean and is less likely to cause incompatibility issues in different browsers.

If you want to use Microsoft Word because of its WYSIWYG interface, realize that many of the more profession HTML editors also have a WYSIWYG interface. For example, Microsoft Expression Web is now free and has an easy to use interface.

Microsoft Word 2003

Microsoft Word 2003 did support the ability to view the HTML source code by clicking View and select HTML source.

is it possible to include normal HTML files in Word, so that they are shown in correct style etc. and not as normal text files?

asked Jan 26, 2010 at 7:59

Tobias's user avatar

Yes it is possible, if you right click any html file and open it in Word using ‘Open With’ option, then it will be there inside the Word.

answered Jan 26, 2010 at 8:17

Sarfraz's user avatar

SarfrazSarfraz

375k77 gold badges531 silver badges577 bronze badges

As you manage your business, learning a complicated Web authoring tool may just be one ball too many. If you are a Microsoft Word user, you can still edit HTML files in Word, just as you would any other text-based file. This permits you to directly edit and change a HTML file without the use of a more expensive Web authoring tool.

Opening an HTML File

  1. Open Word. Click the “File” tab on the ribbon. Click “Options” at the bottom of the drop-down menu.

  2. Click «Advanced» in the left pane. In the right pane, scroll down to the General area. Select the «Confirm File Format Conversion on Open» check box and then click «OK.»

  3. Click the “File” tab and then click “Open.” Browse to the Web page file to open and double-click the file name.

  4. Click «Plain Text» from the Convert File dialog box and click «OK.» Your Web file opens as a plain text file showing the HTML code. Once you open the file, you can edit it and save the file as an HTML file.

Editing an HTML File

  1. Open Word and your HTML file. Make any file edits you need. Use the Styles pane located on the Home tab to apply styles such as headings.

  2. Click the “Insert” tab and then click “Picture” or “Clip Art” to add graphics. If you add graphics, remember to resize them in a program outside of Word since you can end up with two graphics instead of one when you upload the file to the Web.

  3. Click the “Insert” tab and click the “Hyperlink” button in the Links group to add hyperlinks in your document. You can add links to email, Web pages and other documents you plan to upload.

  4. Right-click the Quick Access Toolbar at the top left of the window and select «Customize Quick Access Toolbar.» Click the “Choose Commands From” drop-down arrow and select “All Commands.” Select “Web Page Preview,” click “Add” and then click “OK.” The button appears on your Quick Access Toolbar. Click the “Web Preview” button to see how your HTML file will look as a Web page.

  5. Save your Web page by clicking “File” and then “Save.” Be sure to save the file as a Web page. The file extension needs to be HTM or HTML.

  6. Transfer the edited Web page and its folder to the server. If you do not transfer its folder, you may not get graphics included.

Table des matières

This page explores the solutions to generate Word document on server side (eg. a webserver). My need is to generate full documents automatically which can later be edited by users, hence the choice of Word format.

Possible solutions

  • Generate binary .doc files. Are you kidding me ?

  • Generate .docx files (Afterall, that’s XML, isn’t it ?) BANNED. I don’t have time to read a 7500 pages specification no-one is capable of implementing — not even Microsoft !

  • Use the COM control to pilot Word on the server. BANNED. Microsoft strongly advises against this solution because Office is «unstable«: «Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.» Doh!

  • Generate RTF documents. ABANDONED. This format is not documented enough.

  • OpenOffice.org/LibreOffice piloting. ABANDONED. I don’t want to mangle with OOo automation (Last time I checked, Python API was awful). And that would not be more reliable than MS Office.

  • Expensive, commercial libraries. ABANDONED. I don’t want my applications to be too tied to a commercial API (which will be a pain in the ass to migrate to another API if the company goes bankrupt or causes commercial problems (phpdocx anyone ?)).

  • Apache POI. ABANDONED. The main maintainer left the project.

  • HTML generation: CHOSEN.

Why HTML ?

  • Generating HTML is easy.

  • Generating HTML documents is fast (magnitudes faster than using a COM control).

  • Word can open HTML documents as if it was native Word files. Heck, you can just rename the html file to .doc and Word will open it !

  • HTML documents are easy to style. Word accepts most HTML & CSS directives (font, size, color, tables, alignment…).

  • MS Office also recognizes some Microsoft-specific HTML elements and CSS attributes which can be used to insert page number, table-of-content and so on…

  • MS Office-specific HTML is more or less documented (here)

Trick:
Embedding images requires external files. Thus we cannot use a single HTML file. The solution is simple: generate several files (the main document in html, images…) then put everything in a single MIME 1.0 file. This is exactly what MS Word does when you save as mhtml (.mht) documents. Header & footers also must be put in a separate file: They will also be included in the MIME file.

Generating MIME 1.0 files is easy, even in php.

So our solution can be sum up as:

  • Generate the main document in HTML, using some specific Word HTML elements.

  • Include any additional data in seperate files (images, etc.)

  • Pack all the files in a MIME 1.0 file.

  • Serve this file as a .doc to the client.

Building a Word HTML document

Here are the different items you can/must use to build a Microsoft Office Word HTML document. These are only snippets, not full html documents. (Full HTML example documents will be in the «Examples» section.)

Basically, you generate a HTML document then serve it to the client as a .doc file (both in filename extension and in MIME type). Word will open this file as if it was a simple .doc file.

HTML declaration

<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>
...
</html>

Document properties

<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>
<head><title>Microsoft Office HTML Example</title>
<style> <!-- 
@page
{
    size: 21cm 29.7cm;  /* A4 */
    margin: 2cm 2cm 2cm 2cm; /* Margins: 2 cm on each side */
    mso-page-orientation: portrait;  
}
--></style>
  • size: Page size.

  • margin : Document margins.

  • mso-page-orientation: portrait or landscape.

Page declaration

You are supposed to put pages (or group of pages) in a «section» (in a DIV), like this:

<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>
<head><title>Microsoft Office HTML Example</title>
<style><!-- 
@page
{
    size:21cm 29.7cmt;  /* A4 */
    margin:1cm 1cm 1cm 1cm; /* Margins: 2.5 cm on each side */
    mso-page-orientation: portrait;  
}
@page Section1 { }
div.Section1 { page:Section1; }
--></style>
</head>
<body>
<div class=Section1>
I'm page 1.
<br clear=all style='mso-special-character:line-break;page-break-before:always'>
I'm page 2.
</div>
</body>
</html>
  • @page is used to set properties of the whole document.

  • Each @page SectionX can be used to change the properties of a group of pages.

  • Each page or group of pages must be put in a

    <div>

    (such as

    <div class=Section1>

    in our example. Feel free to create as many ‘sections’ as needed.

Caveat: Changing things like page orientation for a group or a specific page does not seem to work. FIXME

Standard HTML/CSS elements

Word will accept most standard HTML and CSS features, such as headings (h1,h2,h3…), lists (ul,li), tables, colors… Go experiment yourself. Here are some examples:

basic_html.doc
<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>
<head><title>Microsoft Office HTML Example</title></head>
<body>
<h1>Title level 1</h1>
<h2>Title level 2</h2>
<h3>Title level 3</h3>
<p>Text in level 3</p>
<h2>2nd title level 2</h2>
<h3>Another level 3 title</h3>
 
List:
<ul>
<li>element 1</li>
<li>element 2</li>
<li>element 3</li>
  <ul>
  <li>element 4</li>
  <li>element 5</li>
  <li>element 6</li>
      <ul>
      <li>element 7</li>
      <li>element 8</li>
      </ul>
  </ul>
<li>element 9</li>
<li>element 10</li>
</ul>
 
<table width="100%">
<thead style="background-color:#A0A0FF;"><td nowrap>Column A</td><td nowrap>Column B</td><td nowrap>Column C</td></thead>
<tr><td>A1</td><td>B1</td><td>C1</td></tr>
<tr><td>A2</td><td>B2 Test with looooong text: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla sed sapien 
ac tortor porttitor lobortis. Donec velit urna, vulputate eu egestas eu, lacinia non dolor. Cras lacus diam, tempus 
sed ullamcorper a, euismod id nunc. Fusce egestas velit sed est fermentum tempus. Duis sapien dui, consectetur eu 
accumsan id, tristique sit amet ante.</td><td>C2</td></tr>
<tr><td>A3</td><td>B3</td><td>C3</td></tr>
</table>
 
</body>
</html>

Rendering in Word:

Note that these elements can later be styled, either using inline CSS (<p style="…">) or using CSS stylesheets (eg. you can style all h1 elements).

Forcing display mode on opening

<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>
<head><title>Microsoft Office HTML Example</title>
<!--[if gte mso 9]>
<xml>
<w:WordDocument>
<w:View>Print</w:View>
<w:Zoom>100</w:Zoom>
<w:DoNotOptimizeForBrowser/>
</w:WordDocument>
</xml>
<![endif]-->
<body>
...

This will force the «Page» display mode when the file is opened. This section must be put just after the title, otherwise it will not work.
You can use 80 or 90 for Zoom if you want two pages to fit on screen.

Page break

<br clear=all style='mso-special-character:line-break;page-break-before:always'>

Tables and pagebreaks

Prevent a table cell from spanning over multiple pages

Put in your stylesheet:

td { page-break-inside:avoid; }

or apply to only specific cells:

<td style="page-break-inside:avoid;">...</td>

Prevent tables from spanning over multiple pages

Put in your stylesheet:

tr { page-break-after:avoid; }

or apply to all TR of a table:

<tr style="page-break-after:avoid;">...</tr>

A note about computed field

Computed fields include TOC (table of content), page refences and so on.

With Word, when you open a document, all computed fields are not updated by default. This has to be done manually by typing CTRL+A (to select the whole document) then press F9.

Thus, all computed fields you insert in your document will not show up unless the user manually updates them. This a problem related to Word itself. There is not simple solution to this.

TOC (Table of content)

<p class=MsoToc1> 
<!--[if supportFields]> 
<span style='mso-element:field-begin'></span> 
TOC o "1-3" u 
<span style='mso-element:field-separator'></span> 
<![endif]--> 
<span style='mso-no-proof:yes'>Table of content - Please right-clic and choose "Update fields".</span> 
<!--[if supportFields]> 
<span style='mso-element:field-end'></span> 
<![endif]--> 
</p>

As you can’t predict the page numbers, the TOC needs to be manually updated by the user (Not a heavy burden, and I guess it’s possible to automate this by including a script in the file. I’ll investigate that later.)

TOC before update (upon file opening):

TOC after update: It reflects the different heading levels (h1,h2,h3…).

If you want to customize the TOC, have a look at the Microsoft documentation about this dynamic field.

Bookmarks and references

You can reference another chapter or page rather easily. Here is an example: Set a bookmark in a document, and display the page where this bookmark is located.

Bookmarks: Simply put a html anchor:

<a name="MyBookmark"></a>Appendix

Then the reference:

For more information, see appendix at page 
<!--[if supportFields]>
<span style='mso-element:field-begin'></span>PAGEREF MyBookmark h <span style='mso-element:field-end'></span>
<![endif]-->

Header and footer

Headers and footers must be put in a separate file, in a subdirectory. Example:

  • mydocument.htm : The main document

  • mydocument_filesheaderfooter.htm : The header and footer.

Note: It is important that the subdirectory name starts with the main document name (mydocument.htm → mydocument_files), otherwise Word will display a warning.

mydocument.htm
<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>
<head><title>Microsoft Office HTML Example</title>
<link rel=File-List href="mydocument_files/filelist.xml">
<style><!-- 
@page
{
    size:21cm 29.7cmt;  /* A4 */
    margin:1cm 1cm 1cm 1cm; /* Margins: 2.5 cm on each side */
    mso-page-orientation: portrait;  
    mso-header: url("mydocument_files/headerfooter.htm") h1;
    mso-footer: url("mydocument_files/headerfooter.htm") f1;	
}
@page Section1 { }
div.Section1 { page:Section1; }
p.MsoHeader, p.MsoFooter { border: 1px solid black; }
--></style>
</head>
<body>
<div class=Section1>
I'm page 1.
<br clear=all style='mso-special-character:line-break;page-break-before:always'>
I'm page 2.
</div>
</body>
</html>

Note that the file filelist.xml does not need to be present, but its declaration in the main document is mandatory.

mydocument_filesheaderfooter.htm
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml"= xmlns="http://www.w3.org/TR/REC-html40">
<body>
 
<div style="mso-element:header;" id="h1">
<p class=MsoHeader>Header</p>
</div>
 
<div style='mso-element:footer' id=f1>
<p class=MsoFooter><span class=SpellE>Footer</span> page <!--[if supportFields]><span
class=MsoPageNumber><span style='mso-element:field-begin'></span><span
style='mso-spacerun:yes'> </span>PAGE <span style='mso-element:field-separator'></span></span><![endif]--><span
class=MsoPageNumber><span style='mso-no-proof:yes'>1</span></span><!--[if supportFields]><span
class=MsoPageNumber><span style='mso-element:field-end'></span></span><![endif]--><span
class=MsoPageNumber>/</span><!--[if supportFields]><span class=MsoPageNumber><span
style='mso-element:field-begin'></span> NUMPAGES <span style='mso-element:field-separator'></span></span><![endif]--><span
class=MsoPageNumber><span style='mso-no-proof:yes'>1</span></span><!--[if supportFields]><span
class=MsoPageNumber><span style='mso-element:field-end'></span></span><![endif]-->
</p>
</div>
 
</body>
</html>

After opening the document, don’t forget to go in «Page» display mode to see headers/footers.

This is what you get:

Images

As for the Header/Footer, images must be put in a subdirectory. Then you just use the standard <img> html tag. Example:

  • mydocument.htm : The main document

  • mydocument_files/logo_google.png : The image to include.

mydocument.htm
<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:w='urn:schemas-microsoft-com:office:word' xmlns='http://www.w3.org/TR/REC-html40'>
<head><title>Microsoft Office HTML Example</title>
<link rel=File-List href="mydocument_files/filelist.xml">
<style><!-- 
@page
{
    size:21cm 29.7cmt;  /* A4 */
    margin:1cm 1cm 1cm 1cm; /* Margins: 2.5 cm on each side */
    mso-page-orientation: portrait;  
}
@page Section1 { }
div.Section1 { page:Section1; }
p.MsoHeader, p.MsoFooter { border: 1px solid black; }
--></style>
</head>
<body>
<div class=Section1>
Here is an image:<br>
<img src="mydocument_files/logo_google.png">
</div>
</body>
</html>

Result in Word:

Styling

You can include a CSS stylesheet in the main html file: Word will use it.

You can style standard HTML elements (h1,h2,h3…), but you can also apply styles with the class attribute.

Exploring other Word documents features

If you are trying to find the HTML code corresponding to a Word feature, here’s my advice:

  • Create a blank document in Word.

  • Type a few words and use the feature you need.

  • Save as HTML page (Save as ⇒ Other format ⇒ Web page (*.htm,*.html) (NOT filtered))

Then open with you favorite text editor. You are most likely to find the relevant HTML/CSS code.

Creating a MIME (mhtml) file

Once you have created your html document with its associated files (headers/footer, images…), you need to pack them in a single mhtml (MIME) file.

Let’s take an example: A document with header/footer and an image. The files contained in this zip (mime_example.zip) are:

  • mydocument.htm : The main document

  • mydocument_files/headerfooter.htm : The header and footer

  • mydocument_files/smiley.gif : An image.

Building a MIME file only requires to encode these files in base64 and add a header for each one:

mime_example.doc
MIME-Version: 1.0
Content-Type: multipart/related; boundary="----=_NextPart_ZROIIZO.ZCZYUACXV.ZARTUI"
 
------=_NextPart_ZROIIZO.ZCZYUACXV.ZARTUI
Content-Location: file:///C:/mydocument.htm
Content-Transfer-Encoding: base64
Content-Type: text/html; charset="utf-8"
 
PGh0bWwgeG1sbnM6bz0ndXJuOnNjaGVtYXMtbWljcm9zb2Z0LWNvb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ym9keT4NCjxkaXYgY2xhc3M9U2VjdGlvbjE+DQpJJ20g
cGFnZSAxIDxpbWcgc3JjPSJteWRvY3VtZW50X2ZpbGVzL3NtaWxleS5naWYiPg0KPGJyIGNsZWFy
PWFsbCBzdHlsZT0nbXNvLXNwZWNpYWwtY2hhcmFjdGVyOmxpbmUtYnJlYWs7cGFnZS1icmVhay1i
ZWZvcmU6YWx3YXlzJz4NCkknbSBwYWdlIDIuDQo8L2Rpdj4NCjwvYm9keT4NCjwvaHRtbD4NCg0K
DQo=
 
------=_NextPart_ZROIIZO.ZCZYUACXV.ZARTUI
Content-Location: file:///C:/mydocument_files/headerfooter.htm
Content-Transfer-Encoding: base64
Content-Type: text/html; charset="utf-8"
 
PGh0bWwgeG1sbnM6dj0idXJuOnNjaGVtYXMtbWljcm9zb2Z0LWNvbTp2bWwiIHhtbG5zOm89InVy
bjpzY2hlbWFzLW1pY3Jvc29mdC1jb206b2ZmaWNlOm9mZmljZSIgeG1sbnM6dz0idXJuOnNjaGVt
YXMtbWljcm9zb2Z0LWNvbTpvZmZpY2U6d29yZCIgeG1sbnM6bT0iaHR0cDovL3NjaGVtYXMubWlj
cm9zb2Z0LmNvbS9vZmZpY2UvMjAwNC8xMi9vbW1sIj0geG1sbnM9Imh0dHA6Ly93d3cudzMub3Jn
L1RSL1JFQy1odG1sNDAiPg0KPGJvZHk+DQoNCjxkaXYgc3R5bGU9Im1zby1lbGVtZW50OmhlYWRl
cjsiIGlkPSJoMSI+DQo8cCBjbGFzcz1Nc29IZWFkZXI+SGVhZGVyPC9wPg0KPC9kaXY+DQoNCjxk
aXYgc3R5bGU9J21zby1lbGVtZW50OmZvb3RlcicgaWQ9ZjE+DQo8cCBjbGFzcz1Nc29Gb290ZXI+
PHNwYW4gY2xhc3M9U3BlbGxFPkZvb3Rlcjwvc3Bhbj4gcGFnZSA8IS0tW2lmIHN1cHBvcnRGaWVs
ZHNdPjxzcGFuDQpjbGFzcz1Nc29QYWdlTnVtYmVyPjxzcG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ROIIZO.ZCZYUACXV.ZARTUI
Content-Location: file:///C:/mydocument_files/smiley.gif
Content-Transfer-Encoding: base64
Content-Type: image/gif
 
R0lGODlhEgASAOeQAEM0EP/lIf/mIv/jH//mI//kIP/lIvC2AN3e3f/kH9LQynBeMPvYD/zZEens
7/fLAPvXDffMAM7MxJ2Sd//iHeyrAOecAGBLF//kIfrTCOfq7dfX0//iHv7gG3dmO3hnPPC3AGRP
Hf3fGfjMAJCEY+miAMzKwfvXDl9JFPK9AKZxBKCXfP7hHaGXfffKAPbJAP3dF++yAO+xAPbIAJCD
YtfX0mhSHW9TB52TeG1NB8KLAmlTHvTEAK1+A//nI/7iHpySdt6uAWdQHK+KBPrSB+jr7vPBANeu
AtSmAvzbE/7iHXhmPG5OB8ukAuemAJ6UePvZEG5QB/bKAHFTB5hrBKZsA9+0AfjOAsqEAvzbFM6G
AZViBKyBBPPCAPPGAOyqAG9NB/TCAN+XAP7fGfG8AJKGZv7jH/7fGrt3Ap+VesKMAvTMBnZlOvTD
AO25ALGMA/3cFmBKFuaZAM+NAcvJwHVjN/LEAKRrBJpwBPjPBu2uAJ99BPK/AGxLB6+EA+qpALGN
A6h2BP7gGqVqA/XHAP3gGuOVAOCTAN+VAHNiNc3Lw3NXB8yLAvO/AGhRHfC4AP//////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////yH5BAEAAP8ALAAAAAASABIA
AAj+AP8JHNjiw4ULH1oMXDhwwo0hRwjxQMIlygSGAhfsWQOhQYMTRFy4wbOAoY0mEOCcoUChAwwG
I1Ko2TGQBCAIYzgMGFCgwABBDB6ACFRG4KI8MHQCKIAhAIABIjKE+cPkH443EDrwBBAggAGuLKC8
kKEiTR0rDShsNSBAAAADCZI8ODBnyQUvaZkGEECgr4AEWSIcEBMijp0TS73y9UFAgBkAUmIgCpEo
SIanTfn2DVAIQJsKWtgA8eOCwVPFAgIoARDhUYkqT/5NITPCNIsECX6IAHClUQVDYATS6JHiwWUA
yFnz0WNhEImBQnQcMDLjQYQXXUB8sYDGEcMFVJwiyDhwIEaFEoe2lMQ4IYcKRhbkYLnT5yLGgSs8
oEDhYQXGgAA7
 
------=_NextPart_ZROIIZO.ZCZYUACXV.ZARTUI--

Please note:

  • The boundary can be any string you want, as long as you can’t find it in data. (Using a dot is a safe bet because base64 data can’t contain dots.)

  • Take extra care of dashes before and after the boundary marker.

  • Take extra care of empty lines. They are important.

  • You can use other encodings than base64 (such as quoted-printable), but base64 is a safe bet and works on all kind of files.

This file can be renamed to .doc and opened in Word:

Amusing fact: mhtml (MIME) documents are usually smaller than their true .doc counterparts. For example, the previous mime_example.doc (which is a MIME/mhtml file) is 5216 bytes long. Resaved in true .doc format, it’s 24064 bytes.

A basic MIME 1.0 class helper

Here is a basic MIME 1.0 class which will help you generate the mhtml files:

class mime10class
{
    private $data;
    const boundary='----=_NextPart_ERTUP.EFETZ.FTYIIBVZR.EYUUREZ';
    function __construct() { $this->data="MIME-Version: 1.0nContent-Type: multipart/related; boundary="".self::boundary.""nn"; }
    public function addFile($filepath,$contenttype,$data)
    {
        $this->data = $this->data.'--'.self::boundary."nContent-Location: file:///C:/".preg_replace('!\!', '/', $filepath)."nContent-Transfer-Encoding: base64nContent-Type: ".$contenttype."nn";
        $this->data = $this->data.base64_encode($data)."nn";
    }
    public function getFile() { return $this->data.'--'.self::boundary.'--'; }
}

It’s rather simple: Add files with addFile(), then get the final mhtml/MIME1.0 document with getFile().

Example:

header('Content-Type: application/msword');
header('Content-disposition: filename=mydocument.doc')
$doc = New mime10class();
$doc->addFile('mydocument.htm','text/html; charset="utf-8"','Hello, world !');
$doc->addFile('subdiranotherfile.htm','text/html; charset="utf-8"','Hi there.');
echo $doc->getFile();

Sending the file to the client

The .mht file must be served to the client with the following HTTP headers:

Content-Type: application/msword
Content-disposition: attachment; filename=myfile.doc

Yes, we use «.doc» in order not to confuse the final user. Word will recognize this is a .mht file and will open it accordingly.

Note that:

Content-disposition: attachment; filename=myfile.doc

will force download, but:

Content-disposition: filename=myfile.doc

will allow the user to choose between «open» or «save».

Examples

Full, working HTML documents which load correctly in Microsoft Word, using many Word features: Styling, tables, headers & footers, page format, table-of-content, images…

FIXME

php code examples

FIXME

Performances

I have implemented this system in a professional environment, and we are able generate a 70 pages database-driven dynamically-filled document with lots of tables and references in less than 5 seconds. (The document contains no images; The server runs Apache+php+Oracle. Document templates are written in Smarty.)

The performances are excellent, much better than what I expected.

Ideas worth pondering

  • Using a markup language (Markdown ? Textile ?…) which generates HTML may ease the creation and maintenance of templates.

  • With php, the use of a templating engine like Smarty should help to easily create and maintain document templates without touching php code too much. Template inclusion can help to create — for example — standard headers for all documents.

  • Serving files using gzip compression may improve user experience (our mime_example.doc above goes from 5216 bytes to 2569 bytes with default gzip compression).

Table of Contents

  1. How do I make a Word document into HTML?
  2. How do you save something as HTML?
  3. Is it better to use HTML or plain text?
  4. How do I save HTML as plain text?
  5. How do you convert Word document into HTML?
  6. How to convert a HTML file to a Word document?
  7. How can I convert a PDF to HTML?
  8. What is the best PDF to HTML converter?

Using MS Words built-in save as HTML option

How do I make a Word document into HTML?

Using MS Words built-in save as HTML option

  1. Go to the file menu.
  2. Select Save as.
  3. In the drop-down file type box select, Web Page, Filtered.
  4. Click Save.

How do you save something as HTML?

To SAVE HTML File:

  1. Select File Menu.
  2. Select Save Option from There.
  3. Choose a Path (Where you want to Save your HTML File)
  4. Give a Name to your File followed by . html extension ( for Example myfile. html ).
  5. Press SAVE and you are DONE.

Is it better to use HTML or plain text?

To summarize, both plain text HTML emails have their uses. HTML is generally better for marketing emails. Plain text may be better for personal contact. Give people an option to use plain text when receiving your newsletter.

How do I save HTML as plain text?

Select the file and click the Open button.

  1. Click the File tab again, then click the Save as option.
  2. In the Save as type drop-down list, select the Plain Text (*. txt) option.
  3. Click the Save button to save as a text document.

How do you convert Word document into HTML?

Using Word’s Built-in Converter Open the document in Microsoft Word or OpenOffice . Word has the built-in ability to convert documents into HTML format. Select “Save As.”. Go to the File menu and select “Save As.”. Choose “Web Page.”.

How to convert a HTML file to a Word document?

Microsoft Word has 2 HTML File Options.

  • Microsoft’s Word Filtered Web Page.
  • Using a Word Document in a Content Management System.
  • Paste and Convert Solutions.
  • Upload File and Convert Solutions.
  • Stand Alone Conversion Programs.
  • Batch and Complex Conversions.
  • How can I convert a PDF to HTML?

    Another way to convert PDF to HTML is by clicking on “Convert PDF” in the Welcome page. Select a PDF file you want to convert from local folder, select the output format type and choose an output folder to save the converted word file.

    What is the best PDF to HTML converter?

    Top 5 PDF to HTML Online Converter PDF2HTML Online. With the help of PDF2HTML converter you can convert your PDF files to HTML files in a secure way without the need of downloading any software; that Convert PDF To HTML. In just a single click you can convert your PDF files to the HTML format. ZAMAR. PDFOnline. Investintech PDF to HTML.

    Понравилась статья? Поделить с друзьями:
  • Can word open a pdf file
  • Can word files have viruses
  • Can word edit pdf documents
  • Can word do flowcharts
  • Can word count the number of characters