我想將我的editShpID
轉換爲int,以便我可以獲取它的ID並將其添加到列表中。我試過Convert.ToInt32,但它不會轉換,我不知道我怎麼能做到另一種方式。無法將類型'int'隱式轉換爲'Microsoft.Office.Interop.PowerPoint.Shape'
我的代碼是休閒。
Microsoft.Office.Interop.PowerPoint.Shape editedShpID;
editedShpID = null;
foreach (Microsoft.Office.Interop.PowerPoint.Shape editedShape in slide.Shapes)
{
if (editedShape.HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue)
{
editedShp = editedShape;
var textFrame = editedShape.TextFrame;
if (textFrame.HasText == Microsoft.Office.Core.MsoTriState.msoTrue)
{
var textRange = textFrame.TextRange;
pps += editedShape.TextFrame.TextRange.Text;
foreach (char word in textRange)
{
l.Add(word);
Debug.WriteLine(word);
}
}
}
editedShpID = Convert.ToInt32(editedShape.Id);
editedShapesListID.Add(editedShpID);
}
'Microsoft.Office.Interop.PowerPoint.Shape editedShpID;' - 如果你希望它是一個'int'這是爲什麼了'Shape'?你可以不只是'editShapesListID.Add(Convert.ToInt32(editedShape.Id));'? –
'editedShpID = Convert.ToInt32(editedShape.Id);'這是給我的問題,我希望能夠使用形狀屬性,這就是爲什麼我把它聲明爲形狀 –
嗯,'Microsoft.Office。 Interop.PowerPoint.Shape'是一個Int64(long)(https://msdn.microsoft.com/en-us/library/microsoft.office.interop.powerpoint.shape.id(v=office.14).aspx)所以,你應該使用一個很長的,而不是一個int。如果嘗試轉換,並且它的Int32.MaxValue或小於Int32.MinValue,則會得到一個「OverflowException」(https://msdn.microsoft.com/en-us/library/d4haekc4(v = vs.110).aspx) – Magnetron