wordContrl word文件管理工具
阿新 • • 發佈:2019-01-03
wordContrl
介紹
word文件管理工具,具有建立word文件、編輯word文件、將word文件轉為文字等功能
軟體架構
軟體架構說明
安裝教程
- xxxx
- xxxx
- xxxx
下載地址:[email protected]:netbycom/wordContrl.git
使用說明
require("wordControl/wordControl.php"); 1、建立word文件 $wordControl = new wordControl(); //建立段落 $wordControl->createSection(function($wordSection){ $wordSection->align("center")->spacing(1); $wordSection->createText(function($wordText){ $wordText->text("word測試標題")->size(18)->font("華康標題宋W9(P)")->spacing(0); }); }); $wordControl->createSection(function($wordSection){ $wordSection->align("center")->spacing(1); $wordSection->createText(function($wordText){ $wordText->text("(2018年7月)")->size(16)->font('楷體')->color('#333333'); }); }); $wordControl->createSection(function($wordSection){ $wordSection->align("left"); $wordSection->createText(function($wordText){ $wordText->spacing(60)->text("大家好:"); }); }); //建立公共樣式 $this->wordStyle = new wordStyle(); $this->wordStyle->size(16)->font('仿宋_GB2312')->color('#ff0000')->spacing(16); //建立段落並定義為模板 $wordControl->createSection(function($wordSection){ $wordSection->align("left")->ind(2); $wordSection->createText(function($wordText){ $wordText->style($this->wordStyle)->text("測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容"); }); })->createTemplate('content'); //建立段落並定義為模板 $wordControl->createSection(function($wordSection){ $wordSection->align("left")->ind(2); $wordSection->createText(function($wordText){ $wordText->style($this->wordStyle)->color("#00ff00")->text("測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容"); }); })->createTemplate('content1'); //使用模板並設定內容 $wordControl->templateText('content','我是模板內容我是模板內容我是模板內容我是模板內容我是模板內容我是模板內容我是模板內容我是模板內容'); //使用模板並設定內容 $wordControl->templateText('content1','測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容測試內容'); $wordControl->createSection(function($wordSection){ $wordSection->align("left")->ind(2); $wordSection->createText(function($wordText){ $wordText->text("表格標題:")->font('黑體')->size(16)->spacing(0)->bold(); }); }); //建立表格 $wordControl->createTable(function($wordTable){ //設定表格邊框樣式 $wordTable->borders(function($wordTableBorders){ $wordTableBorders->get('left')->size('10')->color("ff0000"); $wordTableBorders->get('right')->size('10')->color("ff0000"); $wordTableBorders->get('top')->size('10')->color("00ff00"); $wordTableBorders->get('bottom')->size('10')->color("00ff00"); }); //建立表格行 $wordTable->createRow(function($wordTableRow){ //建立表格列 $wordTableRow->createCell(function($wordTableCell){ $wordTableCell->width(1000); $wordTableCell->createSection(function($wordSection){ $wordSection->createText(function($wordText){ $wordText->text("姓 名")->bold(); }); }); }); $wordTableRow->createCell(function($wordTableCell){ $wordTableCell->width(1000); $wordTableCell->createSection(function($wordSection){ $wordSection->createText(function($wordText){ $wordText->text("出生日期")->bold(); }); }); }); $wordTableRow->createCell(function($wordTableCell){ $wordTableCell->width(1000); $wordTableCell->createSection(function($wordSection){ $wordSection->createText(function($wordText){ $wordText->text("年 齡")->bold(); }); }); }); $wordTableRow->createCell(function($wordTableCell){ $wordTableCell->width(1000); $wordTableCell->createSection(function($wordSection){ $wordSection->createText(function($wordText){ $wordText->text("課 程")->bold(); }); }); }); $wordTableRow->createCell(function($wordTableCell){ $wordTableCell->width(1000); $wordTableCell->createSection(function($wordSection){ $wordSection->createText(function($wordText){ $wordText->text("得 分")->bold(); }); }); }); }); //建立表格行併為此行建立模板 $wordTable->createRow(function($wordTableRow){ $wordTableRow->createCell(function($wordTableCell){ $wordTableCell->width(1000); $wordTableCell->createSection(function($wordSection){ $wordSection->createText(function($wordText){ $wordText->text("學生1")->color("#ff0000"); }); }); }); $wordTableRow->createCell(function($wordTableCell){ $wordTableCell->width(1000); $wordTableCell->createSection(function($wordSection){ $wordSection->createText(function($wordText){ $wordText->text("2015-01-02"); })->align('center'); }); }); $wordTableRow->createCell(function($wordTableCell){ $wordTableCell->width(1000); $wordTableCell->createSection(function($wordSection){ $wordSection->createText(function($wordText){ $wordText->text("3"); }); }); }); $wordTableRow->createCell(function($wordTableCell){ $wordTableCell->width(1000); $wordTableCell->createSection(function($wordSection){ $wordSection->createText(function($wordText){ $wordText->text("語文")->bold()->underline(); }); }); }); $wordTableRow->createCell(function($wordTableCell){ $wordTableCell->width(1000); $wordTableCell->createSection(function($wordSection){ $wordSection->createText(function($wordText){ $wordText->text("100")->color("#00ff00"); }); }); }); })->createTemplate('row'); //使用表格行模板建立行 $wordTable->templateText('row',array('學生3','2015-01-05','3','數學','98')); $wordTable->templateText('row',array('學生4','2015-01-06','3','數學1','100')); $wordTable->templateText('row',array('學生5','2015-01-07','3','數學3','94')); }); //使用模板並設定內容 $wordControl->templateText('content1','內容結尾內容結尾內容結尾內容結尾內容結尾內容結尾內容結尾內容結尾內容結尾內容結尾內容結尾'); //生成表格並下載 $wordControl->createXML()->save("123.docx")->output(); 2、修改word文件 //解析word文件 $wordSections = $wordControl->load('./temp.docx')->parseWord(); //獲取所有段落物件列表 $wordSectionList = $wordSections->getWordSectionLists(); $wordSection = $wordSections->getWordSectionItem(0)['section']; //獲取指定的段落物件 $wordText = $wordSection->getTextsObj()[0]->text("新的文字內容"); //獲取段落物件下面的文字物件並設定新的內容 $wordSection->updateText($wordText); //修改段落物件下面的文字內容 $wordSection->replaceText('新聞坊','新聞觀察'); //替換段落物件下面的文字內容 $wordControl->createXML()->save("1234.docx")->output(); //生成修改後的文件並下載 3、解析word文件返回文字 //解析word文件 $wordSectionTexts = $wordControl->load('./temp.docx')->parseWord()->getWordSections();