Dear Sir,
I have a PHP script that export CSV with arabic text, for example I download the CSV on the website then save to desktop of my computer and Open it on NOTEPAD... that works fine I could still see all the arabic text OK with no problem, but if I open the CSV file in Microsoft EXCEL, all the arabic text are busted and no longer readable.
arabic text is inserted and stored in database as UTF-8 format.
Do you know a solution for this, how could I make it work OK on MS Excel, because the user want it to view the CSV file in Excel and this is so much urgent for me . please reply.
Regards,
Fauk Chowdhury. -
-
<?php
-
// Connect to database
-
mysql_connect("localhost", "root", "root123");
-
mysql_select_db("medgulf");
-
-
$fname = date("d-m-Y");
-
// mention the file name to display in download prompt
-
$file_name = "$fname.csv";
-
-
header("Content-Disposition: attachment; filename=\"$file_name\"");
-
header("Cache-Control: cache, must-revalidate");
-
header("Pragma: public");
-
header('Content-Type: text/xml, charset=UTF-8; encoding=UTF-8');
-
-
$fd1 = $_POST['fd'];
-
$fm1 = $_POST['fm'];
-
$fy1 = $_POST['fy'];
-
// Output header
-
//echo "Name, Code"."\n";
-
$frmday = $fy1."-".$fm1."-".$fd1;
-
$ld1 = $_POST['ld'];
-
$lm1 = $_POST['lm'];
-
$ly1 = $_POST['ly'];
-
-
$today = $ly1."-".$lm1."-".$ld1;
-
//echo $frmday;
-
$usrname = $_POST['usname'];
-
$export_date = date("Y-m-d");
-
-
$result = mysql_query("SELECT product, agent_code, policy_no, DATE_FORMAT(entry_date, '%d/%m/%Y'), DATE_FORMAT(inception_date_eng, '%d/%m/%Y'), DATE_FORMAT(inception_date_hijri, '%d/%m/%Y'), DATE_FORMAT(expiry_date_eng, '%d/%m/%Y'), DATE_FORMAT(expiry_date_hijri, '%d/%m/%Y'), client_info.first_name, client_info.family_name, client_info.father_name, client_info.grand_father_name, client_info.mobile_no, client_info.dob, client_info.p_o_box, client_info.zip_code, client_info.city, client_info.id_type, client_info.id_no, vehicle_type, license_type, net_premium, brandname, model, reg_type, plate_no, model_year, chassis_no, color, user_name, age_limit FROM vehicle_info, client_info where vehicle_info.policy_no = client_info.sr AND entry_date BETWEEN '$frmday' AND '$today' AND user_name='$usrname' AND exported='yes' ");
-
$str = mb_convert_encoding($result, "UTF-8", "ASCII");
-
echo "encode $str";
-
-
if($result) {
-
while($rs = mysql_fetch_array($result))
-
{ echo $rs[0].", ";
-
echo $rs[1].", ";
-
echo $rs[2].", ";
-
echo $rs[3].", ";
-
echo $rs[4].", ";
-
echo $rs[5].", ";
-
echo $rs[6].", ";
-
echo $rs[7].", ";
-
echo $rs[8].", ";
-
echo $rs[9].", ";
-
echo $rs[10].", ";
-
echo $rs[11].", ";
-
echo $rs[12].", ";
-
echo $rs[13].", ";
-
echo $rs[14].", ";
-
echo $rs[15].", ";
-
echo $rs[16].", ";
-
echo $rs[17].", ";
-
echo $rs[18].", ";
-
echo $rs[19].", ";
-
echo $rs[20].", ";
-
echo $rs[21].", ";
-
echo $rs[22].", ";
-
echo $rs[23].", ";
-
echo $rs[24].", ";
-
echo " ".", ";
-
echo $rs[25].", ";
-
echo $rs[26].", ";
-
echo $rs[27].", ";
-
echo $rs[28].", ";
-
echo " ".", ";
-
echo " ".", ";
-
echo $rs[29].", ";
-
echo $rs[30].", ";
-
}
-
-
$result4 = mysql_query("UPDATE vehicle_info SET exported ='yes', exported_date='$export_date' WHERE user_name ='$usrname'");
-
-
if (!$result4) {
-
die('Query failed: To Vehicle Info Table ');
-
}
-
-
-
}
-
else {
-
-
echo "There Is No Data To Export ";
-
-
}
-
-
-
?>
2 16524 pbmods 5,821
Recognized Expert Expert
Heya, Fauk.
Make sure you're setting your MySQL connection encoding: -
mysql_query("SET NAMES 'utf-8'", $conn);
-
mysql_query("SET CHARACTER SET 'utf-8'", $conn);
-
Where $conn is your MySQL connection resource.
Dear Faruk,
You can use phpexcel library for this purpose. Its works great. You can download the library from here: http://code.google.com/p/php-excel/
The sample code is as follows (I used that in joomla):
function export_contact_ messages() {
$model = $this->getModel('user contacts');
$rows = $model->getContactMess ages();
global $mosConfig_abso lute_path;
if( !file_exists( $mosConfig_abso lute_path . '/libraries/phpexcel/PHPExcel.php') ) {
die('Phpexcel library not found');
}
$phpexcel_path = $mosConfig_abso lute_path . '/libraries/phpexcel/PHPExcel.php';
include_once($p hpexcel_path);
//die($phpexcel_p ath);
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties( )->setCreator("Ti tle")
->setLastModifie dBy("Title")
->setTitle("Cont act Message")
->setSubject("Co ntact Message");
$objPHPExcel->setActiveSheet Index(0)
->setCellValueBy ColumnAndRow(0, 1, "Name")
->setCellValueBy ColumnAndRow(1, 1, "Email")
->setCellValueBy ColumnAndRow(2, 1, "Message")
->setCellValueBy ColumnAndRow(3, 1, "Posted");
$row_count = 2;
foreach ($rows as $row) {
$objPHPExcel->setActiveSheet Index(0)
->setCellValueBy ColumnAndRow(0, $row_count, $row->name)
->setCellValueBy ColumnAndRow(1, $row_count, $row->email)
->setCellValueBy ColumnAndRow(2, $row_count, $row->message)
->setCellValueBy ColumnAndRow(3, $row_count, $row->created_at);
$row_count++;
}
// Rename sheet
$objPHPExcel->getActiveSheet ()->setTitle('cont act_message');
// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheet Index(0);
ob_clean();
// Redirect output to a client’s web browser (Excel5)
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;file name="contract_ messages.xls"') ;
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFact ory::createWrit er($objPHPExcel , 'Excel5');
$objWriter->save('php://output');
exit;
}
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: zahid |
last post by:
Hello,
Dear Friends,
I have to make such type of interface,you can say it a html form.
in which a admin can write arabic data and can insert that data or
recordsin database in ASP.
and i have to make a show.asp in which user can see that arabic data
in table from database on internet.
FOR english version i have make that project completely.
|
by: Do Park via SQLMonster.com |
last post by:
Hello all,
I don?t often export data from a table. I am wondering how you export data
from a table. I?d like to know how you export in real world.
Do you export data from a table to a flat file or what type? There are many
selections when you choose file type.
When do you need to export data? How often?
Do you use DTS rather than export wizard?
|
by: cab2 |
last post by:
We currently have an application built in Access that takes in a csv
file using docmd.transfertext. We allow users to export their data to
a file for later use (csv format). Users are also allowed to re-import
their archived data. This all works fine, until we have to update the
application for international users. The original csv files sent to
users contain dates and numbers in US format. However, once imported,
the numbers appear...
|
by: Igor |
last post by:
Hi everyone!
I have a question about exporting data to Microsoft Excel.
I am writing program in C# and have to export some data to excel workbook. It works very good using OLE technology, but it requires Microsoft Excel installed on every machine with my program. It is not quite convenient to do so.
Is there another way to export data to Excel, or how simply create file of Microsoft Excel format from my program (of cause, the format of...
|
by: Arif |
last post by:
My programs searches the header of input barcode in index file. Get the
record position next to Barcode header. Then moves the file pointer of
products file to reach that record.
My products file contains records as follows:
9N-F1T0153|002002820327|Data Switch|EA|00030900|00000
36-EPSON7753|010343600003|Øنمبر طابعه 500/570|EA|00001200|00000
ER-270019|013388270019|بقتال الشارع|EA|00019900|00000
| |
by: samsadi |
last post by:
Hi every one ,
I am using ASP to export database data to excel file. However, the database table contains special charecters like arabic charecters which is not being exported to excel properly. Is there anyway to acheive this.
can any one help ??
I used the below way:
<%@ Language=VBScript CodePage = "1256"%>
<html dir="rtl">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
|
by: Max2006 |
last post by:
Hi,
We are developing a SQL server based asp.net application. As part of
requirement we should allow users import/export some relational data through
web user interface. We are investigation which file format would be the most
efficient format to import export relational data.
So far we came up with two options: XML and Access MDB files and we prefer
MDB files.
|
by: hash4sp |
last post by:
Hello !
DBF file consists of a field i.e."districts" which holds data in Arabic language. DBF file is in ANSI format. How to convert this ANSI format so that it displays actual Arabic text on the browser.
There is nothing like ANSI encoding in .Net. I could only find ASCII, Unicode, etc. Please give some suggestions or solution to this problem.
Please reply asap.. very urgent for me...
Thanks in advance!
|
by: farukcse |
last post by:
Dear Sir,
I am facing a problem with exporting data . when i exported data the arabic characters comes with a invalid character set . i used utf8 encoding systeme in both of php files. so can any one tell me how can i keep the arabic text in a .csv xcel file after exporting? please reply.
Regards,
Faruk Chowdhury.
eader("Content-Disposition: attachment; filename=\"$file_name\"");
header("Cache-Control: cache, must-revalidate");...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |