{"id":27,"date":"2011-04-06T11:05:07","date_gmt":"2011-04-06T01:05:07","guid":{"rendered":"http:\/\/www.reenadu.com\/?p=27"},"modified":"2011-04-06T11:05:07","modified_gmt":"2011-04-06T01:05:07","slug":"asp-net-dynamically-generate-ms-word-document-2","status":"publish","type":"post","link":"https:\/\/nickdu.com\/?p=27","title":{"rendered":"ASP.net dynamically generate MS Word document (2)"},"content":{"rendered":"<p>MS Word treat this generated \u201cWord\u201d document differently<\/p>\n<p>When clicking download generated document, IE will pop up \u201cFile Download\u201d dialog as expected. However when opening the downloaded document, MS Word will be in \u201c<em>Web Layout View<\/em>\u201d instead of \u201c<em>Print Layout View<\/em>\u201d.<\/p>\n<p style=\"padding-left: 30px;\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" src=\"http:\/\/www.nickdu.com\/wp-content\/uploads\/2011\/04\/popup.jpg\" alt=\"\" width=\"404\" height=\"273\" \/><\/p>\n<p>Let MS Word \u201cthinks\u201d this is true word document and open in \u201c<em>Print Layout View<\/em>\u201d with zoom \u201c<em>90%<\/em>\u201d<\/p>\n<p>Replace original Visual Studio automatically generated .aspx header with the following code<\/p>\n<pre lang=\"html4strict\">\n<html xmlns:o=\"urn:schemas-microsoft-com:office:office\"\nxmlns:w=\"urn:schemas-microsoft-com:office:word\"\nxmlns=\"http:\/\/www.w3.org\/TR\/REC-html40\">\n\n<head>\n<meta http-equiv=Content-Type content=\"text\/html; charset=windows-1252\">\n<meta name=ProgId content=Word.Document>\n<meta name=Generator content=\"Microsoft Word 11\">\n<meta name=Originator content=\"Microsoft Word 11\">\n<!--[if gte mso 9]><xml>\n<w:WordDocument>\n<w:View>Print<\/w:View>\n<w:Zoom>90<\/w:Zoom>\n<w:DoNotOptimizeForBrowser\/>\n<\/w:WordDocument>\n<\/xml><![endif]-->\n<\/head>\n<\/pre>\n<p>OK! Now when MS Word opens this html style Word document, it more likely opens a real Word document.<\/p>\n<p>Another issue comes up that MS Word is so smart, and it automatically breaks the page.<\/p>\n<p>If you want to break the page on a certain position, you can insert the following code into your html style Word document.<\/p>\n<pre lang=\"html4strict\">\nPrevious page\n<br clear=all style=\"page-break-before:always\" mce_style=\"page-break-before:always\">\nNext page\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>MS Word treat this generated \u201cWord\u201d document differently When clicking download generated document, IE will pop up \u201cFile Download\u201d dialog as expected. However when opening the downloaded document, MS Word will be in \u201cWeb Layout View\u201d instead of \u201cPrint Layout View\u201d. Let MS Word \u201cthinks\u201d this is true word document and open in \u201cPrint Layout &hellip; <a href=\"https:\/\/nickdu.com\/?p=27\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;ASP.net dynamically generate MS Word document (2)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9,2],"tags":[],"class_list":["post-27","post","type-post","status-publish","format-standard","hentry","category-net","category-it"],"_links":{"self":[{"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/posts\/27","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nickdu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=27"}],"version-history":[{"count":0,"href":"https:\/\/nickdu.com\/index.php?rest_route=\/wp\/v2\/posts\/27\/revisions"}],"wp:attachment":[{"href":"https:\/\/nickdu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=27"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nickdu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=27"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nickdu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}