當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Spreadsheet_Excel_Writer::addformat方法代碼示例

本文整理匯總了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) {
//.........這裏部分代碼省略.........
開發者ID:qinlibingfeng,項目名稱:CallCenter,代碼行數:101,代碼來源:pub_func.php

示例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;
}
開發者ID:shiyake,項目名稱:php-ihome,代碼行數:43,代碼來源:cp_invitefriend.php

示例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;
}
開發者ID:shiyake,項目名稱:php-ihome,代碼行數:52,代碼來源:cp_invite2.php

示例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();
開發者ID:f476559604,項目名稱:xuanke,代碼行數:22,代碼來源:tt3.php


注:本文中的Spreadsheet_Excel_Writer::addformat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。