Jump to content

Create table in MS WORD using PHP


plodos

Recommended Posts

<?
$link = mysql_connect($dbhost,$dbuser,$dbpass) or die ('Could not connect: ' . mysql_error());
mysql_select_db($dbname) or die ('Error connecting to database');
$sql = "SELECT * FROM papers WHERE ctitle='May 2012'";
$result = mysql_query($sql);
$num = mysql_num_rows($result); //number of entry
$data = mysql_query("select * from papers where ctitle='May 2012' ORDER BY id ASC"); 

$Wrd = new COM("Word.Application");
$Wrd->Application->Visible = False;
$DocName = "MyDoc/MyWord.doc";

$WrdDoc = $Wrd->Documents->Add();
$WTable = $WrdDoc->Tables->Add($Wrd->Selection->Range, 2, $num); // Colums, Rows

while($info=mysql_fetch_array($data))
{ $i=1;
$WTable->Cell($i,1)->Range->Text = $info['title'];
$WTable->Cell($i,2)->Range->Text = $info['name'] $info['surname'] $info['institution'] $info['country'];
$i++;
        }
$Wrd->ActiveDocument->SaveAs(realpath($DocName));
$Wrd->Application->Quit;
$Wrd = null;
?>
Word Created <a href="<?=$DocName?>">Click here</a> to Download.

 

php script is not working. Can someone please help me to detect the errors?

 

i want create a table in ms word file for all entry in my database... "2 columns, number of rows"

 

Cell(1,1)  Cell(1,2)

Cell(2,1)  Cell(2,2)

etc...

Cell(3,1)  Cell(3,2)

Link to comment
https://forums.phpfreaks.com/topic/258810-create-table-in-ms-word-using-php/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.