Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read .doc files and write in html files?

Status
Not open for further replies.

cherphas

Programmer
Jun 5, 2002
24
CA
Is there a way to read a .doc file, which has rich text format, and write the content in an html file? I have tried to read a .txt file and wrote the content in html with this code.

<CFFILE ACTION=&quot;Read&quot;
FILE=&quot;C:\CFusionMX\ VARIABLE=&quot;Message&quot;>

<CFOUTPUT>#Message#</CFOUTPUT>


It works but it didn't detect line breaks, paragraphs. Everything was one bit block of text. Is there a way to detect the a line breaks and add <br> tags or even detect bolded types and add <b></b> to that text? I'm new to Coldfusion by the way. The reason i'm asking is I have to do a site for a client. They don't do html stuff so if they had the updates of the sites content in a .doc file, they would just have to put the file in a folder and it would update itself. I don't see any way of doing this but I'm just asking to make sure. Do any of you have any suggestions to have my clients update the site without using Dreamweaver or knowing HTML?

Thanks,
Joël
 
Ok, I now have this code:

<CFFILE ACTION=&quot;Read&quot; FILE=&quot;C:\CFusionMX\ VARIABLE=&quot;Message&quot;>

<CFLOOP List=&quot;#message#&quot; Index=&quot;rc&quot; Delimiters=&quot;#Chr(10)#&quot;>
<CFOUTPUT>
#rc#<BR>
</CFOUTPUT>
</CFLOOP>

this add the line breaks. but I haven't a clue how to dislay bolded text or alignent.
 
A .txt file is a simple ASCII text format. I doesn't understand bolds or alignment, nor would we want it to.

A .doc file or an .rtf file has formatting tags... but good luck parsing them, they're a royal PITA. There are, I believe, custom tags available in the macromedia.com tag gallery that start to handle them... but I've found they're always a version or two behind on the spec, or simply don't implement the full range of tags. There might be a commercial tag available that does a little better job... but they'd probably be a bit expensive.

My suggestion is to use something like soEditor (used to be ezEdit - they have a LITE version you can download for free, or Ektron's eWebEditPro (
soEditor is a WYSIWYG HTML editor based wholely on CFML... well, and Javascript, since it actually uses DHTML to create the interface. eWebEditPro is a java applet equivilent, and comes with documentation on how to integrate it into, and call it from, your ColdFusion pages.

Both of these basically allow you to embed an editor directly into a web form. These editors allow the user to enter text, then apply formatting (bolding, center, right justify, subscript, etc) simply by selecting text and clicking on the editors toolbar or selecting from the editor's menu. Both allow you to limit the number of options available to the user (don't allow them to make hyperlinks, for example) and can utilize your CSS stylesheets.

The nice thing about doing it this way is that you can embed it in a web form that also collects other non-html information. Like a form field for &quot;page name&quot;, a listbox for &quot;associate products&quot;, a calendar picker to designate a sunrise/sunset date, and then just use the HTML editor for the content of the page. This way, you wouldn't have to parse through, say, a Word Doc to find the page name or header, etc.
Hope it helps,
-Carl
 
Oh... and if you're stuck on using a .txt file, rather than the loop you posted above, simply use a replace function... like:

Code:
<CFFILE ACTION=&quot;Read&quot; FILE=&quot;C:\CFusionMX\[URL unfurl="true"]wwwroot\TaskList\textFile.txt&quot;[/URL] VARIABLE=&quot;Message&quot;>

<CFOUTPUT>#replace(message,&quot;#Chr(10)#&quot;,&quot;<BR />&quot;,&quot;ALL&quot;)#</CFOUTPUT>

You'll probably be much happier with the performance. Hope it helps,
-Carl
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top