4 Replies - 8039 Views - Last Post: 16 August 2010 - 06:39 AM Rate Topic: -----

#1 savanpaun  Icon User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 11
  • Joined: 11-February 10

PHP File convert word to txt

Posted 19 July 2010 - 05:05 AM

Dear Sir
I want to convert a word file to txt file my code is here.
Please help me

$filename="http://localhost/doctxt/assd.doc";
$TXTfilename = $filename . ".txt";
$word = new COM("word.application") or die("Unable to instantiate Word object");
$word->Documents->Open($filename);
// the '2' parameter specifies saving in txt format
$word->Documents[1]->SaveAs($TXTfilename ,2);
$word->Documents[1]->Close(false);
$word->Quit();
$word->Release();
$word = NULL;
unset($word);
$content = file_get_contents($TXTfilename);
unlink($TXTfilename);


i received following arror :
Fatal error: Call to undefined method variant::SaveAs() in C:\wamp\www\doctxt\index.php on line 8

Is This A Good Question/Topic? 0
  • +

Replies To: PHP File convert word to txt

#2 savanpaun  Icon User is offline

  • New D.I.C Head

Reputation: -7
  • View blog
  • Posts: 11
  • Joined: 11-February 10

Re: PHP File convert word to txt

Posted 19 July 2010 - 05:05 AM

Dear Sir
I want to convert a word file to txt file my code is here.
Please help me

$filename="http://localhost/doctxt/assd.doc";
$TXTfilename = $filename . ".txt";
$word = new COM("word.application") or die("Unable to instantiate Word object");
$word->Documents->Open($filename);
// the '2' parameter specifies saving in txt format
$word->Documents[1]->SaveAs($TXTfilename ,2);
$word->Documents[1]->Close(false);
$word->Quit();
$word->Release();
$word = NULL;
unset($word);
$content = file_get_contents($TXTfilename);
unlink($TXTfilename);


i received following arror :
Fatal error: Call to undefined method variant::SaveAs() in C:\wamp\www\doctxt\index.php on line 8
Was This Post Helpful? -1
  • +
  • -

#3 KingCuddles  Icon User is offline

  • D.I.C Regular

Reputation: 176
  • View blog
  • Posts: 496
  • Joined: 20-December 08

Re: PHP File convert word to txt

Posted 19 July 2010 - 05:58 AM

Arrays in general begin with 0.. not 1

Double posting does nothing but annoy people

This post has been edited by KingCuddles: 19 July 2010 - 06:00 AM

Was This Post Helpful? 0
  • +
  • -

#4 Valek  Icon User is offline

  • The Real Skynet
  • member icon

Reputation: 542
  • View blog
  • Posts: 1,713
  • Joined: 08-November 08

Re: PHP File convert word to txt

Posted 19 July 2010 - 06:43 AM

Personally, I try to avoid using COM in PHP because it can get really nasty. Try changing Documents[1] to ActiveDocument and see if that fixes it.
Was This Post Helpful? 1
  • +
  • -

#5 Guest_Vdario*


Reputation:

Re: PHP File convert word to txt

Posted 16 August 2010 - 06:39 AM

Problem SOVLED.

I was not able to understand why the same code was right on windows XP and was bad in Windows 7.

Now I've discovered the reason of the "Fatal error: Call to undefined method variant::SaveAs()" error: the problem resides on the WINWORD's process owner.

Apache (in windows 7) was running on the "SYSTEM" user (check it on the service list) and I had opened the WINWORD only with the user "VDARIO" before (the login user). On the first opening of WINWORD, you must digit your credential, and I didn't it (obviously) with the SYSTEM user.

The solution resides on changing the user of Apache2 on the "connection" tab in the service list, switching it to the login user.

Bye,
Dario

<Email removed>

This post has been edited by macosxnerd101: 16 August 2010 - 06:40 AM
Reason for edit:: Removed email address in compliance with site policies

Was This Post Helpful? 2

Page 1 of 1