TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 02-05-2009, 10:52 PM   #1 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default Text from Word-document

Hi!

I run the website for our neighbourghhood, and sometimes they have protocols that I need to publish on our website.

The problem is that when they write the protocol, they use Word.
If it's just text, it's working great to just copy, and paste it into the newsmanager I've coded.

However, sometimes they've used bold stuff, which is quite easy to just use <strong>. The real problem is when they use tables.

So I'm wondering if PHP can access a worddocument's properties and copy the text from it(with a custom function perhaps?), and if it locates a table, write out a html table that matches it? Bold text to be strong, and italic text as it is.


Thanks in advance!
Tanax
__________________
Tanax is offline  
Reply With Quote
Old 02-05-2009, 11:54 PM   #2 (permalink)
The Contributor
 
Join Date: Jan 2009
Posts: 40
Thanks: 10
Scottymeuk is on a distinguished road
Default

You could use a JavaScript editor like TinyMCE. That will allow you to keep all of the formatting when copied.
Scottymeuk is offline  
Reply With Quote
Old 02-06-2009, 12:00 AM   #3 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Hmm, I suppose you could cobble something together with COM.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 02-06-2009, 12:06 AM   #4 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by Scottymeuk View Post
You could use a JavaScript editor like TinyMCE. That will allow you to keep all of the formatting when copied.
Yes, I've thought about that. But that doesn't support tables, does it?

Quote:
Originally Posted by sketchMedia View Post
Hmm, I suppose you could cobble something together with COM.
What's COM?
__________________
Tanax is offline  
Reply With Quote
Old 02-06-2009, 12:11 AM   #5 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

How are their tables typically laid out in the text files?
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 02-06-2009, 12:57 AM   #6 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

http://www.microsoft.com/com/default.mspx

You could do something like this, however I believe you will need word installed on your server!(help me out windows guys) which may or may not be possible, any who this is how you would do it (I think ).
PHP Code:
<?php
try
{
    
$sDoc realpath('word.doc');
    
$aPath pathinfo($doc);
    
$sName $aPath['filename'];

    
$pWordCOM = new COM("word.application");
    
$pWordCOM->Documents->Open('originalDoc.doc');
    
$pWordCOM->ActiveDocument->SaveAs($sName8); //8 is the number for htm ext
    
$pWordCOM->ActiveDocument->Close(false);
    
$pWordCOM->Quit();
    unset(
$pWordCOM);
}
catch(
Exception $e)
{
?>
    <h4>Error: </h4>
    <p><?php echo $e->getMessage(); ?></p>
    <br />
    <h4>Stack Trace</h4>
    <pre>
    <?php echo $e->getTraceAsString(); ?>
    </pre>
<?php
}
Basically uses COM to open word, then open the document, then saveAs htm.

Not tested btw.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)

Last edited by sketchMedia : 02-06-2009 at 01:04 AM. Reason: typo
sketchMedia is offline  
Reply With Quote
The Following User Says Thank You to sketchMedia For This Useful Post:
Tanax (02-06-2009)
Old 02-06-2009, 01:44 AM   #7 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
How are their tables typically laid out in the text files?
Like a basic table in word? There's a table tool in word that allows you to make a table.. Like that

Quote:
Originally Posted by sketchMedia View Post
http://www.microsoft.com/com/default.mspx

You could do something like this, however I believe you will need word installed on your server!(help me out windows guys) which may or may not be possible, any who this is how you would do it (I think ).
PHP Code:
<?php
try
{
    
$sDoc realpath('word.doc');
    
$aPath pathinfo($doc);
    
$sName $aPath['filename'];

    
$pWordCOM = new COM("word.application");
    
$pWordCOM->Documents->Open('originalDoc.doc');
    
$pWordCOM->ActiveDocument->SaveAs($sName8); //8 is the number for htm ext
    
$pWordCOM->ActiveDocument->Close(false);
    
$pWordCOM->Quit();
    unset(
$pWordCOM);
}
catch(
Exception $e)
{
?>
    <h4>Error: </h4>
    <p><?php echo $e->getMessage(); ?></p>
    <br />
    <h4>Stack Trace</h4>
    <pre>
    <?php echo $e->getTraceAsString(); ?>
    </pre>
<?php
}
Basically uses COM to open word, then open the document, then saveAs htm.

Not tested btw.
Based off of what I read on php.net about COM, that looks like it could work. However, I didn't find any info about saveAs function, and about the integer you pass with it either.. Where did you find that information?

Thanks!
__________________
Tanax is offline  
Reply With Quote
Old 02-06-2009, 01:55 AM   #8 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

That works SketchMedia, with a little bit of re-working. I used the following code and it output a txt document for me, with a folder as well with 2 other files in:

