0
如何根據數據長度在我的excel報告中使用PHPexcel調整列寬?....以及如何使excel中的所有數據居中?居中,並根據數據長度調整excel列
當前代碼:
<?php
if (!isset($_POST['send'])) { ?>
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<?php } else {
require_once 'C:\xampp\htdocs\test\Classes\PHPExcel\IOFactory.php';
$filename = 'file.xlsx';
$title = $_POST['title'];
mysql_connect("localhost","root","") or die ("cant connect!");
mysql_select_db("test") or die ("cant find database!");
$objReader = PHPExcel_IOFactory::createReader('Excel2007');
$objReader->setReadDataOnly(true);
$objPHPExcel = $objReader->load($filename);
$objWorksheet = $objPHPExcel->getActiveSheet();
$objWorksheet = $objPHPExcel->setActiveSheetIndex(0);
$result = mysql_query("SELECT * FROM score");
if(isset($_POST['send'])){
$headings = array(
'ID',
'NAME',
'SCORE 1',
'SCORE 2',
'OTHER QUALITIES',
'INTERVIEW',
'TOTAL',
'AIC',
'BATCHCODE',
);
$objPHPExcel->getActiveSheet()->fromArray($headings, null, 'A1');
$row = 2;
while($rows = mysql_fetch_row($result)){
$objPHPExcel->getActiveSheet()->fromArray($rows, null, 'A' . $row);
$row++;
}
}
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="'.$title.'.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output');
}
if (!isset($_POST['send'])) { ?>
<form id="form1" name="form1" method="post" action="" >
<input name="title" type="text" id="title" value="title" />
<input type="submit" name="send" value="send to excel" id="send" />
</form>
</body>
</html>
<?php }
我想是......列將根據存儲的數據長度自動調節...,使DATAS在中心。