Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PEAR/PHP related question

Status
Not open for further replies.

rpg121

Programmer
Mar 14, 2001
89
US
Hi,

I am using the Spreadsheet Excel writer module of PEAR and have it functioning correctly. I have been using it in a PHP/mySQL database project where I pull info and put it into an exported Excel Document. It has been working just fine, but I've realized while running through the query results, I need to check if I have reached the maximum results per page, and then create a new page. For the first little while, I simply had the pasted code to create and format a new worksheet in each spot, but I run this check upwards of 4 dozen times....so I figured I'd write a function to create a new page.

I call ResearchFunction($worksheet,$workbook,$page); from my main code and it refers to ResearchFunction that is stored in a seperate PHP file that I included from the beginning.

My ResearchFunction looks as follows:
ResearchFunction($worksheet,$workbook,$page) {

-- declaration of all formatting variables such as $background_white2, etc --
$worksheet =& $workbook->addWorksheet("Research (".$page.")");
$worksheet->setMargins(0.75);
$worksheet->centerHorizontally();
$worksheet->printArea(2,1,40,9);
$worksheet->setLandscape();

// Formatting for Research Worksheet
$worksheet->setColumn(0,1,2.14, $background_white2);
$worksheet->setColumn(2,2,11.14, $background_white2);
$worksheet->setColumn(3,3,0.67, $background_white2);
$worksheet->setColumn(4,4,13.14, $background_white2);
$worksheet->setColumn(5,5,16.14, $background_white2);
$worksheet->setColumn(6,6,36.57, $background_white2);
$worksheet->setColumn(7,7,14.29, $background_white2);
$worksheet->setColumn(8,8,12.86, $background_white2);
$worksheet->setColumn(9,10,2.14, $background_white2);
$worksheet->setColumn(11,100,8.43, $background_white2);

// Research Worksheet Titles
$worksheet->write(2,2, "Annual Report", $format_AnnRptHeader2);
$worksheet->writeBlank(2,3, $border_toponly2);
$worksheet->writeBlank(2,4, $border_toponly2);
$worksheet->writeBlank(2,5, $border_toponly2);
$worksheet->write(3,2, "The University of Western Ontario", $format_Arial122);
$worksheet->writeBlank(3,3, $border_bottomonly2);
$worksheet->writeBlank(3,4, $border_bottomonly2);
$worksheet->writeBlank(3,5, $border_bottomonly2);
$worksheet->write(3,7, "Research Information (".$page.")", $format_Arial12Bold2);
$worksheet->mergeCells(3,7,3,9);
$worksheet->writeBlank(3,8, $format_Arial12Bold2);
$worksheet->writeBlank(3,9, $format_Arial12Bold2);

$row = mysql_fetch_array(mysql_query("SELECT * FROM geninfo WHERE fid = '$fid'"));
$faid=$row['faid'];
$row1 = mysql_fetch_array(mysql_query("SELECT facultyname FROM faculties WHERE faid='$faid'"));
$deid=$row['deid'];
$row2 = mysql_fetch_array(mysql_query("SELECT departmentname FROM departments WHERE deid='$deid'"));

// Writes data to subheaders
$worksheet->write(6,2, "Name:", $format_Arial10Bold2);
$worksheet->write(6,3, $row['lname'].", ".$row['fname'].", ".$row['mname'], $format_Arial102);
$worksheet->write(7,2, "Faculty ID:", $format_Arial10Bold2);
$facultyIDNo = "-".$row['textfid']."-";
$worksheet->write(7,3, $facultyIDNo, $format_Arial102);
$worksheet->write(8,2, "Faculty:", $format_Arial10Bold2);
$worksheet->write(8,3, $row1['facultyname'], $format_Arial102);
$worksheet->write(9,2, "Department: ", $format_Arial10Bold2);
$worksheet->write(9,3, $row2['departmentname'], $format_Arial102);

// Research Worksheet Borders
$worksheet->writeBlank(2,1, $border_topandleft2);
$worksheet->writeBlank(2,6, $border_toponly2);
$worksheet->writeBlank(2,7, $border_toponly2);
$worksheet->writeBlank(2,8, $border_toponly2);
$worksheet->writeBlank(2,9, $border_topandright2);
$worksheet->writeBlank(3,6, $border_bottomonly2);
$worksheet->writeBlank(3,1, $border_leftandbottom2);
for($i = 4; $i < 40; $i++) {
$worksheet->writeBlank($i,1, $border_leftonly2);
$worksheet->writeBlank($i,9, $border_rightonly2);
}
$worksheet->writeBlank(40,1, $border_leftandbottom2);
$worksheet->writeBlank(40,9, $border_rightandbottom2);
for($i = 2; $i < 9; $i++) {
$worksheet->writeBlank(40,$i, $border_bottomonly2);
}

}

Basically, exportation fails if I don't include this code in the included PHP file, but if i DO include it, it doesnt fail, but never runs the code.

Any information anyone might have on why this is failing would be greately appreciated :)

Josh Bart
MCP, A+, Network+
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top