我正在致力於建立一個基於所需核心程序的質量,安全或環境管理系統的客戶項目,有3個選項,因此有7個不同的組合。我編寫了一個代碼,查看他們需要的內容,然後將數據插入到其客戶端文檔表中,其中包括模板文檔的副本。代碼本身工作得很好,併成功地爲客戶端構建了一個文檔列表,並插入了模板文檔(MS Word)。編輯phpcopy後的工作文檔
我需要什麼幫助,我不知道這是可能的,是找到一種方法,一旦他們被複制整個編輯word文檔。
模板位於我的/templates
文件夾中,然後複製到/clientfolder
,我用來查詢,追加和複製的代碼如下所示,我知道這並不完美,我將盡快更新它,但它確實有效。
我需要的是內環路包括,編輯剛剛被放置在文檔,並插入公司名稱和公司標誌,這是舉行我的項目中的會話變量代碼。如果您在這裏查看此示例表(http://iso-drive.co.uk/public/templates_documents_list.php),您可以打開一個文檔文檔,它具有兩個文本區域---> [公司名稱] [徽標]。
所以基本上我需要編輯每個Word文檔,然後插入兩個$ _Sessopm [公司名稱]並在$ _SESSION [CompanyLogo的。
//Add Template Documentation
//step 1 identify which documentation set is required
$sql = "SELECT * FROM templates_documents WHERE scope = '".$values["msscope"]."'";
$rs = CustomQuery($sql);
$results = $rs;
while ($row = $results->fetch_assoc())
{
//Step 2 correctly name doc reference
if ($row["scope"] == '9001') $docref = $row["9001ref"];
elseif ($row["scope"] == '14001') $docref = $row["14001ref"];
elseif ($row["scope"] == '18001') $docref = $row["18001ref"];
elseif ($row["scope"] == '9001,14001') $docref = $row["914001ref"];
elseif ($row["scope"] == '9001,18001') $docref = $row["918001ref"];
elseif ($row["scope"] == '14001,18001') $docref = $row["1418001ref"];
elseif ($row["scope"] == '9001,14001,18001') $docref = $row["91418001ref"];
//Step 3 Decode Attachment Field
$fileArray = json_decode($row["attachment"],true);
//values from Attachment Array
$name1 = $fileArray["0"]["name"];
$usrName1 = $fileArray["0"]["usrName"];
$size1 = $fileArray["0"]["size"];
$type1 = $fileArray["0"]["type"];
$searchStr1 = $fileArray["0"]["searchStr"];
$name2 = $folder.'/'.$docref.'.docx';
$usrName2 = $docref.".docx";
$size2=$size1;
$type2=$type1;
$searchStr2 = $usrName2.",!:sStrEnd";
$attachment2 = '[{"name":"'.$folder.'\/'.$usrName2.'","usrName":"'.$usrName2.'","size":'.$size2.',"type":"'.$type2.'","searchStr":"'.$searchStr2.'"}]';
//Step 4 insert template documentation into main docs table
$sql2 = "INSERT INTO documents_doucments (companyfk, docref, doctype, doctitle, revision, issuedate, status, reasonforchange, attachment)
values('".$values["companypk"]."', '$docref', '$row[doctype]','$row[templatename]','0.1', now(),1, 'First Draft', '$attachment2')";CustomQuery($sql2);
//step 4 copy and rename attachment into main docs table
if ($fileArray){
$originalfile = $name1;
$newfile = $name2;
copy($name1, $name2);}
//step 5 insert duplicate records from 3 and 4 above into document history (child) table
//get docpk from master table
$sql3 = "SELECT * FROM documents_doucments where companyfk = '".$values["companypk"]."' and docref = '$docref' ";
$rs3 = CustomQuery($sql3);
$results3 = $rs3;
while ($row = $results3->fetch_assoc())
{
$documentpk = $row["documentpk"];
//insert
$sql4 = "INSERT INTO documents_documenthistory (documentfk, docref, doctype, doctitle, revision, issuedate, status, reasonforchange, attachment) values('$documentpk', '$docref', '$row[doctype]','$row[templatename]','0.1', now(),1, 'First Draft', '$attachment2')";CustomQuery($sql4);
} }
謝謝,PHPWord可以編輯現有文檔嗎?從我讀過的內容來看,它是用來在飛行中創建新的? – 2014-10-20 09:34:51
'$ template = $ phpWord-> loadTemplate('Template.docx');'?看起來很有希望。 – 2014-10-20 09:36:56