2012-04-05 7 views
2

나는 C# 코드를 사용하여 PPT의 테이블 셀의 배경색을 변경하는 코드 조각 아래에 쓴하지만 아무것도 발생하지 않습니다 :C# 코드를 사용하여 ppt의 표 셀의 배경색을 변경하는 방법은 무엇입니까?

예상, 누군가가 나를 도울 수대로 작동하지 않는 코드의 조각 위
//creating powerpoint aaplication 
PowerPoint.Application pptApp = new PowerPoint.Application(); 
pptApp.Visible = Office.MsoTriState.msoTrue; 
var pptPresent = pptApp.Presentations; 
var fileOpen = pptPresent.Open(@file, Office.MsoTriState.msoFalse, Office.MsoTriState.msoTrue, Office.MsoTriState.msoTrue); 
// getting first slide 
PowerPoint.Slide objSlide = fileOpen.Slides[1]; 
PowerPoint.Shapes item = objSlide.Shapes; 
// getting first shape 
var shape1 = item[1]; 
// check if shape is table 
if (shape1.HasTable == Office.MsoTriState.msoTrue) 
{ 
    // change the table cell to red color 
    shape1.Table.Cell(2, 5).Shape.Fill.BackColor.RGB = System.Drawing.Color.Red.ToArgb(); 
    // make it visible 
    shape1.Fill.Visible = Office.MsoTriState.msoTrue; 
} 
// saving the ppt 
fileOpen.SaveAs(openFolder + subStr + ".pptx",PowerPoint.PpSaveAsFileType.ppSaveAsDefault,Office.MsoTriState.msoTrue); 
// close the ppt 
fileOpen.Close(); 

?

답변

1

셀 색을 변경하려면 ForeColor를 BackColor 대신 사용해야합니다. 그리기 색상이 예상대로 작동하지 않을 수 있습니다. 그것을 변경하려면 ColorTranslator를 사용하십시오.

shape1.Table.Cell(2, 5).Shape.Fill.ForeColor.RGB = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red); 
관련 문제