Is it possible to protect few columns of excel file while exporting them, so user cannot make any changes in those columns accidentally.
Here the code by which I am exporting my excel file. I need to protect column 1,2,and 4 to be protected. Need guidance -
require_once('dbconfig.php');
$DB_TBLName = "admission";
$filename = "excelfilename"; //File Name
/*******YOU DO NOT NEED TO EDIT ANYTHING BELOW THIS LINE*******/
//create MySQL connection
//$sql = "Select * from $DB_TBLName where branch_id = '$branch' AND addmission_date between '$date1' AND '$date2'";
$sql = "select * from admission where $search branch_id = '$branch'";
//echo $sql;
//execute query
$result = mysql_query($sql) or die("Couldn't execute query:<br>" . mysql_error(). "<br>" . mysql_errno());
$file_ending = "csv";
//header info for browser
header("Content-Type: application/xls");
header("Content-Disposition: attachment; filename=$filename.xls");
header("Pragma: no-cache");
header("Expires: 0");
/*******Start of Formatting for Excel*******/
//define separator (defines columns in excel & tabs in word)
$sep = "\t"; //tabbed character
//start of printing column names as names of MySQL fields
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo mysql_field_name($result,$i) . "\t";
}
print("\n");
//end of printing column names
//start while loop to get data
while($row = mysql_fetch_row($result))
{
$schema_insert = "";
for($j=0; $j<mysql_num_fields($result);$j++)
{
if(!isset($row[$j]))
$schema_insert .= "NULL".$sep;
elseif ($row[$j] != "")
$schema_insert .= "$row[$j]".$sep;
else
$schema_insert .= "".$sep;
}
$schema_insert = str_replace($sep."$", "", $schema_insert);
$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
$schema_insert .= "\t";
print(trim($schema_insert));
print "\n";
}
?>
Thank you every body in advance and waiting for suggestions and reply
This is not an Excel file, but a CSV file. You are naming it " .XLS
" and for the sake of Microsofts almighty it does what you expect.
But in a CSV file you can't have an further statements to what excel should do with columns. You need a more intelligent conversion to a pure Excel file like in PHPExcel .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.