PDA

View Full Version : Com


g7star
08-27-2002, 09:35 AM
Can I get full list of COM components?
I found some examples at http://php.benscom.com/manual/en/class.com.php
But I need more.

And is there anyway that I can save html and/or php files to hard disk?
So that I can save it as a MS Word file like..

$word->Documents->Open("C:\\Google.htm");
$word->Documents[1]->SaveAs("C:\\Google.doc",1);

I want to make it done with one button click.

Thank you in advance.

Daniel

scoutt
08-27-2002, 10:03 AM
http://www.php.net/manual/en/ref.com.php
http://www.microsoft.com/Com/resources/comdocs.asp

no you can't do what you are asking. to use word you have to have word installed on the server, it has nothing to do with the client side. also the only way to get them to save it is to have a link for them to click on and hope that they don't have word installed on their machine so it will save it instead of open it.

g7star
08-27-2002, 10:59 AM
In fact, I'm the server side.
And the server has MS Word installed.
And those Word files will be saved in the server.

When I open the saved .doc file, I want to see it formatted(as seen in web-browser; without html tags). Actually, that's why I want it to save it as html file first. (I will delete the .html file after save it as .doc file with COM.) If I just copy and paste then, it will copy and paste as text format. I couldn't find any "Save As" function in HTML or PHP. Well, if I can invoke the "Save As" function of the browser, it would be great. Well, that's what I need.

I've been through those web pages.. But not enough time to be a COM programmer. Maybe there's more practical site??

Thank you.

scoutt
08-27-2002, 12:26 PM
ahh I see, that makes more sense. but why open a html file first? aren't the users entering text into it? did you try this

$word->Selection->TypeText("This is a test...");
$word->Documents[1]->SaveAs("Useless test.doc");


that should work and is almost like you have it. not sure where it saves it as I can't test it.

g7star
08-27-2002, 12:59 PM
Yes, that will work.
But I'm trying to save the whole page which will be generated from database and PHP rather then user input.
So basically it will be [Save this page as *.doc file] button.

Any idea?
Thank you.

scoutt
08-27-2002, 01:25 PM
well after the page is done generating then why couldn't you put it in a variable then when they click save (a form button) it gets sent to another page where it gets saved using the
$word->Documents[1]->SaveAs("Useless test.doc");

I would love to test this and I have always wanted to run it but never can as my server doesn't support it. so all I can do is speculate, sorry.

g7star
08-27-2002, 01:36 PM
Can I put a whole page?
From and including <?php to ?> ? or <html> to </html> ?
One page possibly contains multiple submits, functions, and tables generated by other functions.

Again, I want to save whole page including page layout, font setups, and pictures.. not just text data. That's the reason I want to save it as html first.(Well, they are really php files though.. that could be another problem.)

Thank you for your help.

scoutt
08-27-2002, 01:39 PM
yeah I am not sure if it is possible. from what it sounds like you want to create a page that will always be dynamically created and then save teh out come as teh user sees it, is that correct? not sure if that is possible because you never know what the page will be. hmmm let me think on that.

g7star
08-27-2002, 02:13 PM
1. in MS Internet Explorer
File->Save As... abc.html

2. in MS Word
File->Open abc.html
then File->Save As... abc.doc

I want to do exactly same above in script.

I think following is equivalent to 2.
$word->Documents->Open("C:\\abc.htm");
$word->Documents[1]->SaveAs("C:\\abc.doc",1);

But I coudln't get 1.

Hey, I really thank you, scoutt.

torrent
08-27-2002, 05:02 PM
2. in MS Word
File->Open http://www.example.com/abc.html
then File->Save As... abc.doc

You mention you want to save the <?php ?> bit. No can do I'm afraid as you will only be able to open the page through a HTTP connection, therefore all it's PHP content will be parsed. If you mean can you open a web page whose content is generated by PHP then, yes, as Word will not care about that.

g7star
08-29-2002, 11:47 AM
Thank you for your help.
Yeah.. I'm almost there but it seems MS Word has some parsing problem as you said.

If I make it
$word->Documents->Open("http://localhost/projects/reports.php");
It works fine...
But if I give some options like
$word->Documents->Open("http://localhost/projects/reports.php?name=daniel&id_num=001");
It ignores "?" and whatever follows.

Will there be any solution for this?

Daniel

torrent
08-29-2002, 12:01 PM
Hmm...are you sure it ignores the query part of the URI? I don't think that will be the case. What's more likely is that passing that query doesn't generate anything. Some questions:

1) Do you have register_globals Off?
2) If so, are you using either $HTTP_GET_VARS[] or $_GET[] (depending upon version of PHP you are running) to capture the variables being passed in by the query line?
3) What happens if you type http://localhost/projects/reports.php?name=daniel&id_num=001 directly into the address bar? Do you see the output you expect?

