php表格數(shù)據(jù)居中 php表格居中怎么設(shè)置

thinkphp之excel的導(dǎo)出excel怎么居中

導(dǎo)入Excel

成都創(chuàng)新互聯(lián)公司成立十余年來,這條路我們正越走越好,積累了技術(shù)與客戶資源,形成了良好的口碑。為客戶提供成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、網(wǎng)站策劃、網(wǎng)頁設(shè)計、域名與空間、網(wǎng)絡(luò)營銷、VI設(shè)計、網(wǎng)站改版、漏洞修補等服務(wù)。網(wǎng)站是否美觀、功能強大、用戶體驗好、性價比高、打開快等等,這些對于網(wǎng)站建設(shè)都非常重要,成都創(chuàng)新互聯(lián)公司通過對建站技術(shù)性的掌握、對創(chuàng)意設(shè)計的研究為客戶提供一站式互聯(lián)網(wǎng)解決方案,攜手廣大客戶,共同發(fā)展進步。

第一,在前臺html頁面進行上傳文件:如:

form method="post" action="php文件" enctype="multipart/form-data"

h3導(dǎo)入Excel表:/h3input type="file" name="file_stu" /

input type="submit" value="導(dǎo)入" /

/form

第二,在對應(yīng)的php文件進行文件的處理

if (! empty ( $_FILES ['file_stu'] ['name'] ))

{

$tmp_file = $_FILES ['file_stu'] ['tmp_name'];

$file_types = explode ( ".", $_FILES ['file_stu'] ['name'] );

$file_type = $file_types [count ( $file_types ) - 1];

if (strtolower ( $file_type ) != "xls")

{

$this-error ( '不是Excel文件,重新上傳' );

}

$savePath = SITE_PATH . '/public/upfile/Excel/';

/*以時間顯示來命名上傳的文件*/

$str = date ( 'Ymdhis' );

$file_name = $str . "." . $file_type;

if (! copy ( $tmp_file, $savePath . $file_name ))

{

$this-error ( 'die' );

}

$res = Service ( 'ExcelToArray' )-read ( $savePath . $file_name );

//spl_autoload_register ( array ('Think', 'autoload' ) );

/*對生成的數(shù)組進行數(shù)據(jù)庫的寫入*/

foreach ( $res as $k = $v )

{

if ($k != 0)

{

$data ['uid'] = $v [0];

$data ['password'] = sha1 ( '111111' );

$data ['email'] = $v [1];

$data ['uname'] = $v [3];

$data ['institute'] = $v [4];

$result = M ( 'user' )-add ( $data );

if (! $result)

{

$this-error ( '導(dǎo)入數(shù)據(jù)庫失敗' );

}

}

}

}

第三:ExcelToArrary類,用來引用phpExcel并處理Excel數(shù)據(jù)的

備注:ExcelToArrary類建在根目錄下的 addons /services/ExcelToArrary.class.php中

class ExcelToArrary extends Service{

public function __construct() {

include_once('./Excel/PHPExcel.php');

}

public function read($filename,$encode='utf-8'){

$objReader = PHPExcel_IOFactory::createReader('Excel5');

$objReader-setReadDataOnly(true);

$objPHPExcel = $objReader-load($filename);

$objWorksheet = $objPHPExcel-getActiveSheet();

$highestRow = $objWorksheet-getHighestRow();

$highestColumn = $objWorksheet-getHighestColumn();

$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn);

$excelData = array();

for ($row = 1; $row = $highestRow; $row++) {

for ($col = 0; $col $highestColumnIndex; $col++) {

$excelData[$row][] =(string)$objWorksheet-getCellByColumnAndRow($col, $row)-getValue();

}

}

return $excelData;

}

}

第四,以上就是導(dǎo)入的全部內(nèi)容,phpExcel包附在最后。

(二)Excel的導(dǎo)出(相對于導(dǎo)入簡單多了)

第一,先查出數(shù)據(jù)庫里面要生成Excel的數(shù)據(jù),如:

$data= M('User')-findAll(); //查出數(shù)據(jù)

$name='Excelfile'; //生成的Excel文件文件名

$res=service('ExcelToArrary')-push($data,$name);

第二,ExcelToArrary類,用來引用phpExcel并處理數(shù)據(jù)的

