473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Converting HTML content to word doc using PHP code

1
Hi,

I want to Convert a HTML content to word doc using PHP code. pls help
Nov 12 '07 #1
2 4667
Atli
5,058 Expert 4TB
Hi. Welcome to TSDN!

The simplest way to create a Word document is to simply use the Filesystem Functions to create a .doc file containing HTML markup.

The other, slightly more complex way, is to use COM objects to create an actual Word Document. In order for this method to work, you need to have Word installed on the server. Then you can do something like this:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. # Create a Word object
  3. $word = new COM("word.application") or die ("Couldn't create a Word object");
  4. $word->visible = 1;
  5.  
  6. # Create a document and add some text
  7. $word->Documents->Add();
  8. $word->Selection->TypeText("This document was created in PHP!");
  9.  
  10. # Save the document and release the Word object
  11. $word->Documents[1]->SaveAs("sampleword.doc");
  12. $word->Quit();
  13. $word->Release();
  14. $word = null;
  15. ?>
  16.  
Note that Microsoft recommends against using Office in this manner. See this article for more on that.

The last and most complex method would be to create your own Word parser. To do this you would need pretty detailed info on the inner workings of a Word Document.
Nov 12 '07 #2
Hi,

The last and most complex method would be to create your own Word parser. To do this you would need pretty detailed info on the inner workings of a Word Document.
I've often wondered about a 4th way: create OO.o XML (this should be relatively easy), and then callling OpenOffice to re-save the XML as .doc I've never gotten around to trying this, but it should not be hard..
It would, I think, be the easiest way if you want extensive formatting in .doc....

Anybody tried this?

greetz,

Paul
Nov 12 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Phil Powell | last post by:
Based on the information I read in www.php.net on the header command I wrote a dummy test script to try to convert the contents of $stuff to MS Word downloadable format: ...
17
by: mickjames | last post by:
Hi, I'd like to include the whole web page content (as opposed to just the headlines) into RSS/XML to enable people to read them via rss feed readers. Question: how to convert HTML elements...
20
by: Al Moritz | last post by:
Hi all, I was always told that the conversion of Word files to HTML as done by Word itself sucks - you get a lot of unnecessary code that can influence the design on web browsers other than...
1
by: unotin | last post by:
I have an application in ASP that exports to Word using the Response.ContentType method. The application references another ASP page through the img tag that uses a Response.BinaryWrite (of an...
3
by: adam | last post by:
Hi, I'm building a tree control that lazily loads branches of the tree using the document.load() method. The external XML document that is loaded is generated by a servlet as XHTML. What I...
1
by: KK | last post by:
Hi, I need to save certain content to SQL server and then use SQL Server indexing facility to search. SQL Server have recomended using Image data type with a filter type (for .htm, .doc etc..)...
1
by: darrel | last post by:
I have two issues: 1) The WYSIWYG content editor we're using for our CMS doesn't truly support xhtml. 2) .net doesn't truly support xhtml my question is if there is a .net...
9
by: anupamjain | last post by:
Hi, After 2 weeks of search/hit-and-trial I finally thought to revert to the group to find solution to my problem.(something I should have done much earlier) This is the deal : On a JSP...
11
by: Grischa Brockhaus | last post by:
Hi, I'm trying to produce a div layout containing a header on the top with fixed height, a footer on the bottom using fixed height and a content layer using what's left of the browsers window. ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.