nirvana Posted March 27, 2006 Share Posted March 27, 2006 Hi,I have the following codes written to create word document as per tutorial. There are some modifications I did and when I tested apart from echoing all the data it doesn't generate the word doc and it doesn't give any errors either.Is there anything I am missing to do? The server is installed with MS Word as well.If this is not the right forum and I need to post this in COM forum, can someone please direct me to the right forum as this is the only forum I have been posting my problems?thanks in advanceNirvana<?php//This program is to generate datasheet//Connect to Server and Databaseinclude ("Connection.php");//Get device number$device = 2886;//Minimum Insertion Loss Queryprint "$device <br>\n";$IL = @mysql_query("SELECT MIN(measured_parameter)FROM test join test_data where test.test_number = test_data.test_number AND test_descriptor = 'Min IL (dB)' AND tracked_component_number = '$device' AND attenuation = 0 GROUP BY temperature");$row = mysql_num_rows($IL); print "$row<br>"; $i = 0; if ($i < $row) { $value = mysql_fetch_row($IL); $bmk_IL_0 = $value[0]; echo ("$bmk_IL_0 <br>"); } $i = $i++; if ($i < $row) { $value = mysql_fetch_row($IL); $bmk_IL_25 = $value[0]; echo ("$bmk_IL_25 <br>"); } $i = $i++; if ($i < $row) { $value = mysql_fetch_row($IL); $bmk_IL_70 = $value[0]; echo ("$bmk_IL_70 <br>"); }// Instanciate Word$word = new COM("word.application") or die("Unable to instantiate Word");echo "$word\n";// specify the MS Word template document $dts_template = "/Inranet/departments/manufacturing/Customer_DataSheet_v2.doc";// open the template document$word->Documents->Open($dts_template);//get the current date MM/DD/YYYY$current_date = date("m/d/Y");echo "$current_date\n";//assign bookmark name to the varalbles $bmk_date = "date";$bmk_device = "device_sn";$bmk_name = "name";$bmk_IL_0 = "IL_0";$bmk_IL_25 = "IL_25";$bmk_IL_70 = "IL_70";//create a new MS Word Range (to enable text substitution)$dateobj = $word->ActiveDocument->Bookmarks($bmk_date);$deviceobj = $word->ActiveDocument->Bookmarks($bmk_device);$ilobj = $word->ActiveDocument->Bookmarks($bmk_IL_0);$date_range = $dateobj->Range;$device_range = $deviceobj->Range;$il_range = $ilobj->Range;//Substitute the bookmark with actual value$date_range->Text = $bmk_date;$device_range->Text = $bmk_device;$il_range->Text = $bmk_IL_0;//$il_range->Text = $bmk_IL_25;//$il_range->Text = $bmk_IL_70;//Save the template as a new document $new_file = "/Intranet/departments/manufacturing/datasheet/'$device'_datasheet.doc";$word->Documents[1]->SaveAs($new_file);//8. free the object$word->Quit();$word->Release();$word = null;?> Quote Link to comment https://forums.phpfreaks.com/topic/5948-create-word-doc-with-php/ Share on other sites More sharing options...
Barand Posted March 28, 2006 Share Posted March 28, 2006 I'm only guessing here but usually array indexes start at 0Does this work?[code]$word->Documents[0]->SaveAs($new_file);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/5948-create-word-doc-with-php/#findComment-21688 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.