1. <?php
3. /*
4. $con = mysql_connect("localhost","root","");
5. if (!$con)
6.   {
7.   die('Could not connect: ' . mysql_error());
8.   }
9. mysql_select_db("nvron",$con);
10. */
13. $con = mysql_connect("localhost","nvronusr","DBpwd!@#");
14. if (!$con)
15.   {
16.   die('Could not connect: ' . mysql_error());
17.   }
19. mysql_select_db("nvron", $con);
20. $DOWNLOADPATH='C:\Users\LENOVO\Desktop'; // File Downloadable location
21. error_reporting(E_ALL);
22. $date=date('dS M Y'); // date format
23. $date1=date('d_M_Y'); // filename date format
25. $today=date('l');
26. //if($today=='Friday'){
28.     $ActiveUser=0;
29.     $CompletedUser=0;
30.     $NAcount=0;
31.     $NotAttempted=0;
32.     $InprogressUser=0;
34.     $font_type='calibri';
35.     $font_size='16px';
37.         $styleArray = array(
38.             'font' => array(
39.             'bold' => true,
40.             )
41.         );
43.     $my_subject="Employee Report as on ".$date;
45.     $my_message="<span style='font-family:".$font_type."; font-size:".$font_size.";'><br>
47.     <br><br>
49.     </span>
50.     <table style='font-family:".$font_type."; font-size:".$font_size."; border: 1px solid #000000; border-collapse:collapse;' width='400' border='1'>
51.       <tr height='30' bgcolor='red'>
52.        <h3>The Following employee has been Registerd for employee registration </h3> 
53.       </tr>";
59.     //Database connection 
60.    
61.     //Getting count of completed status count
62.     
63.     $qry1 ="select * from employee where email='$_POST[email1]'";
64.     $result1= mysql_query($qry1);
65.     $data=  mysql_fetch_array($result1);
66.     //$ActiveUser=mysql_num_rows($result1);
67.     
68.     //Getting count of incompleted status count
69.    /* $qry2 = "select distinct ss.userid,ss.username from test_course_history ss;"; 
70.     $result2= mysql_query($qry2);
71.     $CompletedUser=mysql_num_rows($result2);
72.     */
73.     //Getting count of Not attempted status count
74.     /*
75.     $qry3 = "select distinct ss.userid,user.username from test_course_history ss, test_users user 
76.             where user.userid=ss.userid and user.`status`='Active'"; 
77.     $result3= mysql_query($qry3);
78.     $NAcount=mysql_num_rows($result3);
79.     $InprogressUser=$NAcount-$CompletedUser;
80.     
81.     $NotAttempted=$ActiveUser-($CompletedUser+$InprogressUser);    
82. 
83. */
84. 
85. 
86. 
87.     $my_message.=" 
88.         
89.         
90.         
91.     </table><br><br><span style='font-family:".$font_type."; font-size:".$font_size.";'>
92.     Thanks,<br>
93.     Regards,<br>
94.     MANOJPRABHAKARAN P<br>
95.     NVRON TEAM<br>
96.     <br>
97.     </span>";
98.     echo $my_message;
99. 
100.     $query="select * from employee where email='$_POST[email1]'";
101.     $result=mysql_query($query);
102.     
103.     $filename='employee_Report_as_on_'.$date1.'.xls';
104.         
105.     $file_headerdata= '' . "\t" . 'fn' . "\t" . 'ln' ."\t" . 'dob'."\t" .'gender'  ."\t" .'maritial'  ."\t" .'present'  ."\t" .'permanent'."\t" .'city'  ."\t".'state'  ."\t" .'zipcode'  ."\t" .'mobile'  ."\t" .'email'  ."\t" .'citizen'  ."\t" .'blood'  ."\t" .'qualification'  ."\t" .'workexp'  ."\t" .'prevcmpy'  ."\t" .'prevdes'  ."\t" .'prevsal'  ."\t" .'expsal'  ."\t" .'hobbies'  ."\t" .'vision'  ."\t" .'language'  ."\t" .'father'  ."\t" .'mother'  ."\t" .'spouse'  ."\t" .'childrens'  ."\t" ."\n";
106.     $file_headerdata = getStyle($file_headerdata)->applyFromArray($styleArray);
107.     while($row=mysql_fetch_array($result))
108.     {
109.    /*
110.         if($row[1]=='Test Online Module')
111.             $row[1]='Test Online Course';
112.         if($row[3]==0 && $row[2]!='completed')
113.             $row[2]='Not Attempted';
114.         else if($row[3]!=0 && $row[2]!='completed') 
115.             $row[2]='Incomplete';
116.       */  
117.      
118.         $file_data[] =$row[0]."\t".$row[1]."\t".$row[2]."\t".$row[3]."\t".$row[4]."\t".$row[5]."\t".$row[6]."\t".$row[7]."\t".$row[8]."\t".$row[9]."\t".$row[10]."\t".$row[11]."\t".$row[12]."\t".$row[13]."\t".$row[14]."\t".$row[15]."\t".$row[16]."\t".$row[17]."\t".$row[18]."\t".$row[19]."\t".$row[20]."\t".$row[21]."\t".$row[22]."\t".$row[23]."\t".$row[24]."\t".$row[25]."\t".$row[26]."\n"; 
119.        
120.        //$file_data[] =$row[0]."\t".$row[1]."\t".$row[2]."\t".$row[3]. "\n"; 
121.        
122.     }
123.     mysql_close($con);
124.         $fname= writetofile($filename,$file_data);
125.     
126. 
127.     // Send mail functionality    
128.     $my_name = "NVRON SUPPORT";
129.     $my_mail = "infoitmanoj@gmail.com";
130.     $my_replyto = "infoitmanoj@gmail.com";
131.     $to = "infoitmanoj@gmail.com";    
132.     $cc="infoitmanoj@gamil.com";        
133.     send_mail($to, $my_mail, $my_name, $my_replyto, $my_subject, $my_message,$cc,$fname);
134. //}
135. 
136. //Write all data in Excel file and return the File name with its location  
137. function writetofile($filename,$file_data) {
138.     
139.     global $DOWNLOADPATH;
140.     $handle = fopen($DOWNLOADPATH.$filename, 'wb') or die("ERR:Can't open file");
141.   
142.     foreach($file_data as $key => $val){
143.         echo "\n";
144.         fwrite($handle, $val);
145.     }
146.     fclose($handle);
147.     $fname=$DOWNLOADPATH.$filename;
148.     return $fname;
149. }
150. 
151. //Send mail concept to send a mail with Attachment
152. function send_mail($mailto, $from_mail, $from_name, $replyto, $subject, $message,$cc,$fname) {
153.     //File  open method
154.     $fp = fopen($fname, "rb");
155.     $upload_size=filesize($fname);
156.     $file = fread($fp, $upload_size);
157. 
158.     $file = chunk_split(base64_encode($file));
159.     $num = md5(time());
160.     $upload_type=filetype($fname); 
161.     
162.      //Normal headers
163. 
164.     $headers  = "From: ".$from_name." <".$from_mail.">\r\n";
165.     $headers .= "Reply-To: ".$replyto."\r\n";
166.     $headers .= "Cc: ".$cc."\r\n";
167.     $headers  .= "MIME-Version: 1.0\r\n";
168.     $headers  .= "Content-Type: multipart/mixed; ";
169.     $headers  .= "boundary=".$num."\r\n";
170.     $headers  .= "--$num\r\n";   
171. 
172.     // With message
173.     
174.     $headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
175.     $headers .= "Content-Transfer-Encoding: 8bit\r\n";
176.     $headers .= $message."\r\n\r\n";
177.     $headers .= "--".$num."\n";
178. 
179.     // Attachment headers
180. 
181.     $headers  .= "Content-Type:".$upload_type." ";
182.     $headers  .= "name=\"".$fname."\"r\n";
183.     $headers  .= "Content-Transfer-Encoding: base64\r\n";
184.     $headers  .= "Content-Disposition: attachment; ";
185.     $headers  .= "filename=\"".basename($fname)."\"\r\n\n";
186.     $headers  .= "".$file."\r\n";
187.     $headers  .= "--".$num."--";
188. 
189. 
190. 
191.     //Send mail method
192. 
193.     if (mail($mailto, $subject, "", $headers)) {
194.     echo "mail send ... OK"; // or use booleans here
195.     } else {
196.     echo "mail send ... ERROR!";
197.     }
198. }
199. ?>

Where you defined getStyle() function?

i'm assuming you want to the PHPExcel. you need to create to download the PHPExcel classes and include them in your script like this.

require_once 'path_to_PHPExcel_classes/Classes/PHPExcel.php';

after this create an object of that class like this.

$objPHPExcel = new PHPExcel();

$objPHPExcel->setActiveSheetIndex( 0 ); // set the first sheet as the sheet to use
$objPHPExcel->getActiveSheet()->getStyle( 'A1' )->applyFromArray( $styleArray ); // apply the style in $styleArray

the getStyle() function works on a particular cell.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.