コード例 #1
0
ファイル: Cell.php プロジェクト: kaantunc/MYK-BOR
 /**
  * Write style
  */
 public function write()
 {
     if (!$this->style instanceof \PhpOffice\PhpWord\Style\Cell) {
         return;
     }
     $brdSz = $this->style->getBorderSize();
     $brdCol = $this->style->getBorderColor();
     $hasBorders = false;
     for ($i = 0; $i < 4; $i++) {
         if (!is_null($brdSz[$i])) {
             $hasBorders = true;
             break;
         }
     }
     // Border
     if ($hasBorders) {
         $mbWriter = new MarginBorder($this->xmlWriter);
         $mbWriter->setSizes($brdSz);
         $mbWriter->setColors($brdCol);
         $mbWriter->setAttributes(array('defaultColor' => CellStyle::DEFAULT_BORDER_COLOR));
         $this->xmlWriter->startElement('w:tcBorders');
         $mbWriter->write();
         $this->xmlWriter->endElement();
     }
     // Text direction
     if (!is_null($this->style->getTextDirection())) {
         $this->xmlWriter->startElement('w:textDirection');
         $this->xmlWriter->writeAttribute('w:val', $this->style->getTextDirection());
         $this->xmlWriter->endElement();
     }
     // Shading
     if (!is_null($this->style->getShading())) {
         $styleWriter = new Shading($this->xmlWriter, $this->style->getShading());
         $styleWriter->write();
     }
     // Alignment
     if (!is_null($this->style->getVAlign())) {
         $this->xmlWriter->startElement('w:vAlign');
         $this->xmlWriter->writeAttribute('w:val', $this->style->getVAlign());
         $this->xmlWriter->endElement();
     }
     // Colspan
     if (!is_null($this->style->getGridSpan())) {
         $this->xmlWriter->startElement('w:gridSpan');
         $this->xmlWriter->writeAttribute('w:val', $this->style->getGridSpan());
         $this->xmlWriter->endElement();
     }
     // Row span
     if (!is_null($this->style->getVMerge())) {
         $this->xmlWriter->startElement('w:vMerge');
         $this->xmlWriter->writeAttribute('w:val', $this->style->getVMerge());
         $this->xmlWriter->endElement();
     }
 }
コード例 #2
0
 /**
  * Write style.
  *
  * @return void
  */
 public function write()
 {
     $style = $this->getStyle();
     if (!$style instanceof SectionStyle) {
         return;
     }
     $xmlWriter = $this->getXmlWriter();
     // Break type
     $breakType = $style->getBreakType();
     $xmlWriter->writeElementIf(!is_null($breakType), 'w:type', 'w:val', $breakType);
     // Page size & orientation
     $xmlWriter->startElement('w:pgSz');
     $xmlWriter->writeAttribute('w:orient', $style->getOrientation());
     $xmlWriter->writeAttribute('w:w', $style->getPageSizeW());
     $xmlWriter->writeAttribute('w:h', $style->getPageSizeH());
     $xmlWriter->endElement();
     // w:pgSz
     // Margins
     $margins = array('w:top' => array('getMarginTop', SectionStyle::DEFAULT_MARGIN), 'w:right' => array('getMarginRight', SectionStyle::DEFAULT_MARGIN), 'w:bottom' => array('getMarginBottom', SectionStyle::DEFAULT_MARGIN), 'w:left' => array('getMarginLeft', SectionStyle::DEFAULT_MARGIN), 'w:header' => array('getHeaderHeight', SectionStyle::DEFAULT_HEADER_HEIGHT), 'w:footer' => array('getFooterHeight', SectionStyle::DEFAULT_FOOTER_HEIGHT), 'w:gutter' => array('getGutter', SectionStyle::DEFAULT_GUTTER));
     $xmlWriter->startElement('w:pgMar');
     foreach ($margins as $attribute => $value) {
         list($method, $default) = $value;
         $xmlWriter->writeAttribute($attribute, $this->convertTwip($style->{$method}(), $default));
     }
     $xmlWriter->endElement();
     // Borders
     if ($style->hasBorder()) {
         $xmlWriter->startElement('w:pgBorders');
         $xmlWriter->writeAttribute('w:offsetFrom', 'page');
         $styleWriter = new MarginBorder($xmlWriter);
         $styleWriter->setSizes($style->getBorderSize());
         $styleWriter->setColors($style->getBorderColor());
         $styleWriter->setAttributes(array('space' => '24'));
         $styleWriter->write();
         $xmlWriter->endElement();
     }
     // Columns
     $colsSpace = $style->getColsSpace();
     $xmlWriter->startElement('w:cols');
     $xmlWriter->writeAttribute('w:num', $style->getColsNum());
     $xmlWriter->writeAttribute('w:space', $this->convertTwip($colsSpace, SectionStyle::DEFAULT_COLUMN_SPACING));
     $xmlWriter->endElement();
     // Page numbering start
     $pageNum = $style->getPageNumberingStart();
     $xmlWriter->writeElementIf(!is_null($pageNum), 'w:pgNumType', 'w:start', $pageNum);
     // Line numbering
     $styleWriter = new LineNumbering($xmlWriter, $style->getLineNumbering());
     $styleWriter->write();
 }
