开发者

Cannot implicitly convert type 'System.Drawing.Font' to 'Microsoft.Office.Interop.Word.Font'

开发者 https://www.devze.com 2023-03-31 11:16 出处:网络
my code : public class Fonts { Font Header = new System.Drawing.Font(\"Tahoma\", 10, FontStyle.Bold); ToWord ToWord = new ToWord(Header);

my code :

   public class Fonts
    {
    Font Header = new System.Drawing.Font("Tahoma", 10, FontStyle.Bold);

      ToWord ToWord = new ToWord(Header);
    }



public class ToWord
{
    public ToWord(开发者_如何学PythonSystem.Drawing.Font Header)
    {
    ......

    Paragraph pIndex = DocumnetWord.Paragraphs.Add(ref oMissing);

    pIndex.Range.Font =Header;//error compile....
    }

}

error :

Cannot implicitly convert type 'System.Drawing.Font' to 'Microsoft.Office.Interop.Word.Font'

What is the correct code?


I think you will need to use the Font class properties directly to assign the appropriate values:

pIndex.Range.Font.Bold = True;
pIndex.Range.Font.Color = Word.WdColor.wdColorBlack;
0

精彩评论

暂无评论...
验证码 换一张
取 消