Click to See Complete Forum and Search --> : Sending instructions from PHP to Word


XTI
03-05-2008, 03:14 PM
I am using PHP to get data from MYSQL and sent it to templates in MS Word to generate documents such as catalogue items.
For example template in word has:

Color: <Variable1>

where value for the Variable1 is coming from database.

Problem is even if there is no value for this variable that line in Word (Color: ....) will show up in the document.

Can anyone suggest a way to remove that line and space required for it, if variable1 is NUL or empty?

In another word how can in the Word document only show the lines that there is a value for it in the database and not see it if it is not filled??

Thanks a bunch in advance

XTI

TheRave
03-06-2008, 03:09 AM
MS Word :S, not the best thing to be used in conjunction with an open source web language. PDF would be a better option. Although if you want to stick with Word, then ASP would be better than PHP.

Anyway, ignore my ramblings. Can you post any of your current code so we can get a feel of what's going on in more detail?

XTI
03-06-2008, 02:29 PM
Quite frankly I am amazed at the quality and wealth of answers I am getting at this forum! Way to go guys!

XTI
03-06-2008, 07:35 PM
sarcasm

felgall
03-07-2008, 12:09 AM
well PHP and Word are like oil and water - they don't go together too well. Word also isn't really suitable for the web due to the major privacy issues with past versions of content and who updated it on which computer being hidden away in documents to cause embarrasment at a later date. Also Word is a proprietary Microsoft format so only Microsoft programs understand the format well enough to update it properly. PDF is the appropriate equivalent format for web use and there is a huge selection of tools available to create and update PDFs from a range of server side languages. If any functions for updating Word documents from server side languages do exist they would be either ASP or .NET.

TheRave
03-07-2008, 02:29 AM
sarcasm

It makes it really easy for us to help you when you don't post your current code...













....SARCASM.

felgall
03-07-2008, 04:25 AM
It makes it really easy for us to help you when you don't post your current code...

What, your crystal ball is malfunctioning the same as mine is. What a coincidence.

TheRave
03-07-2008, 04:38 AM
I've been meaning to get it fixed since it died from overuse.

MrCoder
03-07-2008, 06:23 AM
Source code is overrated..



Why not just make a HTML file then rename it using the .doc extension?

Word will open and convert it for you..

XTI
03-08-2008, 02:06 PM
Thanks for the answers.
1.There is no problem with my existing code so posting it here won't help anyone in coming up with a solution.
Problem is not sending variables to Word. It is to remove titles for these variables from the Word document when the value of variable is NUL or empty.for example:

NAME: <variable1>
POSITION: <variable2>
EXTENSION: <variable3>

Let's say variable 2 is empty (no position) hence we do not want to see the line that says "POSITION: --------------- "
See what I mean?

I have set up template in Word and am filling the variables from MYSQL. But I have not figured out a way to change the Template in case the variables are empty (which might happen).
An alternative way would be printing everything to Word just like print in any programming language such as C. But how can you send print commands to Word instead of pronters? Is it possible?

2.I do not want to generate HTML and open it with Word because the formating and page alignment is very precise and HTML pages when printed depend to some degree to printer setting. It has to be Word.

Thanks in advance.
XTI

felgall
03-08-2008, 03:24 PM
2.I do not want to generate HTML and open it with Word because the formating and page alignment is very precise and HTML pages when printed depend to some degree to printer setting. It has to be Word.

If your layout needs to be precise then Word is not the appropriate way to go as different versions of Word will display it differently, it will look rather different if people don't have all the fonts you used, and if they don't have Word and open it in a more readily available word processor such as open office it will look completely different.

For precisely laid out pages the only option where everyone gets to see exactly the same thing is PDF.

XTI
03-08-2008, 04:58 PM
Farnmers have a saying. It goes:
"I keep saying he is male, they say milk it!"
I keep saying it has to be Word for reasons which I can not argue with or change, you guys keep on suggesting to change to something else!
I know it is easier to use PDF or not use PHP and MYSQL and go with VB and Microsoft applications, but requirements for this proejct are PHP MYSQL and Word.
So question is how can this be done with Word. I know we programmes constatnly have to keep pushing the envelop and borders of possible and impossible. This is one of those challenges.
Any suggestions is appreciated.

felgall
03-09-2008, 03:15 AM
The simplest solution would be for you to buy Word off of Microsoft (should only cost you a billion dollars or so) and then you will have access to the information on how Word works that you will need to be able to build a PHP to Word interface to do what you want. Of course if Microsoft wont sell you Word then you'd need to buy the whole company instead.

