2014-01-06 39 views
0

我正嘗試使用this OpenXml tutorial即時創建一個pptx文件。使用OpenXml無法在PowerPoint中訪問SlideMasterPart

我收到錯誤:

'System.Collections.Generic.IEnumerable' does not contain a definition for 'First' and no extension method 'First' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)

以下行:

var slideMasterPart = presentationPart.SlideMasterParts.First(); 

有沒有解決辦法?

+0

你是否缺少這個namspace DocumentFormat.OpenXml.Packaging? –

+0

不,我有那個。 OpenXml,打包和演示。 – Ste

+0

你是否缺少'使用System.Linq;'或對System.Xml.Linq的引用 –

回答

1

添加引用using System.Linq;

通過解釋,該First()方法是一個擴展方法,該方法位於System.Linq命名空間中,適用於從IEnumerable繼承的任何內容。有關更多信息,請參閱MSDN文檔Enumerable.First MethodSystem.Linq Namespace

+0

完美,謝謝。 – Ste

0

你需要把將要返回的類型名稱:

var slideMasterPart = presentationPart.SlideMasterParts.First<**NameOfType**>(); 

乾杯 -

+0

感謝您的答覆,但它根本不承認「第一」。 – Ste

+0

該錯誤意味着SlideMasterParts是一個通用IEnumerable(即對於某些T,IEnumerable )。通用IEnumerables確實有一個第一個方法。如果它不是一個通用的IEnumerable,那麼它是什麼類型? –

相關問題