Devilzc0de Forum Follow @devilzc0de
  • Home
  • Hacking
  • Networking
  • Programming
  • O.S
  • Server
  • Tweets
  • Search
  • Member List
  • Calendar
Current time: 06-20-2013, 12:24 AM Hello There, Guest! (Login — Register)
Devilzc0de Forum › Information Technology › Programming › PHP v
« Previous 1 ... 14 15 16 17 18 ... 32 Next »

[Tutor] PHP Convert To Excel

Home General Computer Multimedia Business Lounge

Pages (2): 1 2 Next »
Post Reply 
Tweet
Threaded Mode | Linear Mode
Tutor PHP Convert To Excel
02-06-2012, 06:06 PM
Post: #1
vhyVizz Offline
Moderator
**
Moderators
Posts: 2,862
Joined: Apr 2010
Reputation: 39
PHP Convert To Excel
Salam logodc

thread ini dibuat atas request dari ./ rex ketawa
sebenernya diambil dari webnya Roshinari. cuma yg sy buat, dibikin table dulu. baru di convert ke excel..

oke, mulai saja..
terlebih dahulu kita siapkan tabel dan recordnya.
CREATE TABLE nilaimhs(
nim varchar(10),
namaMhs varchar(30),
nilai int(11),
PRIMARY KEY(nim)
)
INSERT INTO nilaimhs VALUES
('M0197001', 'Faza Fauzan Kh.', 80),
('M0197002', 'Dwi Amalia Fitriani', 75),
('M0197003', 'Rosihan Ari Yuana', 45),
('M0197004', 'Nada Hasanah', 83),
('M0197005', 'Muh. Ahsani Taqwim', 90);
Setelah tabel dan record sudah siap, ini script untuk menampilkan data yg sudah diinput tadi
<table>
<tr>
<td align="center" valign="top"><strong>DAFTAR MAHASISWA</strong></td>
</tr>
<tr>
<td align="right"><a href="report.php">Convert To Excel</a></td>
</tr>
<tr>
<td align="center">
<table cellpadding="3" cellspacing="2" align="center" border="1">
<tr align="center">
<td><span class=\"style1\">NO</span></td>
<td><span class=\"style1\">NIM</span></td>
<td><span class=\"style1\">NAMA MAHASISWA</span></td>
<td><span class=\"style1\">NILAI</span></td>
<td><span class=\"style1\">STATUS KELULUSAN</span></td>

<?php

mysql_connect("localhost", "root", "root");
mysql_select_db("xls");

$setning = @mysql_query("SELECT * FROM nilaimhs ORDER BY nim ASC");

$nomor = 1;

while($gb = @mysql_fetch_array($setning))
{
?>
<tr align="center">
<td><?php echo $nomor; ?></td>
<td><?php echo "$gb[nim]"; ?></td>
<td><?php echo "$gb[namaMhs]"; ?></td>
<td><?php echo "$gb[nilai]"; ?></td>
<td>
<?php
if ($gb['nilai'] >= 60)
echo $status = "LULUS";
else
echo $status = "TIDAK LULUS";
?>
</td>
</tr>
<?php
$nomor++;
}
?>
</tr>
</table>
</td>
</tr>
</table>
Gambar :
[Image: 55bf76cd4ca7f5e5ee4223eccbf7ff55d257199e...d5074g.jpg]

Berikutnya, ini script Convert To Excel untuk mengconvert ke excelnya (langsung download)..
<?php

// nama file

$namaFile = "report.xls";

// Function penanda awal file (Begin Of File) Excel

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

// Function penanda akhir file (End Of File) Excel

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

// Function untuk menulis data (angka) ke cell excel

function xlsWriteNumber($Row, $Col, $Value) {
echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
echo pack("d", $Value);
return;
}

// Function untuk menulis data (text) ke cell excel

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