I cannot see COM having any affect on queries being passed by URI as opening a document over the web is governed by an RFC, COM could not alter this in anyway.

Can you post the reports.php code?

g7star
08-29-2002, 01:25 PM
1) I tested it with register_globals Off but there's no real difference. (MS Word pops up a sec. with this option Off)

2) Yes, I tried it. (Actually with $_SERVER['QUERY_STRING'])

3) Yes, it works if I type that in the IE address bar.
But it doesn't work on $word->Documents->Open("http://localhost/projects/reports.php?name=daniel&id_num=001");

The code I posted before is not real. I just wanted to illustrate my situation simple.

The real code is..

<?php
// episode.php
$perm_level = $cpt_db->getPermissions(-1);

$ep_idx = (!empty($ep_idx))?$ep_idx:1;
$sqlString = 'SELECT * from episodes';
$sqlString .= ' WHERE ep_idx='.$ep_idx;

$qry_ep = $cpt_db->query($sqlString);
$nrows_ep = $cpt_db->qry_numrows($qry_ep);
if ($nrows_ep == 0) {
exit();
}
$ep_id = $cpt_db->qry_result($qry_ep,0,'ep_id');
$ep_name = $cpt_db->qry_result($qry_ep,0,'ep_name');
print '<SCRIPT language="javascript">top.document.title="'.$ep_id.' - '.$ep_name.'"</SCRIPT>';

print '<a name="top"><H1>'.$ep_id.'&nbsp;-&nbsp'.$ep_name.'</H1></a>';
print '<table border="1"><tr><td valign="top">';
print '<table border=1>';
if ($perm_level >=5) {
print '<form name = "epUpdate" action = "update/ep_update.php">';
print '<input type="hidden" name = "ep_idx" value = "'.$ep_idx.'">';
print '<TR><TD>Code: <INPUT type="text" name="ep_id" size=3 maxlength=3 value="'.$cpt_db->qry_result($qry_ep,0,'ep_id').'"></TD><TD>Name: <INPUT type="text" name="ep_name" value="'.$cpt_db->qry_result($qry_ep,0,'ep_name').'"></TD></TR>';
print '<tr><td valign="top" colspan=2>Notes: ';
print '<textarea rows = "3" cols="40" name = "notes">';
print $cpt_db->qry_result($qry_ep,0,'notes');
print '</textarea></TD></TR>';
print '<TR><TD align="center" colspan=2><input type="submit" name = "epUpdater" value = "Update"></TR></TD>';
print '</form>';
} else {
print '<tr><td valign="top">Notes: ';
print $cpt_db->qry_result($qry_ep,0,'notes');
}
print '</table>';
print '<table>';
print '<td><a href="#shots" class="navLink">Shots&nbsp;</a></td>';
print '<td><a href="#Characters" class="navLink">Characters&nbsp;</a></td>';
print '<td><a href="#sets" class="navLink">Sets&nbsp;</a></td>';
print '<td><a href="#props" class="navLink">Props&nbsp;</a></td>';
print '<td><a href="#vehicles" class="navLink">Vehicles&nbsp;</a></td>';
print '</tr></table>';

$prn_status=$cpt_db->displayStatus('episode','ep',$ep_idx);
//Location color legend
$sqlString = 'SELECT * FROM shots LEFT JOIN sets USING(s_idx) WHERE ep_idx='.$ep_idx.' AND (shots.deleted="f" or shots.deleted is null) AND shots.s_idx >0 GROUP BY shots.s_idx';
$qry_legend = $cpt_db->query($sqlString);
$numrow_legend = $cpt_db->qry_numrows($qry_legend);
$wrapRows = 6;

$sqlString = 'SELECT * FROM color';
$qry_color = $cpt_db->query($sqlString);
$numColors = $cpt_db->qry_numrows($qry_color);

print '<H3><a id="legend">Location Color Legend</a></H3>';
print '<TABLE BORDER=0>';
//session_register("locColor");
for ($s=0 ; $s<$numrow_legend ; $s++){
if ($s % $wrapRows == 0){
print '<TR>';
}
$curLoc = $cpt_db->qry_result($qry_legend,$s,'s_idx');
$locColor[$curLoc] = $cpt_db->qry_result($qry_color,($s % $numColors),'cr_id');
print '<TD width=10><DIV style="background-color:'.$locColor[$curLoc].'" width="100%">'.($s+1).'</TD>';
print '<TD>'.$cpt_db->qry_result($qry_legend,$s,'s_name').'</TD>';
print '<TD WIDTH=10>&nbsp;</TD>';
if (($s+1) % $wrapRows == 0 and $s > 0){
print '</TR>';
}
}
print '</TABLE>';

... omitted ...

/////////////// HELP //////////////////
// starting word
$word = new COM("word.application") or die("Unable to instanciate Word");

