PEAR Packages
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPEAR Packages

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old February 4th, 2009, 11:45 AM
cyanstudios cyanstudios is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 3 cyanstudios User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 55 m
Reputation Power: 0
Issue with arrays and Spreadsheets in PEAR

Hello,
I have an XDP (XML) form that I'm dumping values from into a PHP file that interprets these values and places them in a spreadsheet using PHP PEAR's Spreadsheet Excel Writer.

A-U are a lot of values that will be calculated into three different sums between Y-ZZ. Ysum-ZZsum are the sums of all Y-ZZ values. It's a lot like an excel sheet.

So when the values are dropped into the php script, this is what it looks like:

PHP Code:
 $_FIELD=array( 
"foreman" => $_POST{'foreman'}, 
"employee" => $_POST{'employee'}, 
"curdate" => $_POST{'mon'},
"A" => $_POST{'A'},
"B" => $_POST{'B'},
"C" => $_POST{'C'},
"D" => $_POST{'D'},
"E" => $_POST{'E'},
"F" => $_POST{'F'},
"G" => $_POST{'G'},
"H" => $_POST{'H'},
"I" => $_POST{'I'},
"J" => $_POST{'J'},
"K" => $_POST{'K'},
"L" => $_POST{'L'},
"M" => $_POST{'M'},
"N" => $_POST{'N'},
"O" => $_POST{'O'},
"P" => $_POST{'P'},
"Q" => $_POST{'Q'},
"R" => $_POST{'R'},
"S" => $_POST{'S'},
"T" => $_POST{'T'},
"U" => $_POST{'U'},
"jobpick" => $_POST{'jobpick'},
"phasepick" => $_POST{'phasepick'},
"costpick" => $_POST{'costpick'},
"Y" => $_POST{'Y'},
"Z" => $_POST{'Z'},
"ZZ" => $_POST{'ZZ'},
"Ysum" => $_POST{'Ysum'},
"Zsum" => $_POST{'Zsum'},
"ZZsum" => $_POST{'ZZsum'},
); 


$foreman $_POST['foreman']; 
$employee $_POST['employee']; 
$curdate $_POST['mon'];
$A $_POST['A'];
$B $_POST['B'];
$C $_POST['C'];
$D $_POST['D'];
$E $_POST['E'];
$F $_POST['F'];
$G $_POST['G'];
$H $_POST['H'];
$I $_POST['I'];
$J $_POST['J'];
$K $_POST['K'];
$L $_POST['L'];
$M $_POST['M'];
$N $_POST['N'];
$O $_POST['O'];
$P $_POST['P'];
$Q $_POST['Q'];
$R $_POST['R'];
$S $_POST['S'];
$T $_POST['T'];
$U $_POST['U'];
$jobpick $_POST['jobpick'];
$phasepick $_POST['phasepick'];
$costpick $_POST['costpick'];
$Y $_POST['Y'];
$Z $_POST['Z'];
$ZZ $_POST['ZZ'];
$Ysum $_POST['Ysum'];
$Zsum $_POST['Zsum'];
$ZZsum $_POST['ZZsum'];


$filestring $foreman "-" $curdate ".dif";
$filestring str_replace' '''$filestring ); 
$filestring str_replace','''$filestring ); 
$co "1";
$glacct "503";
$daycode "";
$rate "30";
$amount "1200";
$type "0";
$union "777";
$craft "ELEC";
$state "15";
$local "151100";
$wc "1560"


As you can see, the last dozen or so are concrete values, not true arrays, just variables.
The rest are arrays that dump multiple values depending on how many rows are inserted into this form.

Now, in order to structure it into the excel file (.dif in this case), this is the code I'm using.

PHP Code:
require_once 'Spreadsheet/Excel/Writer.php';

$workbook = new Spreadsheet_Excel_Writer("$filestring");

