Go Back   PHP-Editors > Programming Help > PHP Programming Help

PHP Programming Help Post any question relating to PHP Programming here and hopefully someone can help.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 2008-01-09, 11:32 AM
Member
 
Join Date: Oct 2005
Posts: 30
OldManRiver
Default Excel Processing

All,

Looking for help with reading/processing/writing Excel in PHP.

Have post on this at:

Excel Processing - Codewalkers

All help appreciated!

Thanks!

OMR
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 2008-01-23, 04:44 PM
Member
 
Join Date: Oct 2005
Posts: 30
OldManRiver
Default What I need

All,

What I need here, on a conceptual basis, code wise is:
Code:
function read_xcel($myfile,$mysheet) {
   $objReader = new PHPxl_Reader;
   $objPHPxl = $objReader->load($myfile);
   $objSheets = $objReader->getActiveSheets();
   $objActiveS = $objReader->setActiveSheet($objSheets);
   $objRange = $objReader->SheetRange($objActiveS);
   foreach ($objRange as $cell) {
      $cellval = array($cell,$objReader->Cell->Value);
   }
   print_r($cellval);
}
Which should give me an array I can parse into MySQL then once I massage all in MySQL I then need something like this:
Code:
function write_xcel($myfile,$mysheet) {
   $objWriter = new PHPxl_Writer;
   $objPHPxl = $objWriter->load($myfile);
   $objActiveS = $objWriter->setActiveSheet($mysheet);
   $sql_str = "SELECT * FROM mydbtable WHERE datatype='data';";
   $result = mysql_query($sql_str);
   while ($row = mysql_fetch_assoc($result)) {
       $rwcl = $row['row_col'];
       $rcdt = $row['datasource'];
       $res = $objWriter->SetCell($rwcl,$rcdt);
   }
   $objWriter->Close;
}
If I can get an example that works like these two hypothetical functions then I can make it all work.

Thanks!

OMR
Reply With Quote
  #3 (permalink)  
Old 2008-01-31, 10:15 AM
Member
 
Join Date: Oct 2005
Posts: 30
OldManRiver
Default Almost There

All,

Maybe you didn't notice, but this project turned out to be much larger than I thought.

Anyway I finally got all the reading done and now working on writing the second file.

I had to break up the output into two (2) MySql tables as 1.) one table deals with header and footer information, for both input and output EXCEL files and 2.) the second table deals with itemized rows.

In particular this is a problem as you notice the output EXCEL file only has ten (10) rows to write into, and the input EXCEL file has 300 rows of data. Now selection (query) of data from the first input file is on the "QTY" column, which we ignore if blank, so usually less than 10 rows are active. But when more than 10 row result from the query, then new rows have to be inserted into the output EXCEL file, conserving the formatting from the row above and then renumbering column one, for all remaining detail item rows.

I'm uploading the source for where I'm at. I used:
  • [li]TBS to open/view the source file, [/li]
    [li]Excel Reader to read my values[/li]
but now have to find a different class to write with.

If you have a single class that can do it all, it would be helpful and jumping in here to help will be appreciated.

All files at:

Excel Processing - Dev Shed

Thanks!

OMR
Reply With Quote
  #4 (permalink)  
Old 2008-03-13, 12:30 AM
Member
 
Join Date: Oct 2005
Posts: 30
OldManRiver
Default RoadBlock

All,

Hey I got all it working but the write to the new SS.

On the subject of write, when I look at all the docs on the Excel Writer Classes, everyone assumes new file, new workbook, new worksheet.

Nothing could be further from my situation! I have a .XLT template with a specific "NAMED" worksheet that must be written to.

Therefore none of the docs fit my problem and I have not yet figured out how to find my worksheet in the writer. Finding worksheets seems to be a "READER" function not a "WRITER" function, so I seem to be at an impasse right now!

Suggestions on how to approach or solve this portion would help me get around my current road block.

All help greatly appreciated!!!

Thanks!!!

OMR
Reply With Quote
  #5 (permalink)  
Old 2008-03-14, 03:26 AM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,165
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

Since I always work in the *nix world, there is no native way (i.e. COM) to read Excel files, since they dont exist on that OS, as they are MS only.

However, what we end up doing is writing out just HTML, tossing the header() of Excel files, and it works wonderfully. Excel reads it just like a big table. Use normal HTML tables, and any inline elements you want. It doesnt understand CSS that much, but you can play with it a little, just keep it inline instead of using classes or ids.
__________________
My company's website: XM Tek
My Homepage/Blog
Reply With Quote
  #6 (permalink)  
Old 2008-03-17, 06:54 PM
Member
 
Join Date: Oct 2005
Posts: 30
OldManRiver
Default

Quote:
Originally Posted by Xnuiem View Post
Since I always work in the *nix world, there is no native way (i.e. COM) to read Excel files, since they dont exist on that OS, as they are MS only.

However, what we end up doing is writing out just HTML, tossing the header() of Excel files, and it works wonderfully. Excel reads it just like a big table. Use normal HTML tables, and any inline elements you want. It doesnt understand CSS that much, but you can play with it a little, just keep it inline instead of using classes or ids.
X,

Appreciate the input and I already can read the Excel, now I'm writing back to pre-defined .XLT template file.

Do you know any source that might help me there?

OMR
Reply With Quote
  #7 (permalink)  
Old 2008-03-18, 12:12 AM
Xnuiem's Avatar
Senior Member
 
Join Date: May 2004
Location: DFW, Texas
Posts: 1,165
Xnuiem will become famous soon enough
Send a message via Yahoo to Xnuiem
Default

I hate to admit it, but I am at a total loss. I have never even tried that before.

I forwarded an email with this thread to a couple of friends that may know, hopefully they will either reply to me or directly to this thread.

Other than that, hope you figure it out. Please post back either way, I would love to know.
__________________
My company's website: XM Tek
My Homepage/Blog
Reply With Quote
  #8 (permalink)  
Old 2008-03-21, 12:38 PM
Member
 
Join Date: Oct 2005
Posts: 30
OldManRiver
Default Work Around

Quote:
Originally Posted by Xnuiem View Post
I hate to admit it, but I am at a total loss. I have never even tried that before.

I forwarded an email with this thread to a couple of friends that may know, hopefully they will either reply to me or directly to this thread.

Other than that, hope you figure it out. Please post back either way, I would love to know.
X,

Harish at:

Class: Excel Writer (excel, xls, excel writer, excelwriter) - PHP Classes

suggested I use the PEAR class, get it working and then extract the class code to my other class libs when it works.

What do you think?

OMR
Reply With Quote
Must read Review for Serious PHP Developers


NuSphere PhpED 5.5 : The Staff of php-editors.com recently spent a few days working with NuSphere PhpED 5.5 (a popular PHP IDE) and NuCoder 2.0 (a PHP Encoding Utility), read up on all the details.

Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 08:28 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.1.0
© Copyright 2003-2008 www.php-editors.com. The ultimate PHP Editor and PHP IDE site.