コード例 #3
0
ファイル: Cell.php プロジェクト: hcvcastro/pxp
 /**
  * Write style
  */
 public function write()
 {
     $style = $this->getStyle();
     if (!$style instanceof CellStyle) {
         return;
     }
     $xmlWriter = $this->getXmlWriter();
     $xmlWriter->startElement('w:tcPr');
     // Width
     $xmlWriter->startElement('w:tcW');
     $xmlWriter->writeAttribute('w:w', $this->width);
     $xmlWriter->writeAttribute('w:type', 'dxa');
     $xmlWriter->endElement();
     // w:tcW
     // Text direction
     $textDir = $style->getTextDirection();
     $xmlWriter->writeElementIf(!is_null($textDir), 'w:textDirection', 'w:val', $textDir);
     // Vertical alignment
     $vAlign = $style->getVAlign();
     $xmlWriter->writeElementIf(!is_null($vAlign), 'w:vAlign', 'w:val', $vAlign);
     // Border
     if ($style->hasBorder()) {
         $xmlWriter->startElement('w:tcBorders');
         $styleWriter = new MarginBorder($xmlWriter);
         $styleWriter->setSizes($style->getBorderSize());
         $styleWriter->setColors($style->getBorderColor());
         $styleWriter->setAttributes(array('defaultColor' => CellStyle::DEFAULT_BORDER_COLOR));
         $styleWriter->write();
         $xmlWriter->endElement();
     }
     // Shading
     $shading = $style->getShading();
     if (!is_null($shading)) {
         $styleWriter = new Shading($xmlWriter, $shading);
         $styleWriter->write();
     }
     // Colspan & rowspan
     $gridSpan = $style->getGridSpan();
     $vMerge = $style->getVMerge();
     $xmlWriter->writeElementIf(!is_null($gridSpan), 'w:gridSpan', 'w:val', $gridSpan);
     $xmlWriter->writeElementIf(!is_null($vMerge), 'w:vMerge', 'w:val', $vMerge);
     $xmlWriter->endElement();
     // w:tcPr
 }
コード例 #4
0
ファイル: Table.php プロジェクト: brunodebarros/phpword
 /**
  * Write border.
  *
  * @param \PhpOffice\PhpWord\Shared\XMLWriter $xmlWriter
  * @param \PhpOffice\PhpWord\Style\Table $style
  * @return void
  */
 private function writeBorder(XMLWriter $xmlWriter, TableStyle $style)
 {
     if ($style->hasBorder()) {
         $xmlWriter->startElement('w:tblBorders');
         $styleWriter = new MarginBorder($xmlWriter);
         $styleWriter->setSizes($style->getBorderSize());
         $styleWriter->setColors($style->getBorderColor());
         $styleWriter->write();
         $xmlWriter->endElement();
         // w:tblBorders
     }
 }
コード例 #5
0
ファイル: Table.php プロジェクト: kaantunc/MYK-BOR
 /**
  * Write row style
  *
  * @param string $type
  */
 private function writeFirstRow(\PhpOffice\PhpWord\Style\Table $style, $type)
 {
     $this->xmlWriter->startElement('w:tblStylePr');
     $this->xmlWriter->writeAttribute('w:type', $type);
     $this->xmlWriter->startElement('w:tcPr');
     if (!is_null($style->getShading())) {
         $styleWriter = new Shading($this->xmlWriter, $style->getShading());
         $styleWriter->write();
     }
     // Borders
     $brdSz = $style->getBorderSize();
     $brdCol = $style->getBorderColor();
     $hasBorders = false;
     for ($i = 0; $i < 6; $i++) {
         if (!is_null($brdSz[$i])) {
             $hasBorders = true;
         }
     }
     if ($hasBorders) {
         $mbWriter = new MarginBorder($this->xmlWriter);
         $mbWriter->setSizes($brdSz);
         $mbWriter->setColors($brdCol);
         $this->xmlWriter->startElement('w:tcBorders');
         $mbWriter->write();
         $this->xmlWriter->endElement();
         // w:tcBorders
     }
     $this->xmlWriter->endElement();
     // w:tcPr
     $this->xmlWriter->endElement();
     // w:tblStylePr
 }
