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