Really feel this is like a series, just finished save as HTML, and made a save as word.
Here's how it works:
In fact, the principle is not difficult, after testing, fwrite write HTML code, as long as the CSS style inline style written, the last saved as Word can display the corresponding style content (about inline, outreach, embedded style definition, please self-search). For example, the HTML code reads:
<div style= ' color:red;font-weight:bold; ' ></div>
Then you can see the red bold text in the generated word. However, if the div is just written in class= ' className ' form, Word will not parse it.
Based on this idea, the CSS style that was originally written in the head is appended directly to the table, and the scientific name, called an inline style sheet (internal style sheet), is changed to inline style to save the style as word.
My initial method is to copy the HTML class Phpexcel, modified as the word class, but in the process of modification, found the Setuseinlinecss method, from the method name can be seen, this is set whether the use of inline style, sad to urge, I had already changed half the time. Only to find that the original add this line of code, this shows, read through the code is how important, fortunately the original author of the code written very good, or else only headache to read ... Seriously suspected that the original author was also to save as word, so deliberately added such a feature ... (⊙﹏⊙) b
However, there is another benefit, when the source code for the PDF saved as HTML, but also added the TAB function, which will be generated for multiple sheet navigation... It is an egg, it may be used later.
PHP Save Excel as Word