コード例 #6
0
ファイル: Paragraph.php プロジェクト: nhatlang19/elearningONL
    /**
     * Write full style.
     *
     * @return void
     */
    private function writeStyle()
    {
        $style = $this->getStyle();
        if (!$style instanceof ParagraphStyle) {
            return;
        }
        $xmlWriter = $this->getXmlWriter();
        $styles = $style->getStyleValues();

        if (!$this->withoutPPR) {
            $xmlWriter->startElement('w:pPr');
        }

        // Style name
        if ($this->isInline === true) {
            $xmlWriter->writeElementIf($styles['name'] !== null, 'w:pStyle', 'w:val', $styles['name']);
        }

        // Pagination
        $xmlWriter->writeElementIf($styles['pagination']['widowControl'] === false, 'w:widowControl', 'w:val', '0');
        $xmlWriter->writeElementIf($styles['pagination']['keepNext'] === true, 'w:keepNext', 'w:val', '1');
        $xmlWriter->writeElementIf($styles['pagination']['keepLines'] === true, 'w:keepLines', 'w:val', '1');
        $xmlWriter->writeElementIf($styles['pagination']['pageBreak'] === true, 'w:pageBreakBefore', 'w:val', '1');

        // Child style: alignment, indentation, spacing, and shading
        $this->writeChildStyle($xmlWriter, 'Alignment', $styles['alignment']);
        $this->writeChildStyle($xmlWriter, 'Indentation', $styles['indentation']);
        $this->writeChildStyle($xmlWriter, 'Spacing', $styles['spacing']);
        $this->writeChildStyle($xmlWriter, 'Shading', $styles['shading']);

        // Tabs
        $this->writeTabs($xmlWriter, $styles['tabs']);

        // Numbering
        $this->writeNumbering($xmlWriter, $styles['numbering']);

        // Border
        if ($style->hasBorder()) {
            $xmlWriter->startElement('w:pBdr');

            $styleWriter = new MarginBorder($xmlWriter);
            $styleWriter->setSizes($style->getBorderSize());
            $styleWriter->setColors($style->getBorderColor());
            $styleWriter->write();

            $xmlWriter->endElement();
        }

        if (!$this->withoutPPR) {
            $xmlWriter->endElement(); // w:pPr
        }
    }
コード例 #7
0
ファイル: Section.php プロジェクト: kaantunc/MYK-BOR
 /**
  * Write style
  */
 public function write()
 {
     if (!$this->style instanceof \PhpOffice\PhpWord\Style\Section) {
         return;
     }
     // Section break
     if (!is_null($this->style->getBreakType())) {
         $this->xmlWriter->startElement('w:type');
         $this->xmlWriter->writeAttribute('w:val', $this->style->getBreakType());
         $this->xmlWriter->endElement();
     }
     // Page size & orientation
     $this->xmlWriter->startElement('w:pgSz');
     $this->xmlWriter->writeAttribute('w:orient', $this->style->getOrientation());
     $this->xmlWriter->writeAttribute('w:w', $this->style->getPageSizeW());
     $this->xmlWriter->writeAttribute('w:h', $this->style->getPageSizeH());
     $this->xmlWriter->endElement();
     // w:pgSz
     // Margins
     $this->xmlWriter->startElement('w:pgMar');
     $this->xmlWriter->writeAttribute('w:top', $this->convertTwip($this->style->getMarginTop(), SectionStyle::DEFAULT_MARGIN));
     $this->xmlWriter->writeAttribute('w:right', $this->convertTwip($this->style->getMarginRight(), SectionStyle::DEFAULT_MARGIN));
     $this->xmlWriter->writeAttribute('w:bottom', $this->convertTwip($this->style->getMarginBottom(), SectionStyle::DEFAULT_MARGIN));
     $this->xmlWriter->writeAttribute('w:left', $this->convertTwip($this->style->getMarginLeft(), SectionStyle::DEFAULT_MARGIN));
     $this->xmlWriter->writeAttribute('w:header', $this->convertTwip($this->style->getHeaderHeight(), SectionStyle::DEFAULT_HEADER_HEIGHT));
     $this->xmlWriter->writeAttribute('w:footer', $this->convertTwip($this->style->getFooterHeight(), SectionStyle::DEFAULT_FOOTER_HEIGHT));
     $this->xmlWriter->writeAttribute('w:gutter', $this->convertTwip($this->style->getGutter(), SectionStyle::DEFAULT_GUTTER));
     $this->xmlWriter->endElement();
     // Borders
     $borders = $this->style->getBorderSize();
     $hasBorders = false;
     for ($i = 0; $i < 4; $i++) {
         if (!is_null($borders[$i])) {
             $hasBorders = true;
             break;
         }
     }
     if ($hasBorders) {
         $styleWriter = new MarginBorder($this->xmlWriter);
         $styleWriter->setSizes($borders);
         $styleWriter->setColors($this->style->getBorderColor());
         $styleWriter->setAttributes(array('space' => '24'));
         $this->xmlWriter->startElement('w:pgBorders');
         $this->xmlWriter->writeAttribute('w:offsetFrom', 'page');
         $styleWriter->write();
         $this->xmlWriter->endElement();
     }
     // Page numbering
     if (!is_null($this->style->getPageNumberingStart())) {
         $this->xmlWriter->startElement('w:pgNumType');
         $this->xmlWriter->writeAttribute('w:start', $this->style->getPageNumberingStart());
         $this->xmlWriter->endElement();
     }
     // Columns
     $this->xmlWriter->startElement('w:cols');
     $this->xmlWriter->writeAttribute('w:num', $this->style->getColsNum());
     $this->xmlWriter->writeAttribute('w:space', $this->convertTwip($this->style->getColsSpace(), SectionStyle::DEFAULT_COLUMN_SPACING));
     $this->xmlWriter->endElement();
     // Line numbering
     $styleWriter = new LineNumbering($this->xmlWriter, $this->style->getLineNumbering());
     $styleWriter->write();
 }