hey guys, anyone here know how to format word doc using PHP?, i already got how to create one, but the formatting is my problem, like setting bold letters, btw i tried html markup it works but the problem though is how to set the page width? it's taking up the whole page, this problem doesn't happen when word doc is created by default not in html

Member Avatar for diafol

New Word documents use Office Open XML, which from what I can gather is a zipped XML document. So, have a look at this page - I don't know it will help:

http://msdn.microsoft.com/en-us/office/bb265236.aspx

It contains link to downloadable manuals of schemas etc. You may need to be able to access xsd files as well as pdfs though.

Opening a word document with an archiving program like 7-zip really lets you get under its skin. VERY informative.

For example a word file containing this:

Peace peace

Gives:

<?xml version="1.0" encoding="UTF-8" standalone="true"?>
-<w:document mc:Ignorable="w14 wp14" xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
    xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml" xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
    xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" 
    xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w10="urn:schemas-microsoft-com:office:word" 
    xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" 
    xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:v="urn:schemas-microsoft-com:vml" 
    xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" 
    xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas">
    -<w:body>
        -<w:p w:rsidRDefault="00AC700E" w:rsidR="009C1713">
            <w:bookmarkStart w:name="_GoBack" w:id="0"/>
            -<w:r w:rsidRPr="00AC700E">
                -<w:rPr>
                    <w:b/>
                 </w:rPr>
                 <w:t>Peace</w:t>
            </w:r>
            <w:bookmarkEnd w:id="0"/>
                -<w:r>
                    <w:t xml:space="preserve"> peace</w:t>
                </w:r>
         </w:p>
         -<w:sectPr w:rsidR="009C1713">
             <w:pgSz w:w="11906" w:h="16838"/>
             <w:pgMar w:gutter="0" w:footer="708" w:header="708" w:left="1440" w:bottom="1440" w:right="1440" w:top="1440"/>
             <w:cols w:space="708"/>
             <w:docGrid w:linePitch="360"/>
         </w:sectPr>
     </w:body>

So from the above, I take it that bold is <w:b/>?

Have you tried setting inline styles on the HTML body?

Member Avatar for diafol

I agree. Open html in Word and then you can use a macro to autoformat.

Member Avatar for soldierflup

Ever tried the PHPWord library ?
You can download it here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.