class ExcelToArrary extends Service{

public function __construct() {

/*導(dǎo)入phpExcel核心類 注意 :你的路徑跟我不一樣就不能直接復(fù)制*/

include_once('./Excel/PHPExcel.php');

}

/* 導(dǎo)出excel函數(shù)*/

public function push($data,$name='Excel'){

error_reporting(E_ALL);

date_default_timezone_set('Europe/London');

$objPHPExcel = new PHPExcel();

$objPHPExcel-getProperties()-setCreator("php愛好者")

-setLastModifiedBy("php愛好者")

-setTitle("數(shù)據(jù)EXCEL導(dǎo)出")

-setSubject("數(shù)據(jù)EXCEL導(dǎo)出")

-setDescription("備份數(shù)據(jù)")

-setKeywords("excel")

-setCategory("result file");

foreach($data as $k = $v){

$num=$k+1;

$objPHPExcel-setActiveSheetIndex(0)

//Excel的第A列,uid是你查出數(shù)組的鍵值,下面以此類推

-setCellValue('A'.$num, $v['uid'])

-setCellValue('B'.$num, $v['email'])

-setCellValue('C'.$num, $v['password'])

}

$objPHPExcel-getActiveSheet()-setTitle('User');

$objPHPExcel-setActiveSheetIndex(0);

header('Content-Type: application/vnd.ms-excel');

header('Content-Disposition: attachment;filename="'.$name.'.xls"');

header('Cache-Control: max-age=0');

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');

$objWriter-save('php://output');

exit;

}

php高手進,急。怎么讓他居中啊

你這個是絕對定位吧。有公式的

{left:50%;height:50%;margin-left:-(你中間內(nèi)容部分的總寬度)/2;margin-top:-(你浮動的對象的總高度)/2;}

PHP怎么把全部頁面居中

頁面居中需要用css控制html

用到的css居中的style有text-align:center; 和 margin:0px?auto

舉例為:

html

head

meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/?

title無標題/title

/head

body?style="text-align:center;"

div?style="margin:0px?auto"

頁面

/div

/body

/html

網(wǎng)頁制作中如何將表單中的內(nèi)容居中

1、需要在DW中讓該表格中的這些內(nèi)容達到居中的效果。

2、如果要讓DW表格內(nèi)容居中的話,選擇居中對齊就可以了。

3、在代碼窗口里面將該表格的align="某某"改成align="left"即可。

4、另外,還可以先用鼠標拖選中要改變居中方式的那些表格,可以一次拖選中多個表格。

5、再去點擊DW下面屬性欄中的那些居中樣式按鈕即可。

6、最終的結(jié)果都使表格內(nèi)容居中。

PHP生成excel,就是用header生成,請問如何控制生成的excel樣式。比如居中對齊,背影顏色等?

哎.這個問題怎麼這麼冷門呢.這麼久了都沒個人來回答一下.我來吧.望樓主采納.

用樓主的這種方式來生成excel表的話.是控制不了樣式的.為此,需要對代碼重新做一些修改.

我們可以在代碼上簡單的加上td width=設(shè)定表格寬度.td align=水平對齊方式

至於背景色嘛.你就只有自己加上其它的屬性來進行控制了(我倒是加了個對文字顏色進行控制).上代碼了.我貼了一段我自己的你看看.然後,舉一反三就行了.照著改就行了.good luck!

?php

error_reporting(0);//屏蔽提示信息

Header( "Content-type: application/octet-stream ");

Header( "Accept-Ranges: bytes ");

Header( "Content-type:application/vnd.ms-excel ;charset=utf-8");//自己寫編碼

Header( "Content-Disposition:attachment;filename=abnormal_Report.xls "); //名字

echo "table width='100%' border='1' "; //邊框

echo"tr";

echo "td style='color:red' align='center' font size=4ID /font/td";

echo "td style='color:red' align='center' font size=4異常時間 /font/td";

echo "td style='color:red' align='center' font size=4異常地點 /font/td";

echo "td style='color:red' align='center' font size=4詳細內(nèi)容 /font/td";

echo "td style='color:red' align='center' font size=4提交人 /font/td";

echo "td style='color:red' align='center' font size=4提交時間 /font /td";

echo "/tr";

................

?

PHP、html網(wǎng)頁設(shè)計,如圖,表格只能居中,我要居左,怎么改?代碼是寫好的(樣式文件?)

判斷不出來。 table設(shè)置的是width:100%; 就算float:left也沒用。 要看父級的容器是個什么樣式。 所以需要整個css代碼。

分享標題:php表格數(shù)據(jù)居中 php表格居中怎么設(shè)置
文章位置:http://www.muchs.cn/article46/hjegeg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、網(wǎng)站營銷、軟件開發(fā)、網(wǎng)站導(dǎo)航、網(wǎng)站內(nèi)鏈、定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)