I have a products page list and i am exporting it to a word document and also allowing user to print the document window.print
... I click ExportToWord
button saves as
dialog opens and i canceled it... Next when i click print button the print dialog appears for a second and minmizes and the Saves as
dialog appears containing the word document...
For word:
else if($btn_value == 'word')
{
$nam = 'StudentSeatAllot';
$this->load->library('table');
$getCollege = $this->adminmodel->getUserCollege();
$data['viewseatdet']=$this->adminmodel->seatallotreport($college);
$this->table->set_heading('Degree','Department','Batch',
'Category','Seatsalloted');
$out = $this->table->generate($data['viewseatdet']);
//header("Content-type: application/x-ms-download");
//header("Content-disposition: attachment; filename=$cur_date.doc");
header("Content-Type: application/vnd.ms-word");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-disposition: attachment; filename=$nam.doc");
$collegeName = $getCollege[2];
$collegeAddr1 = $getCollege[5].', '.$getCollege[6].' - '.$getCollege[7];
$collegeAddr2 = $getCollege[10].', '.$getCollege[8];
echo '<b><center>'.strtoupper($collegeName).'</b>';
echo '<br><b>'.strtoupper($collegeAddr1);
echo '<br><b>'.strtoupper($collegeAddr2).'</center>';
echo '<br><br>';
echo 'S E A T A L L O T - D E T A I L S<br><br>';
print_r($out);
}
For print i am using javascript:
function tablePrint()
{
var display_setting="toolbar=no,location=no,directories=no,menubar=no,";
display_setting+="scrollbars=yes,,status=no,width=750, height=600, left=100, top=25";
var content_innerhtml = document.getElementById("tbl_display").innerHTML;
var document_print=window.open("","",display_setting);
document_print.document.open();
document_print.document.write('<html><head><title>Campus Unified</title><link rel="stylesheet" type="text/css" href="<?=base_url()?>stylesheets/stylesheet.css" /> </head>');
document_print.document.write('<body onLoad="self.print();" >');
document_print.document.write('<center><strong>');
document_print.document.write(content_innerhtml);
document_print.document.write('</strong></center>');
document_print.document.write('</body></html>');
document_print.document.close();
}
![alt text][1]
Second EDIT: My print button,
<button type="submit" class="print" name="print" value="print" onfocus="this.blur();"
onclick="tablePrint();">
and content_innerhtml
<div id="tbl_display" style="display:none" >
<? if(isset($viewseatdet_print)) { ?>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="3" align="right" style="padding-right:5px" class="table_label">Date : <?= date('d-m-Y') ?></td>
</tr>
<tr><td colspan="3" class="table_label" align="center">
<? if(isset($_SESSION['empCollege'])) { $userCollege = $_SESSION['empCollege'];
echo strtoupper($userCollege[2]).'<br>'.strtoupper($userCollege[5]);
if(!empty($userCollege[6])){ echo ', '.$userCollege[6]; }
if(!empty($userCollege[7])){ echo ' - '.$userCollege[7]; }
if( (sizeof($userCollege))==11)
{ echo '<br>'.strtoupper($userCollege[9]).', '.strtoupper($userCollege[8]); }
}?>
</td></tr>
</table>
<table ><tr height="10px"><td> </td></tr></table>
<div style="padding-left:4px" class="table_label_header" align="center">
S E A T S - A L L O T M E N T
</div>
<table width="500px" cellpadding="4" cellspacing="0" border="1" >
<tr>
<td style="width:10%" class="grid_header" align="center">Degree</td>
<td style="width:15%" class="grid_header" align="center">Department</td>
<td style="width:15%" class="grid_header" align="center">Category</td>
<td style="width:10%" class="grid_header" align="center">Seatsalloted</td>
</tr>
<? if(empty($viewseatdet_print))
{ echo '<tr><td colspan=2>no record found !</td></tr>'; } ?>
<? foreach($viewseatdet_print as $row) { ?>
<tr>
<td style="width:10%" class="table_label" align="center"><?= $row['dDegreeName']?></td>
<td style="width:15%" class="table_label" align="center"><?= $row['dDepartmentName']?></td>
<td style="width:15%" class="table_label" align="center"><?= $row['dCategory']?></td>
<td style="width:15%" class="table_label" align="center"><?= $row['dSeatsAllot']?></td>
</tr>
<? } ?>
</table>
<? } ?>
</div>
Word HTML:
<button type="submit" class="word" name="word" value="word" onfocus="this.blur();"
onclick="return getButtonType('word');">