Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9292913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:59:47+00:00 2026-06-18T20:59:47+00:00

I have got problem with encoding while I transferring data from MySQL to .XLS

  • 0

I have got problem with encoding while I transferring data from MySQL to .XLS file. Table is in “utf8_czech_ci” and PHP script in UTF-8. I always get characters like “ěščřžýáíé” in bad form like “ěšÄřžýáíé”. There is my script

<?php

mb_http_input("utf-8");
mb_http_output("utf-8");

     $dbhost  = "XXXXXXXXXXX";
     $dbuser  = "XXXXXXXXXXX";
     $dbpass  = "XXXXXXXXXXX";
     $dbname  = "XXXXXXXXXXX";
     $dbtable = $_GET['table'];

function xlsBOF() {
    echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
    return;
}

function xlsEOF() {
    echo pack("ss", 0x0A, 0x00);
    return;
}

function xlsWriteLabel($Row, $Col, $Value ) {
    $L = strlen($Value);
    echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
    echo $Value;
    return;
}

$dbc = mysql_connect( $dbhost , $dbuser , $dbpass ) or die( mysql_error() );
mysql_query("set names utf8;");
mysql_select_db( $dbname );
$q = "SELECT * FROM ".$dbtable."";
$qr = mysql_query( $q ) or die( mysql_error() );

header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");
header("Content-type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment;filename=export_".$dbtable.".xls ");
header("Content-Transfer-Encoding: binary ");
xlsBOF();

$col = 0;
$row = 0;
$first = true;

while( $qrow = mysql_fetch_assoc( $qr ) )
{
    if( $first )
    {
        foreach( $qrow as $k => $v )
        {
            xlsWriteLabel( $row, $col, strtoupper( ereg_replace( "_" , " " , $k ) ) );
            $col++;
        }
        $col = 0;
        $row++;
        $first = false;
    }
    foreach( $qrow as $k => $v )
    {
        xlsWriteLabel( $row, $col, $v );
        $col++;
    }

    $col = 0;
    $row++;
}

xlsEOF();
exit();

Thanks for responses …

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T20:59:48+00:00Added an answer on June 18, 2026 at 8:59 pm

    An Excel file uses a codepage block to identify the character set being used within the file, but by default it will use the locale codepage. If you want to force UTF-8, then you’ll need to write a UTF-8 codepage block as well

    $record          = 0x0042;   // Record identifier
    $length          = 0x0002;   // Number of bytes to follow
    $cv              = 0x04B0;   // The UTF-8 code page
    
    $header          = pack('vv', $record, $length);
    $data            = pack('v',  $cv);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have got a problem to get back a parameter from my view to
The problem is: I have got a table of columns (A, B, C) where
have a nice day. I got problem when trying to create an image from
I have some problem while trying to use the schemagen tool from JAXB library
I have problem with encoding data in Oracle database. I want to xor string
I have problem with this code string.Join(,, Encoding.Unicode.GetBytes(10.10.10.11).Select(x => x.ToString(X2))); i got error cannot
I'm using BackboneJS, I have a got a collection which gets its data from
I have strange problem and minimal knowledge on VB6, I got an EXE file
I have got a problem with calling a global function, which takes a pointer
I have got a strange problem about in_array recently which I cannot understand. e.g.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.