Jump to content
  • Sign Up
PShim

Сохранение в doc

Recommended Posts

Здравствуйте. Подскажите пожалуйста, что стоит дописать в скрипт чтобы файл сохранялся со стилем(css). Есть свой скрипт и есть взятый из jq(https://www.jqueryscript.net/other/Export-Html-To-Word-Document-With-Images-Using-jQuery-Word-Export-Plugin.html). 

function Export2Doc(element, filename = ''){
  var preHtml = "<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><meta charset='utf-8'><title>Export HTML To Doc</title></head><body>";
  var postHtml = "</body></html>";
  var html = preHtml+document.getElementById(element).innerHTML+postHtml;

  var blob = new Blob(['\ufeff', html], {
      type: 'application/msword'
  });
  var url = 'data:application/vnd.ms-word;charset=utf-8,' + encodeURIComponent(html);
  filename = filename?filename+'.doc':'document.doc';
  var downloadLink = document.createElement("a");
  document.body.appendChild(downloadLink);
  if(navigator.msSaveOrOpenBlob ){
      navigator.msSaveOrOpenBlob(blob, filename);
  }else{
      downloadLink.href = url;
      downloadLink.download = filename;
      downloadLink.click();
  }
  document.body.removeChild(downloadLink);
}

 

Share this post


Link to post
Share on other sites

Здравствуйте.

На пример вот так:

var preHtml = "<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><meta charset='utf-8'><title>Export HTML To Doc</title></head><body>";

preHtml += '<style type="text/css">h1{font-size:120%;font-family:Verdana,Arial,Helvetica,sans-serif;color:#336}\n</style';

var postHtml = "</body></html>";

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Similar Content

    • By prank
      Здравствуйте возникла проблема: http://prntscr.com/t96dcc (parallax) его высота смещает блок с текстом. Может подскажите другую рамку с текстом или как исправить это. 
      Параллакс: 
      <section class="parallax sticky" id="scene"> <div class="parallax-L" data-depth="0.3" id="L"><img src="img/bmw-m32.png" alt="" /></div> #L { width: 100%; height: 50vh; padding: 0; margin: 0; } .L { background: url(bmw-m32.jpg) left no-repeat; background-size: cover; overflow: hidden; } img { max-width: 20%; height: auto; } .sticky{ position: sticky; top: 0; } Рамка с текстом:
      <div class="ramka-5"> Рамка 5 </div> .ramka-5 { width: 4000px; position: relative; z-index: 2; background-color: white; width: 50%; margin: 0 auto; padding: 25px; border-right: 1px solid #333; border-left: 1px solid #333; border-radius: 10px; display: flex;     align-items: center;     justify-content: center;       font-size: 24px;     font-family: 'Roboto Condensed', sans-serif; }  
  • Member Statistics

    46,866
    Total Members
    1,451
    Most Online
    prank
    Newest Member
    prank
    Joined
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...