By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,048 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

PHP COM and Excel

P: n/a
Sol
I have to work with an excel file, read only on my machine. I set up
the COM class, and it is working all right, but I hit a wall now.

I need to search for a given string in the worksheet, using the Find
command in VBA, but I can't seem to make it work on php. Below you can
find a snip of the code:

$objExcel = new COM("excel.application") or die("Falha ao inicializar
o excel");
$objExcel->Workbooks->Open("$arquivo") or die("Não foi possível abrir
o arquivo");
$worksheet = $objExcel->Worksheets($i);
$worksheet->Cells(8, 2)->Find("What:=\"Observações\",
After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart,
SearchOrder:=xlByRows, SearchDirection:=xlNext MatchCase:=False,
SearchFormat:=False") or die("Not Again");

Anyone got any idea how to make it work?
Sep 25 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a

"Sol" <sa********@gmail.comwrote in message
news:d5**********************************@k13g2000 hse.googlegroups.com...
I have to work with an excel file, read only on my machine. I set up
the COM class, and it is working all right, but I hit a wall now.

I need to search for a given string in the worksheet, using the Find
command in VBA, but I can't seem to make it work on php. Below you can
find a snip of the code:

$objExcel = new COM("excel.application") or die("Falha ao inicializar
o excel");
$objExcel->Workbooks->Open("$arquivo") or die("Não foi possível abrir
o arquivo");
$worksheet = $objExcel->Worksheets($i);
$worksheet->Cells(8, 2)->Find("What:=\"Observações\",
After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart,
SearchOrder:=xlByRows, SearchDirection:=xlNext MatchCase:=False,
SearchFormat:=False") or die("Not Again");

Anyone got any idea how to make it work?
=================

Hi,
what exactly does "make it work" mean?
What is not working? Error messages?

Richard
Sep 25 '08 #2

P: n/a
Sol <sa********@gmail.comwrote:
>I have to work with an excel file, read only on my machine. I set up
the COM class, and it is working all right, but I hit a wall now.

I need to search for a given string in the worksheet, using the Find
command in VBA, but I can't seem to make it work on php. Below you can
find a snip of the code:

$objExcel = new COM("excel.application") or die("Falha ao inicializar
o excel");
$objExcel->Workbooks->Open("$arquivo") or die("Não foi possível abrir
o arquivo");
$worksheet = $objExcel->Worksheets($i);
$worksheet->Cells(8, 2)->Find("What:=\"Observações\",
After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart,
SearchOrder:=xlByRows, SearchDirection:=xlNext MatchCase:=False,
SearchFormat:=False")
You didn't really expect to pass parameters that way, did you? The :=
syntax is part of the Visual Basic language. It's not something that Excel
understands natively.

PHP doesn't support named parameters. You'll have to do this positionally.

define('xlFormulas', -4123 );
define('xlNext', 1 );
define('xlPart', 2 );
define('xlByRows', 1 );
$worksheet->Cells(8,2)->Find( "Observações",
$worksheet->ActiveCell(), xlFormulas, xlPart, xlByRows );
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Sep 27 '08 #3

P: n/a
Sol
On 27 set, 02:41, Tim Roberts <t...@probo.comwrote:
Sol<samuel....@gmail.comwrote:
I have to work with anexcelfile, read only on my machine. I set up
the COM class, and it is working all right, but I hit a wall now.
I need to search for a given string in the worksheet, using the Find
command in VBA, but I can't seem to make it work onphp. Below you can
find a snip of the code:
$objExcel = new COM("excel.application") or die("Falha ao inicializar
oexcel");
$objExcel->Workbooks->Open("$arquivo") or die("Não foi possível abrir
o arquivo");
$worksheet = $objExcel->Worksheets($i);
$worksheet->Cells(8, 2)->Find("What:=\"Observações\",
After:=ActiveCell, LookIn:=xlFormulas, LookAt:=xlPart,
SearchOrder:=xlByRows, SearchDirection:=xlNext MatchCase:=False,
SearchFormat:=False")

You didn't really expect to pass parameters that way, did you? *The :=
syntax is part of the Visual Basic language. *It's not something thatExcel
understands natively.

PHPdoesn't support named parameters. *You'll have to do this positionally.

* define('xlFormulas', -4123 );
* define('xlNext', 1 );
* define('xlPart', 2 );
* define('xlByRows', 1 );
* $worksheet->Cells(8,2)->Find( "Observações",
* * $worksheet->ActiveCell(), xlFormulas, xlPart, xlByRows );
--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
Since I didn't know how exactly the COM extension worked, I was not
sure how it was. Thanks for the reply I will try that and get back to
you.

Just one question, why exactly this line? define('xlFormulas',
-4123 );
Sep 30 '08 #4

P: n/a
Sol <sa********@gmail.comwrote:
>
Since I didn't know how exactly the COM extension worked, I was not
sure how it was. Thanks for the reply I will try that and get back to
you.

Just one question, why exactly this line?
define('xlFormulas', -4123 );
The PHP online manual would be quicker than this newsgroup. That creates a
PHP constant. After that runs, you can write:
$i = xlFormulas;
instead of this:
$i = -4123;
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Oct 2 '08 #5

P: n/a
Sol
On Oct 2, 1:04*am, Tim Roberts <t...@probo.comwrote:
Sol <samuel....@gmail.comwrote:
Since I didn't know how exactly the COM extension worked, I was not
sure how it was. Thanks for the reply I will try that and get back to
you.
Just one question, why exactly this line?
* define('xlFormulas', -4123 );

The PHP online manual would be quicker than this newsgroup. *That creates a
PHP constant. *After that runs, you can write:
* * $i = xlFormulas;
instead of this:
* * $i = -4123;
--
Tim Roberts, t...@probo.com
Providenza & Boekelheide, Inc.
I know what defines does, my question was why define xlFormulas as
-4123 that's what I didn't get.
Oct 2 '08 #6

P: n/a
Sol <sa********@gmail.comwrote:
>>
>Just one question, why exactly this line?
* define('xlFormulas', -4123 );

The PHP online manual would be quicker than this newsgroup. *That creates a
PHP constant. *After that runs, you can write:
* * $i = xlFormulas;
instead of this:
* * $i = -4123;

I know what defines does, my question was why define xlFormulas as
-4123 that's what I didn't get.
Ah, my apologies. That happens to be the value of the "xlFormulas"
constant from Excel. You can find these values using Google, although I
got them using Python, just because I'm more comfortable there:

Python 2.4.4 (#71, Oct 18 2006, 08:34:43) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>import win32com.client
xl = win32com.client.Dispatch('Excel.Application')
win32com.client.constants.xlFormula
-4123
>>win32com.client.constants.xlPart
2
>>>
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Oct 5 '08 #7

P: n/a
xlFormulas, xlValues, or xlComments

Those constants are used to tell what you want to find. Each cell
can have a formula, a value and a comment. So to distinguish the
different types of information to search through, you have those
constants.

For instance, if you'd like to search for something inside a cell,
perhaps the output of a formula, rather than the formula itself,
you'd use the xlValues constant.

If you'd like to search through the formulas and find a particular
variable, you'd use the xlFormulas constant to identify where to
search.

And because each cell can have a comment, you can search through
comments, rather than the values or the formulas.

Hope this helps and good luck. It seems limited to perhaps the MS
Excel Find function.

http://msdn.microsoft.com/en-us/libr...ffice.10).aspx

--
Jim Carlock
You Have More Than Five Senses
http://www.associatedcontent.com/art...ve_senses.html

Oct 6 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.