// if you want see thw World interface the value must be '1' else '0'
$word->Visible = 1;


//doc file location
//$word->Documents->Open("D:\\test.html"); // works

//$word->Documents->Open("http://www.codeproject.com/useritems/AdvComboBox.asp"); // works
//$word->Documents->Open("http://tracker/cpt/index.php"); // works
//$word->Documents->Open("http://localhost/LocalTracker/wwwroot/cpt/mainPage.php?".$_SERVER['QUERY_STRING']; // doesn't work
//$word->Documents->Open("http://localhost/LocalTracker/wwwroot/cpt/mainPage.php?inc_page=episode&ep_idx=1"); // doesn't work
$word->Documents->Open("http://localhost/LocalTracker/wwwroot/cpt/reports.php"); // works



//html file location '1'mean HTML format
$word->Documents[1]->SaveAs("C:\\test.doc",1);

//closing word
$word->Quit();


//free the object from the memory
$word->Release();
$word = null;
?>

print $_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'];
//print 'mainPage.php?'.$_SERVER['QUERY_STRING'];


But you don't really need to understand the code here.
Just see things after
/////////////// HELP //////////////////


Well.. this page is called by this

<?php
// mainPage.php
require_once("cpt.php");

?>
<html>
<head>
<TITLE><?php print "Production Tracker"; ?></TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<?php
print '<link rel="stylesheet" href="'.$cpt_styleSheet.'" type="text/css" media="SCREEN">';
print '<link rel="stylesheet" href="'.$cpt_print_styleSheet.'" type="text/css" media="PRINT">';
?>
<body class="mainPage">
<?php
if ( empty($inc_page) ) {
$inc_page = 'home';
}
include_once( $inc_page.'.php');
?>
</body>
</html>

As you can see, a page is displayed according to the parameters.(in our case mainPage.php?inc_page=episode&ep_idx=1) But it seems the episode page is not get called. (It dies somewhere.)

Again it works when I put it in the address bar.

torrent
08-29-2002, 02:09 PM
Okay, I have justed tested opening a document via a URI (with a query) and saving it to c:\test.doc. I can absolutely confirm that it works.

Take this script and run it from your Windows server<?php

/////////////// HELP //////////////////
// starting word
$word = new COM("word.application") or die("Unable to instanciate Word");

// if you want see thw World interface the value must be '1' else '0'
$word->Visible = 1;
$word->Documents->Open("http://www.ski-info-online.com/Siteowners/PHP/NextPrev-Links.php?page=5");
//$word->Documents->Open("http://localhost:8080/SiteOwners/PHP/NextPrev-Links.php"); // uncomment this to see the basic URI working


//html file location '1'mean HTML format
$word->Documents[1]->SaveAs("C:\\test.doc",1);

//closing word
$word->Quit();


//free the object from the memory
$word->Release();
$word = null;
?>You should get a list of ski resorts, the last of which is Deer Valley. If you remove the query line (i.e. everything after the ?) then you will get different results. One thing I noticed was that you are instantiating the COM class twice! the se4cond of which simply overwrites the first. If you want to have two COM objects open simultaneously then you will need give them different names.

g7star
08-29-2002, 02:51 PM
Thanks a lot!
Now I know it's working.

But not my case..
Yeah.. It makes an infinite loop on previous code.:D
But even after fixing it, there's still problem. The file I'm calling includes or requires other files.. and the Word saves only the 1st page(log-in page in the case) where I mean to have the last one in the order. (The IE displays only the last one and that makes sense.)

Oh.. well.. I guess I can't change the COM specs, right?

Daniel

torrent
08-29-2002, 03:01 PM
I am actually very confused as to what exactly you mean. Includes or requires will not have any affect whatsoever on the result. Wanna know why? By the time any information is sent to Word it has already been parsed by the server, that means all the includes have been included and the results are part of the information returned.

You will see exactly the same in your Word Document as you will in your browser (if you enter the same URI in the address bar).

g7star
08-30-2002, 01:58 PM
I got it.. well.. sort of..
The thing was when I invoked
$word->Documents->Open(filename and paramters);
It includes another file and that includes another file and that... ... until it gets to the login file.
But for some reason it's out of session.. and requires to input id and password again. And that was where the file was saved.

I'm not sure if it is the proper way but anyways, I passed the id and password in a function call like
$word->Documents->Open(filename and paramters including id and password);
And it worked.

BUT!!
It is way too slow!
Most of time it gets browser time out.
(It even takes long~ to open the file with Word.)
You might say "Why don't you just call the one that generates whatever page you want to save?"
My answer is.. most functions used here are OO and COM function call doesn't recognize the scope it's in.. meaning need to all over again inside
$word->Documents->Open("HERE!!")

Any comments?