Selaa lähdekoodia

导出word 还没完成 可以存为html

visuddhinanda 4 vuotta sitten
vanhempi
sitoutus
909ce9d51f
1 muutettua tiedostoa jossa 26 lisäystä ja 10 poistoa
  1. 26 10
      app/article/export.php

+ 26 - 10
app/article/export.php

@@ -5,6 +5,7 @@ require_once '../public/function.php';
 
 
 // Creating the new document...
+/*
 $phpWord = new \PhpOffice\PhpWord\PhpWord();
 
 
@@ -13,28 +14,28 @@ $phpWord->addTitleStyle(1, array('size' => 16), array('numStyle' => 'hNum', 'num
 $phpWord->addTitleStyle(2, array('size' => 14), array('numStyle' => 'hNum', 'numLevel' => 1));
 $phpWord->addTitleStyle(3, array('size' => 12), array('numStyle' => 'hNum', 'numLevel' => 2));
 
-/* Note: any element you append to a document must reside inside of a Section. */
+# Note: any element you append to a document must reside inside of a Section. 
 
-// Adding an empty Section to the document...
+# Adding an empty Section to the document...
 $section = $phpWord->addSection();
 
 $section->addTitle('Article Title', 1);
 
-// Adding Text element to the Section having font styled by default...
+# Adding Text element to the Section having font styled by default...
 $section->addText(
     '"Learn from yesterday, live for today, hope for tomorrow. '
         . 'The important thing is not to stop questioning." '
         . '(Albert Einstein)'
 );
-
+*/
 /*
  * Note: it's possible to customize font style of the Text element you add in three ways:
  * - inline;
  * - using named font style (new font style object will be implicitly created);
  * - using explicitly created font style object.
  */
-
-// Adding Text element with font customized inline...
+/*
+# Adding Text element with font customized inline...
 $section->addText(
     '"Great achievement is usually born of great sacrifice, '
         . 'and is never the result of selfishness." '
@@ -52,7 +53,7 @@ $footnote->addTextBreak();
 $footnote->addText('And text break.');
 $textrun->addText('Trailing text.');
 
-// Adding Text element with font customized using named font style...
+# Adding Text element with font customized using named font style...
 $fontStyleName = 'oneUserDefinedStyle';
 $phpWord->addFontStyle(
     $fontStyleName,
@@ -65,19 +66,33 @@ $section->addText(
     $fontStyleName
 );
 
-// Adding Text element with font customized using explicitly created font style object...
+# Adding Text element with font customized using explicitly created font style object...
 $fontStyle = new \PhpOffice\PhpWord\Style\Font();
 $fontStyle->setBold(true);
 $fontStyle->setName('Tahoma');
 $fontStyle->setSize(13);
 $myTextElement = $section->addText('"Believe you can and you\'re halfway there." (Theodor Roosevelt)');
 $myTextElement->setFontStyle($fontStyle);
+*/
+
+$html = "<html><body>";
+$html .= $_POST["html"];
+$html .= "</body></html>";
+
+#load from html
+$uuid=UUID::v4();
+$source = _DIR_TMP_EXPORT.'/'.$uuid.'.html';
+file_put_contents($source,$html);
+//echo date('H:i:s'), " Reading contents from `{$source}`", EOL;
+$phpWord = \PhpOffice\PhpWord\IOFactory::load($source, 'HTML');
 
 // Saving the document as OOXML file...
 $objWriter = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
-$tmpFileName = _DIR_TMP_EXPORT.'/'.UUID::v4().'.docx';
+$tmpFileName = _DIR_TMP_EXPORT.'/'.$uuid.'.docx';
 $objWriter->save($tmpFileName);
 
+// Read contents
+
 //4.从浏览器下载
 ob_clean();
 ob_start();
@@ -97,4 +112,5 @@ while (!feof($fp) && $file_count < $file_size){
 fclose($fp);
 ob_end_flush();
 
-unlink($tmpFileName);
+//unlink($tmpFileName);
+//unlink($source);