php Code:
try
{
    $szOpenDocument = 'C:/wamp/www/word/word-open.doc';
    $szSaveDocument = 'C:/wamp/www/word/word-save.txt';

    $pWordCOM = new COM("word.application");
    $pWordCOM->Documents->Open($szOpenDocument);
    $pWordCOM->ActiveDocument->SaveAs($szSaveDocument, 8);
    $pWordCOM->ActiveDocument->Close(false);
    $pWordCOM->Quit();
    unset($pWordCOM);
}
catch(Exception $e)
{
    die($e->getMessage());
}
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
The Following User Says Thank You to Wildhoney For This Useful Post:
Tanax (02-06-2009)
Old 02-06-2009, 02:07 AM   #9 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by Wildhoney View Post
That works SketchMedia, with a little bit of re-working. I used the following code and it output a txt document for me, with a folder as well with 2 other files in:

php Code:
try
{
    $szOpenDocument = 'C:/wamp/www/word/word-open.doc';
    $szSaveDocument = 'C:/wamp/www/word/word-save.txt';

    $pWordCOM = new COM("word.application");
    $pWordCOM->Documents->Open($szOpenDocument);
    $pWordCOM->ActiveDocument->SaveAs($szSaveDocument, 8);
    $pWordCOM->ActiveDocument->Close(false);
    $pWordCOM->Quit();
    unset($pWordCOM);
}
catch(Exception $e)
{
    die($e->getMessage());
}
Thanks!

Just a question though.
Where do you find info about the Documents and Open thingy?
As used here:
PHP Code:
$pWordCOM->Documents->Open($szOpenDocument); 
Also, these things?
PHP Code:
$pWordCOM->ActiveDocument->SaveAs($szSaveDocument8); 
As said before, I found the info about the COM class, but it didn't have any of those functions.. ActiveDocument nor Documents..

Anyways, thanks! However, I didn't really want to save it as a txt.. I wanted to get the HTML code so I can post it on the website, without having to write the HTML code for bold and tables wherever they are used..
__________________
Tanax is offline  
Reply With Quote
Old 02-06-2009, 02:50 AM   #10 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Originally Posted by Tanax View Post
Thanks!

Just a question though.
Where do you find info about the Documents and Open thingy?
As used here:
PHP Code:
$pWordCOM->Documents->Open($szOpenDocument); 
Also, these things?
PHP Code:
$pWordCOM->ActiveDocument->SaveAs($szSaveDocument8); 
As said before, I found the info about the COM class, but it didn't have any of those functions.. ActiveDocument nor Documents..

Anyways, thanks! However, I didn't really want to save it as a txt.. I wanted to get the HTML code so I can post it on the website, without having to write the HTML code for bold and tables wherever they are used..
Alot of searching on MSDN (hateful site).

http://msdn.microsoft.com/en-us/library/bb216319.aspx
http://msdn.microsoft.com/en-us/library/bb221597.aspx
http://msdn.microsoft.com/en-us/library/bb238158.aspx

It should save it in html format, theoretically.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
The Following User Says Thank You to sketchMedia For This Useful Post:
Tanax (02-06-2009)
Old 02-06-2009, 03:09 AM   #11 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

I have been looking for a way to do this on a linux shared server, meaning no word to open. Anyone got a solution for that? I had to ask..
CoryMathews is offline  
Reply With Quote
Old 02-06-2009, 12:11 PM   #12 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by sketchMedia View Post
Thanks alot!
And yes, I hate that site.. :S

But thanks, I'll try it!
__________________
Tanax is offline  
Reply With Quote
Old 02-06-2009, 12:33 PM   #13 (permalink)
The Acquainted
 
Join Date: Oct 2007
Posts: 170
Thanks: 18
maZtah is an unknown quantity at this point
Default

Why don't you code an option so that a user can upload files with a newsitem for example? That way the user just can upload the Word document to the server (and visitors can download the document).
maZtah is offline  
Reply With Quote
Old 02-06-2009, 12:39 PM   #14 (permalink)
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default

Because these so called "users" are 60 years old, and don't know how to use a computer, nontheless upload files xD only thing they know is Word, so I have to do all the news publishing. However, yes, I could allow the visitors from our neighbourghhood to download the word document, but better to actually be able to publish something, so that's why
__________________
Tanax is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Input-field with captured text falsely empties on click sidisinsane Javascript, AJAX, E4X 5 12-05-2008 12:12 AM
What is a Variable? codefreek Absolute Beginners 7 07-01-2008 08:29 PM
Need help editing/saving text files webosb Absolute Beginners 6 12-14-2007 06:43 PM
Text Limiter WinSrev Advanced PHP Programming 5 12-04-2007 09:58 PM
PDF Creation - Help! Sam Granger General 7 10-31-2007 11:32 AM


All times are GMT. The time now is 09:17 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design