2011-10-31 3 views
0

내가 내가이 문자열을 사용하여 .DOC 또는 .DOCX 파일을 만들고 싶어 HTML에서 .doc/.docx 파일을 만드는 방법 (문자열로)?

<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><head><style><!-- 

        /*paged media */ div.header {display: none } 
        div.footer {display: none } /*@media print { */ 


        @page { size: A4; margin: 10%; @top-center { 
        content: element(header) } @bottom-center { 
        content: element(footer) } } 


        /*font definitions*/ 

        /*element styles*/ .del 
        {text-decoration:line-through;color:red;} 

          .ins {text-decoration:none;background:#c0ffc0;padding:1px;} 



        /* Word style definitions */ 

/* TABLE STYLES */ 

/* PARAGRAPH STYLES */ 
.DocDefaults {display:block;space-after: 4mm;line-height: 115%;font-family: Calibri;font-size: 11.0pt;} 
.Normal {display:block;} 

/* CHARACTER STYLES */ .DefaultParagraphFont {display:inline;} 


        /* TABLE CELL STYLES */ 
        --></style><script type="text/javascript"> 

       function toggleDiv(divid){ 
        if(document.getElementById(divid).style.display == 'none'){ 
         document.getElementById(divid).style.display = 'block'; 
        }else{ 
         document.getElementById(divid).style.display = 'none'; 
        } 
       } 

      </script></head><body> 

    <!-- userBodyTop goes here --> 



    <div class="document"> 

    <p class="Normal DocDefaults "><span style="font-weight: bold;">Hi</span><span style="white-space:pre-wrap;"> </span>[name]<span style="white-space:pre-wrap;">. </span><span style="font-weight: bold;color: #FF0000;">your</span><span style="white-space:pre-wrap;"> ac is</span><span style="white-space:pre-wrap;"> </span>[acc_no]<span style="white-space:pre-wrap;">, and </span><span style="font-weight: bold;color: #FF0000;">your</span><span style="white-space:pre-wrap;"> password </span><span style="white-space:pre-wrap;">is </span>[password].</p> 

    <p class="Normal DocDefaults ">Thanks you.</p></div> 







    <!-- userBodyTail goes here --> 

    </body></html> 

노호와 같은 HTML 형식으로 srting 있습니다. doc 또는 docx는 download.what에 대한 DB의 디렉토리 및 링크에 저장해야합니다.

+0

아무 것도 시도해 보지 않으셨습니까? 또한 http://www.phpdocx.com/을 보셨습니까? – Chris

+0

phpdocx는 서버에 pdf 및 zip 모듈이 필요합니다. 하지만 난 그 모듈을 설치할 수 없습니다. 그래서 코어 PHP 코드에 대한 serching 오전. 위의 문자열은 doc 형식으로 내보낼 수 있으며 사용자가 저장할 수 있습니다. 하지만 내 요구 사항은 서버 디렉토리에 저장하고 DB에 디렉토리의 링크를 나중에 다운로드 – user989184

+0

때 html을 (웹 페이지로 저장된 문서) 브라우저에서 문서의 스타일을 제대로 표시하고 있습니다. 다시 doc로 내 보내면 스타일이 올바르게 표시되지 않습니다. 이슈가 뭐야? – user989184

답변

0

저는 개발자가되었지만 HTML을 .docx로 변환 할 수 있습니다. 문서이 당신을 위해 작동합니다

"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"><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=\"http://www.w3.org/TR/REC-html40\"><body>" 

희망,/.dcox하는 파일 확장자를 변경하십시오 HTML 파일 &에 & 추가 다음 코드를 교체하십시오.

+0

웹 페이지에 .docx 파일을 표시 할 수 있습니까? 이것이 당신이하려는 일입니다. –

0
/* HTML to Microsoft Word Export 
* This code demonstrates how to export an html element to Microsoft Word 
* with CSS styles to set page orientation and paper size. 
* Tested with Word 2010, 2013 and FireFox, Chrome, Opera, IE10-11 
* Fails in legacy browsers (IE<10) that lack window.Blob object 
*/ 
function saveDoc() { 

    if (!window.Blob) { 
    alert('Your legacy browser does not support this action.'); 
    return; 
    } 

    var html, link, blob, url, css; 

    // EU A4 use: size: 841.95pt 595.35pt; 
    // US Letter use: size:11.0in 8.5in; 

    css = ('\ 
    <style>\ 
    @page WordSection1{size: 841.95pt 595.35pt;mso-page-orientation: portrait;}\ 
    div.WordSection1 {page: WordSection1;}\ 
    h1 {font-family: "Times New Roman", Georgia, Serif; font-size: 16pt;}\ 
    p {font-family: "Times New Roman", Georgia, Serif; font-size: 14pt;}\ 
    </style>\ 
    '); 

    var rightAligned = document.getElementsByClassName("sm-align-right"); 
    for (var i=0, max=rightAligned.length; i < max; i++) { 
    rightAligned[i].style = "text-align: right;" 
    } 

    var centerAligned = document.getElementsByClassName("sm-align-center"); 
    for (var i=0, max=centerAligned.length; i < max; i++) { 
    centerAligned[i].style = "text-align: center;" 
    } 

    html = document.getElementById('text').innerHTML; 
    html = '\ 
    <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>Document Title</title>\ 
    <xml>\ 
     <w:worddocument xmlns:w="#unknown">\ 
     <w:view>Print</w:view>\ 
     <w:zoom>90</w:zoom>\ 
     <w:donotoptimizeforbrowser />\ 
     </w:worddocument>\ 
    </xml>\ 
    </head>\ 
    <body lang=RU-ru style="tab-interval:.5in">\ 
    <div class="Section1">' + html + '</div>\ 
    </body>\ 
    </html>' 

    blob = new Blob(['\ufeff', css + html], { 
    type: 'application/msword' 
    }); 

    url = URL.createObjectURL(blob); 
    link = document.createElement('A'); 
    link.href = url; 

    filename = 'filename'; 

    // Set default file name. 
    // Word will append file extension - do not add an extension here. 
    link.download = filename; 

    document.body.appendChild(link); 

    if (navigator.msSaveOrOpenBlob) { 
    navigator.msSaveOrOpenBlob(blob, filename + '.doc'); // IE10-11 
    } else { 
    link.click(); // other browsers 
    } 

    document.body.removeChild(link); 
};