本文整理汇总了PHP中Spreadsheet_Excel_Writer::addformat方法的典型用法代码示例。如果您正苦于以下问题:PHP Spreadsheet_Excel_Writer::addformat方法的具体用法?PHP Spreadsheet_Excel_Writer::addformat怎么用?PHP Spreadsheet_Excel_Writer::addformat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Spreadsheet_Excel_Writer
的用法示例。
在下文中一共展示了Spreadsheet_Excel_Writer::addformat方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save_detail_excel
function save_detail_excel($sql, $file_name, $file_type = "xls")
{
global $db_conn;
if ($sql != "") {
set_time_limit(0);
ini_set('memory_limit', '600M');
$rows = mysqli_query($db_conn, $sql);
$row_counts_list = mysqli_num_rows($rows);
$field_count = mysqli_num_fields($rows);
$fields = mysqli_fetch_fields($rows);
if ($row_counts_list != 0) {
//文档类型
if ($file_type == "xls") {
//记录集个数小于2000,使用phpexcel生成xls
/*if ($row_counts_list<2000 and $field_count<12) {
include("../plugin/excel.php");
//当前活动表
$objPHPExcel->setActiveSheetIndex(0);
//sheet表名
$objPHPExcel->getActiveSheet()->setTitle("".$file_name."");
$field_count2=$field_count-1;
$objPHPExcel->getActiveSheet()->setSharedStyle($excel_tit_left, "A1:$tit_arr[$field_count2]1");
$objPHPExcel->getActiveSheet()->setSharedStyle($excel_list_left, "A2:$tit_arr[$field_count2]".($row_counts_list+1));
for ($i=0;$i<$field_count;$i++){
$objPHPExcel->getActiveSheet()->setCellValue("$tit_arr[$i]1","".$fields[$i]->name."");
}
$i=1;
while($rs= mysqli_fetch_array($rows)){
$i+=1;
for ($k=0;$k<$field_count;$k++){
$objPHPExcel->getActiveSheet()->getCell($tit_arr[$k].$i)->setValueExplicit($rs[$k], PHPExcel_Cell_DataType::TYPE_STRING);
}
//if($i%100==0){
// ob_flush();
// flush();
//}
}
$objPHPExcel->setActiveSheetIndex(0);
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$file_path=excel_file("".$file_name."_","xls");
$objWriter->save(str_replace('.php', '.xls',$file_path[2]));
}else{*/
//记录集个数大于2000,使用XML生成xls
include "Spreadsheet/Excel/Writer.php";
$file_path = excel_file("" . $file_name . "_", "xls");
$workbook = new Spreadsheet_Excel_Writer($file_path[2]);
$workbook->setCustomColor(20, 146, 208, 80);
$format_title_sty =& $workbook->addformat(array('Size' => 10, 'Bold' => 1, 'Border' => 1, 'FgColor' => 20, 'FontFamily' => utf82gb("宋体")));
$format_cont_sty =& $workbook->addformat(array('Size' => 10, 'Border' => 1, 'FontFamily' => utf82gb("宋体")));
$sheet_rows = 40000;
//单Sheet记录集个数
$sheet_id = 0;
$i = 0;
$sheet_i = 0;
while ($rs = mysqli_fetch_array($rows)) {
$i++;
$sheet_i++;
$row_ = $i % $sheet_rows;
if ($row_ == 1) {
if ($row_counts_list < $sheet_rows + 1) {
$sheet_id = "";
} else {
$sheet_id++;
}
$sheets =& $workbook->addWorksheet("" . utf82gb($file_name . $sheet_id) . "");
for ($f = 0; $f < $field_count; $f++) {
$sheets->writeString(0, $f, utf82gb($fields[$f]->name), $format_title_sty);
}
$sheet_i = 1;
}
for ($k = 0; $k < $field_count; $k++) {
$sheets->writeString($sheet_i, $k, utf82gb($rs[$k]), $format_cont_sty);
}
}
$workbook->close();
//}
} elseif ($file_type == "xml_xls") {
$file_type = "xls";
$file_path = excel_file("" . $file_name . "_", $file_type);
$fp = fopen($file_path[2], "w");
$sheet_rows = 40000;
//单Sheet记录集个数
$xml_head = "<?xml version=\"1.0\"?>\n<?mso-application progid=\"Excel.Sheet\"?>\n<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:html=\"http://www.w3.org/TR/REC-html40\"><DocumentProperties xmlns=\"urn:schemas-microsoft-com:office:office\"><Title>详单数据导出</Title><Author>亚铭科技</Author><Category>详单、汇总</Category>\n<Company>亚铭科技</Company></DocumentProperties>\n<OfficeDocumentSettings xmlns=\"urn:schemas-microsoft-com:office:office\"><AllowPNG/> <RemovePersonalInformation/></OfficeDocumentSettings><ExcelWorkbook xmlns=\"urn:schemas-microsoft-com:office:excel\"> <WindowHeight>8010</WindowHeight><WindowWidth>14805</WindowWidth><WindowTopX>240</WindowTopX><WindowTopY>105</WindowTopY>\n<ProtectStructure>False</ProtectStructure><ProtectWindows>False</ProtectWindows></ExcelWorkbook>\n<Styles>\n<Style ss:ID=\"Default\" ss:Name=\"Normal\"><Alignment ss:Vertical=\"Bottom\"/><Borders/><Font ss:FontName=\"宋体\" x:CharSet=\"134\" ss:Size=\"10\" ss:Color=\"#000000\"/><Interior/><NumberFormat/><Protection/></Style><Style ss:ID=\"s71\"><Alignment ss:Vertical=\"Center\"/><Borders><Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/><Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/><Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/><Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/></Borders><Font ss:FontName=\"宋体\" x:CharSet=\"134\" ss:Color=\"#000000\"/><NumberFormat ss:Format=\"@\"/></Style><Style ss:ID=\"s72\"><Alignment ss:Vertical=\"Center\"/><Borders>\n<Border ss:Position=\"Bottom\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/><Border ss:Position=\"Left\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/>\n <Border ss:Position=\"Right\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/><Border ss:Position=\"Top\" ss:LineStyle=\"Continuous\" ss:Weight=\"1\"/></Borders><Font ss:FontName=\"宋体\" x:CharSet=\"134\" ss:Color=\"#000000\" ss:Bold=\"1\"/> <Interior ss:Color=\"#92D050\" ss:Pattern=\"Solid\"/><NumberFormat ss:Format=\"@\"/></Style></Styles>";
fwrite($fp, $xml_head);
for ($i = 0; $i < $field_count; $i++) {
$filed_list .= "<Cell ss:StyleID=\"s72\"><Data ss:Type=\"String\">" . $fields[$i]->name . "</Data></Cell>";
}
$xml_sheet_head_row = "<Row>" . ($filed_list .= "</Row>");
$i = 0;
$sheet_id = 0;
while ($rs = mysqli_fetch_array($rows)) {
$i++;
$style = "";
$f_list = "";
$row_ = $i % $sheet_rows;
if ($row_ == 1) {
//.........这里部分代码省略.........
示例2: process_file
function process_file($filename, &$tempname)
{
global $_SGLOBAL;
$isfile = 1;
$data = new Spreadsheet_Excel_Reader();
$data->setOutputEncoding('UTF-8');
$data->read($filename);
$tempname = $_SGLOBAL['timestamp'] . '_download_' . rand() . '.xls';
$filedownload = S_ROOT . './plugin/invite/download/' . $tempname;
//初始化一个反馈结果的文件
require_once S_ROOT . './plugin/invite/phpwritexcel/Writer.php';
$workbook = new Spreadsheet_Excel_Writer($filedownload);
$worksheet =& $workbook->addWorksheet('Sheet1');
$worksheet->setInputEncoding('UTF-8');
$format_column =& $workbook->addformat(array('Size' => 9, 'Bold' => 1));
//读取结果文件的信息
$rows = 0;
$recordindex = array('realname', 'sex', 'birthday', 'otheremail', 'academy', 'startyear', 'collegeid', 'class', 'mobile', 'unit');
$record = array('好友姓名(必填)', '好友性别', '生日(8位)', '邮箱(必填)', '学院', '入学年份', '学号', '班别', '手机(必填)', '所在单位', '备注');
$dataindexinfo = array();
encode_record(&$record);
input_downloadfile($worksheet, $rows, $record, $format_column);
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
$datainfo = array();
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
$datainfo[$j - 1] = $data->sheets[0]['cells'][$i][$j];
$dataindexinfo[$recordindex[$j - 1]] = $data->sheets[0]['cells'][$i][$j];
}
$nopass = checkinfo($datainfo[0], $datainfo[3], $datainfo[8]);
if (!empty($nopass)) {
$datainfo[$j - 1] = $nopass;
encode_record(&$datainfo);
input_downloadfile($worksheet, &$rows, $datainfo, $format_column);
continue;
}
$dataindexinfo[inviter] = $_SGLOBAL[supe_uid];
$dataindexinfo[usertype] = '6';
inserttable('baseprofile', $dataindexinfo, 1);
invite_alumni($datainfo);
}
$workbook->close();
return $rows;
}
示例3: process_file
function process_file($filename, &$tempname)
{
global $_SGLOBAL;
$isfile = 1;
$data = new Spreadsheet_Excel_Reader();
//exit('adsf');
$data->setOutputEncoding('gbk');
$data->read($filename);
$tempname = date("Y-m-d") . '_download_' . rand() . '.xls';
$filedownload = S_ROOT . './plugin/invite/download/' . $tempname;
//初始化一个反馈结果的文件
require_once S_ROOT . './plugin/invite/phpwritexcel/Writer.php';
$workbook = new Spreadsheet_Excel_Writer($filedownload);
$worksheet =& $workbook->addWorksheet('Sheet1');
$worksheet->setInputEncoding('utf-8');
$format_column =& $workbook->addformat(array('Size' => 9, 'Bold' => 1));
//读取结果文件的信息
$rows = 0;
$recordindex = array('realname', 'sex', 'birthday', 'otheremail', 'academy', 'collegeid', 'class', 'mobile', 'unit');
$record = array('好友姓名(必填)', '好友性别', '生日(8位)', '邮箱(必填)', '学院', '学号', '班别', '手机(必填)', '所在单位', '备注');
$dataindexinfo = array();
encode_record(&$record);
input_downloadfile($worksheet, $rows, $record, $format_column);
for ($i = 2; $i <= $data->sheets[0]['numRows']; $i++) {
//以下注释的for循环打印excel表数据
$datainfo = array();
//$datainfo = array('name', 'sex', 'birthday', 'otheremail', 'academy', 'collegeid', 'class', 'mobile', 'unit');
for ($j = 1; $j <= $data->sheets[0]['numCols']; $j++) {
$datainfo[$j - 1] = $data->sheets[0]['cells'][$i][$j];
$dataindexinfo[$recordindex[$j - 1]] = $data->sheets[0]['cells'][$i][$j];
}
//var_dump($datainfo[0]);
//检查记录的正确性
$nopass = checkinfo($datainfo[0], $datainfo[2], $datainfo[3], $datainfo[7], $isfile);
if (!empty($nopass)) {
//没有通过的记录加入到一个新文件中
$datainfo[$j - 1] = $nopass;
encode_record(&$datainfo);
//var_dump($datainfo);
//var_dump($rows);
input_downloadfile($worksheet, &$rows, $datainfo, $format_column);
continue;
}
//邀请处理
//var_dump($dataindexinfo);
inserttable('baseprofile', $dataindexinfo, 1);
//var_dump($datainfo);
invite_alumni($datainfo);
}
$workbook->close();
return $rows;
}
示例4:
<?php
//加载类
require_once 'Spreadsheet/Excel/Writer.php';
//初始化类
$workbook = new Spreadsheet_Excel_Writer();
//设置版本
$workbook->setVersion(8);
//设置字体
$format_title =& $workbook->addformat(array('Size' => 10, 'Bold' => 1, 'Color' => 'red'));
//添加一个工作表
$worksheet =& $workbook->addWorksheet('sheet-1');
//设置列宽
$worksheet->setColumn(0, 19, 13);
//冻结行列
$worksheet->freezePanes(array(3, 5));
//追加数据
$worksheet->writeString(0, 0, '対象社員一覧(一次評価)', $format_title);
// 发送 Excel 文件名供下载
$workbook->send('demo.xls');
// 完成下载
$workbook->close();