我们在进行网页交互设计的时候,通常都会使用PHP中ge变量方法来获得fom表单中的数据,以此来实现各种网页动态查询或者请求。对于稍有HTML基础的朋友来说,应该都知道HTMLfom表单中有两种提交方式即ge和po......
以下是【金聪采编】分享的内容全文:
以下是【金聪采编】分享的内容全文:
要使用纯PHP创建或编辑Excel电子表格,我们将使用PHPExcel库,它可以读写许多电子表格格式,包括xls,xlsx,ods和csv。在我们继续之前,仔细检查您的服务器上是否有PHP 5.2或更高版本以及安装了以下PHP扩展:php_zip,php_xml和php_gd2。
创建电子表格
创建电子表格是PHP应用程序中最常见的用例之一,用于将数据导出到Excel电子表格。查看以下代码,了解如何使用PHPExcel创建示例Excel电子表格:
// Include PHPExcel library and create its objectrequire('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');
如果要下载电子表格而不是将其保存到服务器,请执行以下操作:
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中编辑电子表格与创建电子表格类似:
// Include PHPExcel library and create its objectrequire('PHPExcel.php');// Load an existing spreadsheet$phpExcel = PHPExcel_IOFactory::load('products.xlsx');// Get the first sheet$sheet = $phpExcel ->getActiveSheet();// Remove 2 rows starting from the row 2$sheet ->removeRow(2,2);// Insert one new row before row 2$sheet->insertNewRowBefore(2, 1);// Create the PHPExcel spreadsheet writer object// We will create xlsx file (Excel 2007 and above)$writer = PHPExcel_IOFactory::createWriter($phpExcel, "Excel2007");// Save the spreadsheet$writer->save('products.xlsx');
准备电子表格进行打印
要准备电子表格进行打印,我们将设置纸张方向,尺寸和边距:
$sheet->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE);$sheet -> getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4); $sheet->getPageMargins()->setTop(1);$sheet ->getPageMargins()->setRight(0.75);$sheet ->getPageMargins()->setLeft(0.75);$sheet ->getPageMargins()->setBottom(1);
将PHPExcel与Laravel一起使用
PHPExcel库也可以在Laravel框架中使用。查看以下PHP包(此处)并通过Composer安装它。完成安装步骤后,您可以使用以下代码将数据从数据库导出到Excel电子表格中:
Excel::create('Products', function($excel) { // Set the title $excel->setTitle('Product list'); // Set the creator $excel->setCreator('Voja Janjic'); // Set description $excel->setDescription('PHP Excel spreadsheet testing'); $excel->sheet('Products', function($sheet) { // Get data from the database $products = Product::all(); // Generate header row $sheet->row(1, array( 'ID', 'Product', 'Price', 'Quantity', )); // Generate data rows $i = 2; foreach($products as $product) { $sheet->row($i, array( $product->product_id, $product->product_name, $product->price, $variety->quantity, )); $i++; } });})->export('xlsx');
金聪线报提示:[ PHP通过get方法获得form表单数据方法总结 ] 仅为会员分享交流,仅供学习、参考使用,请勿用于其他用途,如果想商业使用或者代理,请自行联系版权方获取授权。任何未获取授权的商业使用与本站无关,请自行承担相应责任。
本站不存储任何资源文件,敬请周知!
本网站采用 BY-NC-SA 协议进行授权 转载请注明原文链接:PHP通过get方法获得form表单数据方法总结
本站不存储任何资源文件,敬请周知!
此资源仅供个人学习、研究使用,禁止非法转播或商业用途,请在获取后24小时内删除,如果你觉得满意,请寻求购买正版或获取授权!
免责申明:本站仅提供学习的平台,所有资料均来自于网络分享线索,版权归原创者所有!本站不提供任何保证,并不承担任何法律责任,如果对您的版权或者利益造成损害,请提供相应的资质证明,我们将于3个工作日内予以处理。版权申诉相关说明本网站采用 BY-NC-SA 协议进行授权 转载请注明原文链接:PHP通过get方法获得form表单数据方法总结