Word dosyasını olarak HTML dosyası kullanırken biçimlendirme Yeni hat?

3 Cevap php

Ben zaten bir Word dosyası olarak "ihraç" edilecek yarattık önceden varolan bir HTML sayfası ihtiyacı bir müşteri için bir PHP uygulama yazıyorum. Basitçe, bu da böyle yapılır:

if (isset($_GET["word"])) {
  header("Content-type: application/vnd.ms-word");
  header("Content-Disposition: attachment;Filename=some_file.doc");
}

Bir "kelime" bayrak sayfa sorgu dizesi, örneğin yer alıyorsa, bu, tabii, adı verilecek:

whateverpage.php?somequery=string&someother=test&word
Anyways, my question is, despite how complex this HTML page actually is, it actually transfers pretty well to a nicely formatted Word file just by changing the content-type. The only problem I'm having is that new line breaks (HTML <br> tags) aren't formatting properly. E.g.: In my html, if I have something that looks like
Aug
01
with a BR between the lines, it always ends up showing
Aug 01
in the generated Word file. I've done some Googling and lots of tests with various other things but nothing seems to format properly with a simple new line. Does anyone know how to properly format a new line character in a Word file that's being created from an HTML file? Any help is greatly appreciated. Edit: I've tried wrapping the said line in a P tag, ala:
<p>Aug<br>01</p>
Without luck. I've also tried making a basic document and Word, saving it as an HTML file and looking at the generated (i.e sloppy) Word HTML source. There is some CSS in there that I thought might give me a clue, but I tried everything and nothing seemed to work properly. Word seems to add an 'MsoNormal' class to wrapped paragraphs, I tried adding this but it just removes any font formatting I had and doesn't help. Here is the CSS Word creates itself:
p.MsoNormal, li.MsoNormal, div.MsoNormal
    {mso-style-unhide:no;
    mso-style-qformat:yes;
    mso-style-parent:"";
    margin-top:0cm;
    margin-right:0cm;
    margin-bottom:10.0pt;
    margin-left:0cm;
    line-height:115%;
    mso-pagination:widow-orphan;
    font-size:11.0pt;
    font-family:"Calibri","sans-serif";
    mso-ascii-font-family:Calibri;
    mso-ascii-theme-font:minor-latin;
    mso-fareast-font-family:Calibri;
    mso-fareast-theme-font:minor-latin;
    mso-hansi-font-family:Calibri;
    mso-hansi-theme-font:minor-latin;
    mso-bidi-font-family:"Times New Roman";
    mso-bidi-theme-font:minor-bidi;
    mso-fareast-language:EN-US;}

3 Cevap

Your problem is probably due to the fact that when you switch the content type to a Word document, the browser doesn't render it as HTML. My guess is that you need to add a newline to the Word document if you want a line break. How to insert this line break? I'm not sure, but you could always try:

echo "Aug\r\n01";

\ R \ n yeni satır karakterleri nerede.

Ben bu yüzden böyle benim satır sonlarını etiketleme oldu, bu aynı sorun vardı:

<br/>

Ben sadece bunu değişti

<br>

Sonra benim hat çalışma başlangıç ​​sonları.

Peki, sadece echo "<p>Aug</p><p>01</p>"; güzel değil, ama aradığınız satır sonunu etkisi olmalıdır, bir satır-break korumak istiyorsanız.