$worksheet =& $workbook->addWorksheet($employee);
// The first row of the spreadsheet has hard values, no variability.
$worksheet->write(00'CO'); //write(row, column, 'value')
$worksheet->write(01'EMP');
$worksheet->write(02'JOB');
$worksheet->write(03'PHASE');
$worksheet->write(04'COST');
$worksheet->write(05'GL-ACCT');
$worksheet->write(06'DAYCODE');
$worksheet->write(07'HOURS');
$worksheet->write(08'RATE');
$worksheet->write(09'AMOUNT');
$worksheet->write(010'TYPE');
$worksheet->write(011'UNION');
$worksheet->write(012'CRAFT');
$worksheet->write(013'STATE');
$worksheet->write(014'LOCAL');
$worksheet->write(015'WC');
$worksheet->write(016'DAY1');
$worksheet->write(017'DAY2');
$worksheet->write(018'DAY3');
$worksheet->write(019'DAY4');
$worksheet->write(020'DAY5');
$worksheet->write(021'DAY6');
$worksheet->write(022'DAY7');

$int=1//This is to generate new rows per loop
while ($Y != "")
{
$worksheet->write($int0$county);
$worksheet->write($int1$employee);
$worksheet->write($int2$jobpick);
$worksheet->write($int3$phasepick);
$worksheet->write($int4$costpick);
$worksheet->write($int5$glacct);
$worksheet->write($int6$daycode);
$worksheet->write($int7$Y);
$worksheet->write($int8$rate);
$worksheet->write($int9$amount);
$worksheet->write($int10$type);
$worksheet->write($int11$union);
$worksheet->write($int12$craft);
$worksheet->write($int13$state);
$worksheet->write($int14$local);
$worksheet->write($int15$wc);
$worksheet->write($int16$A);
$worksheet->write($int17$D);
$worksheet->write($int18$G);
$worksheet->write($int19$J);
$worksheet->write($int20$M);
$worksheet->write($int21$P);
$worksheet->write($int22$S);
$int++;
}
$workbook->close(); 

Doing this was creating, what I assume to be, an infinite loop. I've tried replacing the while with an if and it worked, but only ended up putting the last returned values in second (1) row. It didn't increment up nor make any other rows.
I've tried using the following variables in tons of different ways to make this work
PHP Code:
 $county count($Y); //I'm thinking this will tell it when to stop looping if that's necessary.
$ind=0//used to indicate which value of $Y etc. to use per calculation, not to be confused with $int which has to start at one because of the hard values in row 1. 


I hope this post wasn't too lengthy. There's some structuring I just haven't nailed correctly and I'm looking for some insights. I think I have all the tools here, they're just not being arranged right.

Thank you.

Reply With Quote
  #2  
Old February 4th, 2009, 11:48 AM
cyanstudios cyanstudios is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Feb 2009
Posts: 3 cyanstudios User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 55 m
Reputation Power: 0
I tried this now
PHP Code:
 $county count($Y);
$int=1;
do
{
$worksheet->write($int0$county);
$worksheet->write($int1$employee);
$worksheet->write($int2$jobpick);
$worksheet->write($int3$phasepick);
$worksheet->write($int4$costpick);
$worksheet->write($int5$glacct);
$worksheet->write($int6$daycode);
$worksheet->write($int7$Y);
$worksheet->write($int8$rate);
$worksheet->write($int9$amount);
$worksheet->write($int10$type);
$worksheet->write($int11$union);
$worksheet->write($int12$craft);
$worksheet->write($int13$state);
$worksheet->write($int14$local);
$worksheet->write($int15$wc);
$worksheet->write($int16$A);
$worksheet->write($int17$D);
$worksheet->write($int18$G);
$worksheet->write($int19$J);
$worksheet->write($int20$M);
$worksheet->write($int21$P);
$worksheet->write($int22$S);
$int++;
}
while (
$int <= $county); 


And I'm still getting the last values per array in just one row on the spreadsheet.

You can see that I'm putting $county in the first cell for testing purposes. It's returning a value of "1" even two Y values are being submitted, so for this method to work, I would also need to figure why $county is working this way.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPEAR Packages > Issue with arrays and Spreadsheets in PEAR


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 9 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek