Jump to content

Recommended Posts

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 advance
Nirvana

<?php
//This program is to generate datasheet

//Connect to Server and Database
include ("Connection.php");
//Get device number
$device = 2886;

//Minimum Insertion Loss Query
print "$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;

?>
Link to comment
https://forums.phpfreaks.com/topic/5948-create-word-doc-with-php/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.