使用php語言來做表格,應(yīng)該怎么做-創(chuàng)新互聯(lián)

要使用純PHP創(chuàng)建或編輯Excel電子表格,我們將使用PHPExcel庫,它可以讀寫許多電子表格格式,包括xls,xlsx,ods和csv。在我們繼續(xù)之前,仔細(xì)檢查您的服務(wù)器上是否有PHP 5.2或更高版本以及安裝了以下PHP擴(kuò)展:php_zip,php_xml和php_gd2。

創(chuàng)新互聯(lián)公司堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都做網(wǎng)站、網(wǎng)站建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的泗縣網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

使用php語言來做表格,應(yīng)該怎么做

創(chuàng)建電子表格

創(chuàng)建電子表格是PHP應(yīng)用程序中最常見的用例之一,用于將數(shù)據(jù)導(dǎo)出到Excel電子表格。查看以下代碼,了解如何使用PHPExcel創(chuàng)建示例Excel電子表格:

// Include PHPExcel library and create its object
require('PHPExcel.php');
 
$phpExcel = new PHPExcel;
 
// Set default font to Arial
$phpExcel->getDefaultStyle()->getFont()->setName('Arial');
 
// Set default font size to 12
$phpExcel->getDefaultStyle()->getFont()->setSize(12);
 
// Set spreadsheet properties – title, creator and description
$phpExcel ->getProperties()->setTitle("Product list");
$phpExcel ->getProperties()->setCreator("Voja Janjic");
$phpExcel ->getProperties()->setDescription("PHP Excel spreadsheet testing.");
 
// Create the PHPExcel spreadsheet writer object
// We will create xlsx file (Excel 2007 and above)
$writer = PHPExcel_IOFactory::createWriter($phpExcel, "Excel2007");
 
// When creating the writer object, the first sheet is also created
// We will get the already created sheet
$sheet = $phpExcel ->getActiveSheet();
 
// Set sheet title
$sheet->setTitle('My product list');
 
// Create spreadsheet header
$sheet ->getCell('A1')->setValue('Product');
$sheet ->getCell('B1')->setValue('Quanity');
$sheet ->getCell('C1')->setValue('Price');
 
// Make the header text bold and larger
$sheet->getStyle('A1:D1')->getFont()->setBold(true)->setSize(14);
 
// Insert product data
 
 
// Autosize the columns
$sheet->getColumnDimension('A')->setAutoSize(true);
$sheet->getColumnDimension('B')->setAutoSize(true);
$sheet->getColumnDimension('C')->setAutoSize(true);
 
// Save the spreadsheet
$writer->save('products.xlsx');

如果要下載電子表格而不是將其保存到服務(wù)器,請執(zhí)行以下操作:

header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="file.xlsx"');
header('Cache-Control: max-age=0');
$writer->save('php://output');

以上就是php語言怎么做表格的詳細(xì)內(nèi)容,更多請關(guān)注創(chuàng)新互聯(lián)成都網(wǎng)站設(shè)計公司其它相關(guān)文章!

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

新聞名稱:使用php語言來做表格,應(yīng)該怎么做-創(chuàng)新互聯(lián)
鏈接分享:http://muchs.cn/article36/cspesg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計公司、搜索引擎優(yōu)化網(wǎng)站排名、App開發(fā)、定制網(wǎng)站、定制開發(fā)

廣告

聲明:本網(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)站托管運(yùn)營