A cheaper solution would be to abandon PHP and move to hosting that supports .NET where an interface to Word is already available.

Trying to get PHP and Word to communicate is like trying to fly your boat to the moon - it could be done but the boat would need lots of modifications in order to get there and buying a spaceship to use instead would be the cheaper option. In the case of PHP and Word the cheaper options to get it to work are to either replace Word with PDF (cheapest option) or replace PHP with .NET (next cheapest option). Reverse engineering Word would be the third cheapest option and would probably only take you about 50 years or so to do yourself (by which time the version you reverse engineered would be long dead) or cost you a few million in wages to employ the staff necessary to do the job in a year or two.

Your current requirements are impractical unless you have the necessary millions or billions to spend. Changing the requirements to a combination that can actually work together already would be much easier.

XTI
03-09-2008, 01:07 PM
To know it all?!
I let you know when I completed the job. Nothing is impossible.

felgall
03-09-2008, 01:48 PM
I never said it was impossible, just impractical. You have made the task thousands of times more difficult than it needs to be by selecting incompatible technologies.

MrCoder
03-10-2008, 04:12 AM
If you open a word document and save it as HTML then change the extension to .doc and load it in to word it *should* be a perfect version of the original.

So export from word as HTML, edit in PHP as a flat text file then save it off with the .doc extension.

felgall
03-10-2008, 03:59 PM
That way should work provided that you save the file in Microsoft's proprietary HTML format (with all the conditional comments around the code to rebuild the Word document) rather than trying to filter it into regular HTML. I hadn't thought of that use for that file format before.

XTI
03-10-2008, 05:27 PM
I am amazed that you guys keep on talking, repeating the same thing (which by the way has no solution to my specific problem!) Why the heck do you repeat this?

To be useful:
1. Read the question
2. Keep in mind the exact requirements
3. Offer a suggestion ONLY if it is matching the above 2 points!

I don't have any problem genrateing Word documents from PHP or sending data to it. Even as it is right now my program is doing that just fine. Issue is removing specific headings/titles in the Word document when there are no values corresponding to them.

Please stick to the point.
THNX

felgall
03-10-2008, 08:34 PM
You have already been given all the solutions that are possible including all the stupid ones. The only one not previously suggested is to just completely abandon what you are trying to do completely.

Word is a proprietary format which means that only the people at Microsoft know what the codes in it mean. Doing substitutions for special markers in the file doesn't require a knowledge of what the rest of the content means. Making the changes you are asking about does require a knowledge of what those codes mean and no one apart from Microsoft staff know that.

To be able to do what you want you need the file in a format where the codes are in a format that can be recognised.

XTI
03-10-2008, 09:36 PM
Enough already felgall. Move along your comments are just waste of time. Just ignore this thread go waste somebody else's time.
In addition to the fact that you can't understand simple instruction apparently you can;t read and write. I posted the question and I am telling you: your suggestions are uselss, repetitious, heading for nowhere and a waste of time >>> To put it simple enough for you to get it: Move along. Not welcome here!
This idiotic repetition and argument is just blocking any meaningful answer anyone might want to suggest.
Igore this thread move along.

TheRave
03-11-2008, 03:40 AM
XTI, since you seem to be unable to understand the perfectly valid comments/answers to your problem, I suggest you try asking elsewhere for help.

Good luck with your search for answers.

And remember this line from program design:

- If your requirements are near impossible to meet or require some dirty coding then your requirements are most likely wrong and need to be reviewed.

MrCoder
03-11-2008, 05:01 AM
I am amazed that you guys keep on talking, repeating the same thing (which by the way has no solution to my specific problem!) Why the heck do you repeat this?

To be useful:
1. Read the question
2. Keep in mind the exact requirements
3. Offer a suggestion ONLY if it is matching the above 2 points!

I don't have any problem genrateing Word documents from PHP or sending data to it. Even as it is right now my program is doing that just fine. Issue is removing specific headings/titles in the Word document when there are no values corresponding to them.

Please stick to the point.
THNX

I have given you a perfectly valid solution to your problem, I have used the same method of editing word documents many times in the past with perfect results.
I don't think you studied my answer enough.

XTI, if the solution I have providing in my 2 post above does not meet your requirements then please explain why.

It is a very simple way of editing word documents.

I hope you haven't spent a vast amount of time creating a word document parser only to realize there is a much faster / easier way of doing it?

LiLcRaZyFuZzY
03-11-2008, 11:23 AM
Alright, XTI, we'll be asking you to keep your answers polite, also remember that all the users are donating their free-time, so don't be so harsh when the answer doesn't fit your needs exactly.