 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
02-05-2009, 10:52 PM
|
#1 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
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
__________________
|
|
|
|
02-05-2009, 11:54 PM
|
#2 (permalink)
|
|
The Contributor
Join Date: Jan 2009
Posts: 40
Thanks: 10
|
You could use a JavaScript editor like TinyMCE. That will allow you to keep all of the formatting when copied.
|
|
|
|
02-06-2009, 12:00 AM
|
#3 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Hmm, I suppose you could cobble something together with COM.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
02-06-2009, 12:06 AM
|
#4 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Quote:
Originally Posted by Scottymeuk
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
Hmm, I suppose you could cobble something together with COM.
|
What's COM?
__________________
|
|
|
|
02-06-2009, 12:11 AM
|
#5 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
|
|
|
02-06-2009, 12:57 AM
|
#6 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
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($sName, 8); //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
|
|
|
|
|
The Following User Says Thank You to sketchMedia For This Useful Post:
|
|
02-06-2009, 01:44 AM
|
#7 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Quote:
Originally Posted by Wildhoney
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
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($sName, 8); //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!
__________________
|
|
|
|
02-06-2009, 01:55 AM
|
#8 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
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.
|
|
|
|
The Following User Says Thank You to Wildhoney For This Useful Post:
|
|
02-06-2009, 02:07 AM
|
#9 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Quote:
Originally Posted by Wildhoney
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($szSaveDocument, 8);
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..
__________________
|
|
|
|
02-06-2009, 02:50 AM
|
#10 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
Quote:
Originally Posted by Tanax
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($szSaveDocument, 8);
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)
|
|
|
|
|
The Following User Says Thank You to sketchMedia For This Useful Post:
|
|
02-06-2009, 03:09 AM
|
#11 (permalink)
|
|
The Addict
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
|
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..
|
|
|
|
02-06-2009, 12:11 PM
|
#12 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Quote:
Originally Posted by sketchMedia
|
Thanks alot!
And yes, I hate that site.. :S
But thanks, I'll try it!
__________________
|
|
|
|
02-06-2009, 12:33 PM
|
#13 (permalink)
|
|
The Acquainted
Join Date: Oct 2007
Posts: 170
Thanks: 18
|
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).
|
|
|
|
02-06-2009, 12:39 PM
|
#14 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
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 
__________________
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|