مشکل با ساخت فایل excel

amirepsilon

Active Member
سلام
دوستان من فایل excel رو میتونم بسازم
ولی مشکل اینجاست که حروف فارسی رو نمیتونم درست نشون بودم
کسی میتونه کمکم کنه ؟
این هم کد :

PHP:
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=222.xls");
 

Masoud1365

مدیر انجمن
یه کلاس برای ساخت فایل اکسل دیدم ( phpclasses.org ) که خیلی کامل بود اگر از اونا استفاده کنید فکر کنم امکان ست کردن یونیکد هم باشه ! ( یه سرچی بزنید تو ساتی که گفتم ، احتمالا مشکل حل میشه :wink: )
 

imanmir

Member
سلام دوست عزیز

خوبی خسته نباشی
لطفا لینک یا کدی که بشه یک فایل اکسل درست شود و با php به mysql ببرم اینجا بزاری یا یک لینک منبع معرفی کن
رسی
 

k2-4u

Well-Known Member
فایل excel رو میشه خیلی ساده درست کرد
کافیه ابتدای یک فایل اول کد زیر رو قرار بدین
HTML:
<html xmlns:o="urn:schemas-microsoft-com:office:office"
				xmlns:x="urn:schemas-microsoft-com:office:excel"
				xmlns="http://www.w3.org/TR/REC-html40">

				<head>
				<meta http-equiv=Content-Type content="text/html; charset=utf-8">
				<meta name=ProgId content=Excel.Sheet>
				<!--[if gte mso 9]><xml>
				 <o:DocumentProperties>
				  <o:LastAuthor>$table</o:LastAuthor>
				  <o:LastSaved>2005-01-02T07:46:23Z</o:LastSaved>
				  <o:Version>10.2625</o:Version>
				 </o:DocumentProperties>
				 <o:OfficeDocumentSettings>
				  <o:DownloadComponents/>
				 </o:OfficeDocumentSettings>
				</xml><![endif]-->
				<style>
				<!--table
					{mso-displayed-decimal-separator:"\.";
					mso-displayed-thousand-separator:"\,";}
				@page
					{margin:1.0in .75in 1.0in .75in;
					mso-header-margin:.5in;
					mso-footer-margin:.5in;}
				tr
					{mso-height-source:auto;}
				col
					{mso-width-source:auto;}
				br
					{mso-data-placement:same-cell;}
				.style0
					{mso-number-format:General;
					text-align:general;
					vertical-align:bottom;
					white-space:nowrap;
					mso-rotate:0;
					mso-background-source:auto;
					mso-pattern:auto;
					color:windowtext;
					font-size:10.0pt;
					font-weight:400;
					font-style:normal;
					text-decoration:none;
					font-family:Arial;
					mso-generic-font-family:auto;
					mso-font-charset:0;
					border:none;
					mso-protection:locked visible;
					mso-style-name:Normal;
					mso-style-id:0;}
				td
					{mso-style-parent:style0;
					padding-top:1px;
					padding-right:1px;
					padding-left:1px;
					mso-ignore:padding;
					color:windowtext;
					font-size:10.0pt;
					font-weight:400;
					font-style:normal;
					text-decoration:none;
					font-family:Arial;
					mso-generic-font-family:auto;
					mso-font-charset:0;
					mso-number-format:General;
					text-align:general;
					vertical-align:bottom;
					border:none;
					mso-background-source:auto;
					mso-pattern:auto;
					mso-protection:locked visible;
					white-space:nowrap;
					mso-rotate:0;}
				.xl24
					{mso-style-parent:style0;
					white-space:normal;}
				-->
				</style>
				<!--[if gte mso 9]><xml>
				 <x:ExcelWorkbook>
				  <x:ExcelWorksheets>
				   <x:ExcelWorksheet>
					<x:Name>srirmam</x:Name>
					<x:WorksheetOptions>
					 <x:Selected/>
					 <x:ProtectContents>False</x:ProtectContents>
					 <x:ProtectObjects>False</x:ProtectObjects>
					 <x:ProtectScenarios>False</x:ProtectScenarios>
					</x:WorksheetOptions>
				   </x:ExcelWorksheet>
				  </x:ExcelWorksheets>
				  <x:WindowHeight>10005</x:WindowHeight>
				  <x:WindowWidth>10005</x:WindowWidth>
				  <x:WindowTopX>120</x:WindowTopX>
				  <x:WindowTopY>135</x:WindowTopY>
				  <x:ProtectStructure>False</x:ProtectStructure>
				  <x:ProtectWindows>False</x:ProtectWindows>
				 </x:ExcelWorkbook>
				</xml><![endif]-->
				</head>

				<body link=blue vlink=purple>
				<table x:str border=0 cellpadding=0 cellspacing=0 style='border-collapse: collapse;table-layout:fixed;'>

سپس دقیقا مثل ساختار جدول HTML محتوا رو به صورت زیر . در ادامه فایل بریزین

HTML:
<tr>
<td>text</td>
<td>text</td>
</tr>

<tr>
<td>text</td>
<td>text</td>
</tr>

<tr>
<td>text</td>
<td>text</td>
</tr>

بعد ادامه تک را رو ببندین

HTML:
</table>
</body>
</html>
 

k2-4u

Well-Known Member
بهترین کار برای خروجی گرفتن از excel
استفاده از ODBC هستش
http://nl.php.net/manual/en/function.odbc-connect.php
این هم یک مثال

PHP:
<?php
// Microsoft SQL Server using the SQL Native Client 10.0 ODBC Driver - allows connection to SQL 7, 2000, 2005 and 2008
$connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);

// Microsoft Access
$connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);

// Microsoft Excel
$excelFile = realpath('C:/ExcelData.xls');
$excelDir = dirname($excelFile);
$connection = odbc_connect("Driver={Microsoft Excel Driver (*.xls)};DriverId=790;Dbq=$excelFile;DefaultDir=$excelDir" , '', '');
?>

و
 

imanmir

Member
با سلام

مرسی،لطفا یک نمونه کامل را آپلود کنید زیاد واضح نبود
 

k2-4u

Well-Known Member
برای نمونه کامل به
http://nl.php.net/manual/en/function.odbc-connect.php
این آدرس برین
.
بیس کار رو برای شما توضیح دادم . دیگه شما به عنوان یک برنامه نویس
ادامه کار رو خودتون دنبال کنید
کلید کار شما اتصال به excel با توابع odbc هستش که خدمتتون عرض کردم
 

excel

New Member
اگر در زمينه نرم افزار اكسل اطلاعات تخصصي خواستيد
به تالارهاي گفتگو جامعه اكسل ايرانيان برويد
www.exceliran.com
 

جدیدترین ارسال ها

بالا