찾다
php教程php手册php生成excel文件源代码

php生成excel文件源代码

Jun 13, 2016 am 10:07 AM
classexcelphp접두사지도 시간문서소스 코드생성하다~의

php生成excel文件源代码

php教程生成excel文件源代码

class excel{

    /**
     *头的excel文件(前缀的行)
     *
     *从excel复制的xml规格。
     *
     * @访问私有
     * @无功串
     */
    var $header = "
 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">";

    /**
     *页脚的excel文件(附加到行)
     *
     *从excel复制的xml规格。
     *
     * @访问私有
     * @无功串
     */
    var $footer = "";

    /**
     * document lines (rows in an array)
     *
     * @access private
     * @var array
     */
    var $lines = array ();

    /**
     工作表名称
     *
     *包含一个单一的工作表名称
     *
     * @访问私有
     * @无功串
     */
    var $worksheet_title = "table1";

    /**
  添加一个单行的文档字符串$
     *
     * @访问私有
     * @帕拉姆库马拉阵列一维阵列
     * @待办事项行创造应做减本-> addarray
     */
    function addrow ($array) {

        // initialize all cells for this row
        $cells = "";
       
        // foreach key -> write value into cells
        foreach ($array as $k => $v):
   
         // 加个字符串与数字的判断 避免生成的 excel 出现数字以字符串存储的警告
         if(is_numeric($v)) {
          // 防止首字母为 0 时生成 excel 后 0 丢失
          if(substr($v, 0, 1) == 0) {
           $cells .= "" . $v . "n";
          } else {
           $cells .= "" . $v . "n";
          }
         } else {
             $cells .= "" . $v . "n";
         }

        endforeach;

        // transform $cells content into one row
        $this->lines[] = "n" . $cells . "n";

    }

    /**
    *添加一个数组到文档
     *
     *这应该是唯一的方法需要生成一个excel
     *文件。
     *
     * @访问公开
     * @帕拉姆库马拉数组二维数组
     * @待办事项可以转移到__construct()稍后
     */
    function addarray ($array) {

        // run through the array and add them into rows
        foreach ($array as $k => $v):
            $this->addrow ($v);
        endforeach;

    }

    /**
    设置工作表名称
     *
     *检查的字符串不允许字符(: /?*),
     *削减它的最大31个字符,并设置标题。该死
     *为何未允许字符无处可寻?视窗
     *帮助没有帮助...
     *
     * @访问公开
     * @帕拉姆库马拉字符串$标题设计标题
     */
    function setworksheettitle ($title) {

        // strip out special chars first
        $title = preg_replace ("/[\|:|/|?|*|[|]]/", "", $title);

        // now cut it to the allowed length
        $title = substr ($title, 0, 31);

        // set title
        $this->worksheet_title = $title;

    }

   /**
     *生成excel文件
     *
     *最后生成的excel文件,并使用header()函数
     *提供给浏览器。
     *
     * @访问公开
     * @帕拉姆库马拉字符串$文件名名称的excel文件来生成(... xls)中
     */
    function generatexml ($filename) {

        // deliver header (as recommended in php manual)
        header("content-type: application/vnd.ms-excel; charset=utf-8");
        header("content-disposition: inline; filename="" . $filename . ".xls"");

        // print out document to the browser
        // need to use strips教程lashes for the damn ">"
        echo stripslashes ($this->header);
        echo "nworksheet_title . "">n

n";
        echo "n";
        echo implode ("n", $this->lines);
        echo "
nn";
        echo $this->footer;

    }

}

/**
 *  cakephp中使用方法
 *  注意 ** cakephp 配置文件 define('debug', 0);
 *
 *  vendor ('excel');
 *  $doc = array (
 *       0 => array ('中国', '中国人', '中国人民', '123456');
 *  );
 *  $xls = new excel;
 *  $xls->addarray ( $doc );
 *  $xls->generatexml ("mytest");
 */

/**
 *  非框架使用方法
 *
 *  require_once('excel.php');
 *  $doc = array (
 *       0 => array ('中国', '中国人', '中国人民', '123456');
 *  );
 *  $xls = new excel;
 *  $xls->addarray ( $doc );
 *  $xls->generatexml ("mytest");
 */

성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress

Undresser.AI Undress

사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover

AI Clothes Remover

사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool

Undress AI Tool

무료로 이미지를 벗다

Clothoff.io

Clothoff.io

AI 옷 제거제

Video Face Swap

Video Face Swap

완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

뜨거운 도구

ZendStudio 13.5.1 맥

ZendStudio 13.5.1 맥

강력한 PHP 통합 개발 환경

mPDF

mPDF

mPDF는 UTF-8로 인코딩된 HTML에서 PDF 파일을 생성할 수 있는 PHP 라이브러리입니다. 원저자인 Ian Back은 자신의 웹 사이트에서 "즉시" PDF 파일을 출력하고 다양한 언어를 처리하기 위해 mPDF를 작성했습니다. HTML2FPDF와 같은 원본 스크립트보다 유니코드 글꼴을 사용할 때 속도가 느리고 더 큰 파일을 생성하지만 CSS 스타일 등을 지원하고 많은 개선 사항이 있습니다. RTL(아랍어, 히브리어), CJK(중국어, 일본어, 한국어)를 포함한 거의 모든 언어를 지원합니다. 중첩된 블록 수준 요소(예: P, DIV)를 지원합니다.

Atom Editor Mac 버전 다운로드

Atom Editor Mac 버전 다운로드

가장 인기 있는 오픈 소스 편집기

VSCode Windows 64비트 다운로드

VSCode Windows 64비트 다운로드

Microsoft에서 출시한 강력한 무료 IDE 편집기

스튜디오 13.0.1 보내기

스튜디오 13.0.1 보내기

강력한 PHP 통합 개발 환경