2017-08-06 13 views
0

我正在開發一個Word加載項(VSTO)。將字符串轉換爲WdPaperSize對象 - Word VSTO

我有一個頁面大小值的XML文件中,就像這樣:

<entry name="Size">wdPaperA3</entry> 

我試圖讓這些價值和將它們放置在WdPaperSize對象,像這樣:

WdPaperSize val = this.getFromXML("Size"); 
foreach (Section i in doc.Sections) 
    { 
     i.PageSetup.PaperSize = val; 
    } 

但我得到這些錯誤:

Cannot implicitly convert type 'string' to 'Microsoft.Office.Interop.Word.WdPaperSize' 

'WdPaperSize' is a type, which is not valid in the given context 

如何將字符串轉換爲WdPaperSize對象?

回答

1

WdPaperSize是一個枚舉。試試:

i.PageSetup.PaperSize = (WdPaperSize) Enum.Parse(typeof(WdPaperSize), val); 
+0

謝謝!很棒。 – Rolland