// header file excel

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 untuk nama file
header("Content-Disposition: attachment;
filename=".$namaFile."");

header("Content-Transfer-Encoding: binary ");

// memanggil function penanda awal file excel
xlsBOF();

// ------ membuat kolom pada excel --- //

// mengisi pada cell A1 (baris ke-0, kolom ke-0)
xlsWriteLabel(0,0,"NO");

// mengisi pada cell A2 (baris ke-0, kolom ke-1)
xlsWriteLabel(0,1,"NIM");

// mengisi pada cell A3 (baris ke-0, kolom ke-2)
xlsWriteLabel(0,2,"NAMA MAHASISWA");

// mengisi pada cell A4 (baris ke-0, kolom ke-3)
xlsWriteLabel(0,3,"NILAI");

// mengisi pada cell A5 (baris ke-0, kolom ke-4)
xlsWriteLabel(0,4,"STATUS KELULUSAN");

// -------- menampilkan data --------- //

// koneksi ke mysql

mysql_connect("localhost", "root", "root");
mysql_select_db("xls");

// query menampilkan semua data

$query = "SELECT * FROM nilaimhs";
$hasil = mysql_query($query);

// nilai awal untuk baris cell
$noBarisCell = 1;

// nilai awal untuk nomor urut data
$noData = 1;

while ($data = mysql_fetch_array($hasil))
{
// menampilkan no. urut data
xlsWriteNumber($noBarisCell,0,$noData);

// menampilkan data nim
xlsWriteLabel($noBarisCell,1,$data['nim']);

// menampilkan data nama mahasiswa
xlsWriteLabel($noBarisCell,2,$data['namaMhs']);

// menampilkan data nilai
xlsWriteNumber($noBarisCell,3,$data['nilai']);

// menentukan status kelulusan
if ($data['nilai'] >= 60) $status = "LULUS";
else $status = "TIDAK LULUS";

// menampilkan status kelulusan
xlsWriteLabel($noBarisCell,4,$status);

// increment untuk no. baris cell dan no. urut data
$noBarisCell++;
$noData++;
}

// memanggil function penanda akhir file excel
xlsEOF();
exit();

?>
Gambar :
[Image: 9ea89aa75c6d40ac6c866b83e91e3d5d41d8b556...ca5d4g.jpg]

Keterangan :
Quote:mysql_connect("localhost", "root", "root");
mysql_select_db("xls");
sesuaikan host, username, password, database dengan yang ada di kompi kalian..

Quote:<?php
if ($gb['nilai'] >= 60)
echo $status = "LULUS";
else
echo $status = "TIDAK LULUS";
?>
script itu untuk status kelulusan..

apalagi ya keterangannya? tanya aja deh kalo ada yang ga ngerti..


makasih..
Find all posts by this user
Quote this message in a reply
 Reputed by :  ./ rex(+1) , kurapika(+1) , ditatompel(+1) , DC_Julianz(+1) , Killu4(+1) , ketek(+1) , schumbag(+1)
02-06-2012, 06:13 PM
Post: #2
./ rex Away
Wahyu Adi Prasetyo
**
Moderators
Posts: 846
Joined: Sep 2010
Reputation: 47
RE: PHP Convert To Excel
jadi tersipu hehehehe mantap dah tengkiu mbak ijin belajar ngetrek
Visit this user's website Find all posts by this user
Quote this message in a reply
02-06-2012, 06:18 PM
Post: #3
vhyVizz Offline
Moderator
**
Moderators
Posts: 2,862
Joined: Apr 2010
Reputation: 39
RE: PHP Convert To Excel
hehehe gpp kaka.. kan sama2 belajar..
Find all posts by this user
Quote this message in a reply
02-06-2012, 07:12 PM
Post: #4
0n4l Offline
./Devilz Officer
Posts: 152
Joined: Feb 2011
Reputation: 0
RE: PHP Convert To Excel
ikut nyimak belajar teteh ....
Find all posts by this user
Quote this message in a reply
02-06-2012, 07:17 PM
Post: #5
ditatompel Offline
Administrator
*******
Administrators
Posts: 2,205
Joined: Dec 2010
Reputation: 371
RE: PHP Convert To Excel
Ajib tante... Ijin pelajari... Klo ane biasanya pake PHPExcel.. asik
Find all posts by this user
Quote this message in a reply
02-06-2012, 07:26 PM
Post: #6
vhyVizz Offline
Moderator
**
Moderators
Posts: 2,862
Joined: Apr 2010
Reputation: 39
RE: PHP Convert To Excel
(02-06-2012 07:12 PM)0n4l Wrote:  ikut nyimak belajar teteh ....
ya silakan..

(02-06-2012 07:17 PM)ditatompel Wrote:  Ajib tante... Ijin pelajari... Klo ane biasanya pake PHPExcel.. asik
btw, sama2 ribet sih yang pastinya hmm
Find all posts by this user
Quote this message in a reply
02-06-2012, 07:35 PM
Post: #7
DC_Julianz Offline
17yo, singgle, Programmer
**
Moderators
Posts: 2,049
Joined: Sep 2011
Reputation: 70
RE: PHP Convert To Excel
wawa aku izin pelajari teh belajar



mantap
Visit this user's website Find all posts by this user
Quote this message in a reply
02-06-2012, 07:37 PM
Post: #8
vhyVizz Offline
Moderator
**
Moderators
Posts: 2,862
Joined: Apr 2010
Reputation: 39
RE: PHP Convert To Excel
(02-06-2012 07:35 PM)DC_Juli24 Wrote:  wawa aku izin pelajari teh belajar



mantap

ya silakan chaer
Find all posts by this user
Quote this message in a reply
02-06-2012, 08:11 PM
Post: #9
Bunga.Mataharry Away
Devilzc0de Ambassador
***
Posts: 1,432
Joined: Jan 2011
Reputation: 90
RE: PHP Convert To Excel
itu semua diketik sendiri ya kode nya Vi, gak jadi belajar php aah... prustasiprustasi
Visit this user's website Find all posts by this user
Quote this message in a reply
02-06-2012, 08:15 PM
Post: #10
vhyVizz Offline
Moderator
**
Moderators
Posts: 2,862
Joined: Apr 2010
Reputation: 39
RE: PHP Convert To Excel
(02-06-2012 08:11 PM)nofia fitri Wrote:  itu semua diketik sendiri ya kode nya Vi, gak jadi belajar php aah... prustasiprustasi

iya diketik sendiri..
kalo vi kan coding dari nol.
kalo yg udah expert, pake function untuk memudahkan..

ayo belajar mbaaak hore
Find all posts by this user
Quote this message in a reply
« Next Oldest | Next Newest »
Pages (2): 1 2 Next »
Post Reply 


Topic Tools
Topic Link :
BBCode :
HTML Code :
View a Printable Version Send Thread to a Friend Subscribe to this thread
Submit Google Submit Face book Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  [Tutor] script untuk import excel ke MySQL dellacroug 9 181 04-29-2013 11:33 AM
Last Post: Sixmart
  [Ask] escaping/convert json utf8 darkslayer 1 64 04-20-2013 11:50 AM
Last Post: wenkhairu
  [Ask] cara convert word to swf region 3 172 10-24-2012 04:24 PM
Last Post: Cruz3N
  [Tutor] Convert Gambar Ke Text dengan PHP fuxnbums 13 1,379 05-21-2012 03:12 AM
Last Post: adiscsi
Information Convert text to MD5 for beginners devilgyan 4 365 05-17-2012 12:36 AM
Last Post: suicidal
  [Ask] Excel Reader Joris 8 675 03-11-2012 08:05 PM
Last Post: Joris
  [ask]script php untuk convert ping 5 2,164 04-20-2010 09:15 AM
Last Post: ping

Users Browsing

  • Contact Us
  • devilzc0de
  • Return to Top
  • Mobile Version
  • RSS Syndication
  • Help
Current time: 06-20-2013, 12:24 AM Powered By MyBB, © 2002-2013 MyBB Group. Theme created by Justin S. | Mixed By Chaer.Newbie | Fixed By Aditya

USING THIS SITE INDICATES THAT YOU HAVE READ AND ACCEPT OUR TERMS. IF YOU DO NOT ACCEPT THESE TERMS, YOU ARE NOT AUTHORIZED TO USE THIS SITE