簡體   English   中英

使用PHP保護列后如何導出Excel文件

[英]How Export Excel file after protecting column using php

導出時可以保護excel文件的幾列嗎,因此用戶不能意外地對這些列進行任何更改。

這是我導出excel文件的代碼。 我需要保護列1,2和4。 需要指導-

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";
    }
?>

預先感謝大家,等待建議和答復

這不是Excel文件,而是CSV文件。 您將其命名為“ .XLS ”,並且為了Microsoft的全能,它會按您的期望進行操作。

但是在CSV文件中,您無法進一步說明excel對列的處理方式。 您需要像在PHPExcel中那樣更智能地轉換為純Excel文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM