473,382 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

PHP COM and Excel

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

"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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
3
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet...
6
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C#...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
22
by: Howard Kaikow | last post by:
There's a significant problem in automating Excel from VB .NET. Reminds me of a problem I encountered almost 3 years ago that was caused by the Norton Auntie Virus Office plug-in. Can anybody...
9
by: Anthony | last post by:
To me, creating Excel 2003 spreadsheets programmatically via VB.NET hasn't really changed since the days of VB6. That is, I'd do something similar to this Code: Dim ExcelApp As...
7
by: Alain \Mbuna\ | last post by:
Hi everybody. In my program I have some data that is calculated after some input from the user. I have written some code that opens an Excel workbook, with 5 worksheets and the calculated data...
16
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.