0

I've been using the code below to successfully create spreadsheets for a few years. Now I have the need to insert page breaks at random times. I haven't found any code that does that without having to abandon this code and installing something completely different which I'd rather not do. This code is very simple and effective. Anyone know how? If it's easier creating a new worksheet that would be fine. Thanks in advance.

for ($y = 0; $y <= $totline; $y++) {

    $value = trim($fnames[$y]);

    if ((!isset($value)) OR ($value == "")) 
        {$value = "\t";}
    else 
        {$value = str_replace('"', '""', $value); 
        $value = '"' . $value . '"' . "\t";}

    $line .= $value;
}

$header = trim($line);

$line = " ";

for ($x = 1; $x <= $totrows; $x++) { 

    $rowarr = $arrin[$x];

    $result = strpos($rowarr[0], "-");

    if ($showroom == "yes" or $result === false) {

        for ($y = 0; $y <= $totline; $y++) {

            $value = trim($rowarr[$y]);

            if ((!isset($value)) OR ($value == "")) 
                {$value = "\t";}
            else 
                {$value = str_replace('"', '""', $value); 
                $value = '"' . $value . '"' . "\t";}

            $line .= $value; 
        }

    $data .= trim($line)."\n";
    $line = " ";
    }
}

if ($data == "") { 
    $data = "\n(0) Records Found!\n";                         
} 
$filename = "payroll_" . date('Ymd') . ".xls";

header("Content-type: application/x-msdownload"); 
header("Content-Disposition: attachment; filename=\"$filename\""); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
print "$header\n$data";
print "$header\n$data";   
?>

Edited by Reverend Jim: Fixed formatting

2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by mongo23
0

I added the '\r\n' and now I get a blank line inserted on a break but not a new page. Here is the latest code:

for ($x = 1; $x <= $totrows; $x++) { 

    $rowarr = $arrin[$x];

    if (!$savedept) {
        $savedept = $rowarr[0];}

    if ($savedept <> $rowarr[0]) {
        $data .= "\r\n";           [B][COLOR="red"] //Want a page break here[/COLOR][/B]
        $savedept = $rowarr[0];}

    for ($y = 0; $y <= $totline; $y++) {

        $value = trim($rowarr[$y]);

        if ((!isset($value)) OR ($value == "")) 
            {$value = "\t";}
        else 
            {$value = str_replace('"', '""', $value); 
            $value = '"' . $value . '"' . "\t";}

        $line .= $value; 
        }

    $data .= trim($line)."\n";
    $line = " ";
}

Edited by mike_2000_17: Fixed formatting

0

I really don't think there is a character you can put in there that would force it to create a new worksheet or page. Basically you're just sending a tab delimited file with an Excel header. If you're going to get fancier, I think your only option is to use PEAR or something like PHPExcel. Either way, I think it's time to update. :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.