php com word 设置字体和字号

// 打开word 编辑
        $file = 'C:/Users/Administrator/Desktop/11.doc';
        $word = new \com("word.application",null,CP_UTF8) or die("Unable to instantiate Word");
        $word->Visible = 0;
        $word->Documents->Open($file,true,false);
        
        $Paragraphs = $word->ActiveDocument->Paragraphs;
      
        for ($i = 1; $i <= $Paragraphs->Count; $i++) {
             $font = $Paragraphs->Item($i)->Range->Font;
            $font->Name='仿宋_GB2312';
            $font->Size=16;
        }

        $word->ActiveDocument->Save();
        $word->Quit();
        $word = null;

有的文档的字号可能是三号,小二等汉字形式,那么用此方法打印一下$font->Size即可换算成数字。

猜你喜欢

转载自blog.csdn.net/wang740209668/article/details/108601638