Creating excel file for download
Posted by mkhairul - June 15, 2008 at 03:06:33 pm -Categories: blog
There is a problem with CI's excel plugin. It generates a tab delimited file and download it as an excel file. But when I open it up using Excel, it says the file is in a different format. So it is NOT an excel file.
The problem of it not being an Excel file is that, the file that is to be downloaded is supposed to be fed on to another application (written in ASP.NET) and the application just outright refuses it. So, a colleague suggest to me that he will copy the contents into an excel file and uploaded it, which defeats the purpose of a system.
I found a way to create an excel file from Appserv Open Project.
-
function xlsBOF() {
-
return;
-
}
-
-
function xlsEOF() {
-
return;
-
}
-
-
function xlsWriteNumber($Row, $Col, $Value) {
-
return;
-
}
-
-
function xlsWriteLabel($Row, $Col, $Value ) {
-
echo $Value;
-
return;
-
}
And send the header to the browser, for it to be download.
-
// Query Database
-
$result=mysql_db_query($dbname,"select id,prename,name,sname,grade from appdata where course='$courseid' and sec='$section'")
-
-
// Send Header
-
-
// XLS Data Cell
-
-
xlsBOF();
-
xlsWriteLabel(1,0,"Student Register $semester/$year");
-
xlsWriteLabel(2,0,"COURSENO : ");
-
xlsWriteLabel(2,1,"$courseid");
-
xlsWriteLabel(3,0,"TITLE : ");
-
xlsWriteLabel(3,1,"$title");
-
xlsWriteLabel(4,0,"SETION : ");
-
xlsWriteLabel(4,1,"$sec");
-
xlsWriteLabel(6,0,"NO");
-
xlsWriteLabel(6,1,"ID");
-
xlsWriteLabel(6,2,"Gender");
-
xlsWriteLabel(6,3,"Name");
-
xlsWriteLabel(6,4,"Lastname");
-
$xlsRow = 7;
-
++$i;
-
xlsWriteNumber($xlsRow,0,"$i");
-
xlsWriteNumber($xlsRow,1,"$id");
-
xlsWriteLabel($xlsRow,2,"$prename");
-
xlsWriteLabel($xlsRow,3,"$name");
-
xlsWriteLabel($xlsRow,4,"$sname");
-
$xlsRow++;
-
}
-
xlsEOF();
Works like a charm.
No Comments yet »
RSS feed for comments on this post. TrackBack URI
Leave a comment
Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds.
Valid XHTML and CSS.
