Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 PHP Code: Output as Word Doc format Jump to:  
Category: >> PHP Code >> Output as Word Doc format Bookmark and Share

<< lastnext >>

Snippet Name: Output as Word Doc format

Description: Pull data from a DB and output it in MS Word (.DOC) format.

Comment: (none)

Language: PHP
Highlight Mode: PHP
Last Modified: February 27th, 2009

<?PHP
 
$query = "SELECT * FROM TABLE  WHERE data = '$data'";
 
    $result = MYSQL_QUERY($query);
    $count = MYSQL_NUM_FIELDS($result); 
 
    FOR ($i = 0; $i < $count; $i++){ 
        IF (ISSET($header)) 
            $header .= MYSQL_FIELD_NAME($result, $i)."\t"; 
            ELSE 
                $header = MYSQL_FIELD_NAME($result, $i)."\t"; 
        } 
 
    WHILE ($row = MYSQL_FETCH_ROW($result)){ 
        $line = ''; 
 
        FOREACH ($row AS $value) 
            { 
            IF (!ISSET($value) || $value == '') 
                $value = "\t"; 
                ELSE 
                    { 
                    $value = STR_REPLACE('"', '""', $value); 
                    $value = '"'.$value.'"'."\t"; 
                    } 
 
            $line .= $value; 
            } 
 
        IF (ISSET($data)) 
            $data .= TRIM($line)."\n"; 
            ELSE 
                $data = TRIM($line)."\n"; 
        } 
 
    $data = STR_REPLACE("\r", "", $data); 
 
    IF ($data == '') 
        $data = "\nno matching records\n"; 
 
    HEADER("Content-Type: application/vnd.ms-word; name='word'"); 
    HEADER("Content-type: application/octet-stream"); 
    HEADER("Content-Disposition: attachment; filename=filename_here.doc"); 
    HEADER("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
    HEADER("Pragma: no-cache"); 
    HEADER("Expires: 0"); 
 
    ECHO $header."\n".$data; 
    EXIT;
 
?> 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 280 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?