2011-03-24 31 views
8

Estoy usando openXML y C# para generar una diapositiva de PowerPoint pero no puedo ver cómo cambiar/configurar el tamaño del texto y color. ¿Es esto posible y hay algún ejemplo ya que no puedo encontrar ninguno con googlear?Usando C# y Powerpoint OpenXML, ¿es posible cambiar el tamaño de fuente y el color del texto?

Estoy construyendo una tabla (similar a esto: http://blogs.msdn.com/b/brian_jones/archive/2009/08/13/adding-repeating-data-to-powerpoint.aspx) y quiero cambiar un número de cosas en cada celda (fontsize, color de fuente, color de fondo de la celda).

+2

@DustinDavis: ¿Cómo fue este comentario algo más que ruido inútil? Así no es como funciona SO, y debes saber mejor; esta no es tu primera vez aquí. –

+0

no estoy seguro de qué se trata todo esto de @DustinDavis, pero ¿estarías dispuesto a mirar el código VB.NET? Dijiste que estaba bien en http://stackoverflow.com/questions/3903142/is-it-possible-to-update-a-powerpoint-slide-with-new-data-in-c, pero nunca aceptó la respuesta allí , por lo que no estoy seguro si responder en VB.NET funciona para usted o no. –

+0

@Otaku - estoy feliz de ver el código de VB.net si tiene alguna muestra – leora

Respuesta

7

Sus comentarios indican que este formato es para una tabla dentro de una diapositiva de PowerPoint.

Supuestos
Estoy asumiendo que ya ha creado la tabla, filas de la tabla, celdas de tabla, y el texto de la pantalla.
También suponiendo que tiene todo funcionando y ahora desea agregar formato.

Si desea dar formato al texto ya las celdas, puede hacerlo utilizando la siguiente:

//Create the TableCell for the PowerPoint table you are building. 
A.TableCell tableCell3 = new A.TableCell(); 
A.TextBody textBody5 = new A.TextBody(); 
A.BodyProperties bodyProperties5 = new A.BodyProperties();//Created but not modified. 
A.ListStyle listStyle5 = new A.ListStyle();//Created but not modified. 
A.Paragraph paragraph5 = new A.Paragraph(); 

//First Word: "Hello" with Font-Size 60x and Font-Color Green. 
A.Run run1 = new A.Run(); 
A.RunProperties runProperties1 = new A.RunProperties() { Language = "en-US", FontSize = 6000, Dirty = false, SmartTagClean = false };//Set Font-Size to 60px. 
A.SolidFill solidFill1 = new A.SolidFill(); 
A.RgbColorModelHex rgbColorModelHex1 = new A.RgbColorModelHex() { Val = "00B050" };//Set Font-Color to Green (Hex "00B050"). 
solidFill1.Append(rgbColorModelHex1); 
runProperties1.Append(solidFill1); 
A.Text text1 = new A.Text(); 
text1.Text = "Hello"; 
run1.Append(runProperties1); 
run1.Append(text1); 

//Second Word: "World" with Font-Size 60x and Font-Color Blue. 
A.Run run2 = new A.Run(); 
A.RunProperties runProperties2 = new A.RunProperties() { Language = "en-US", FontSize = 6000, Dirty = false, SmartTagClean = false };//Set Font-Size to 60px. 
A.SolidFill solidFill2 = new A.SolidFill(); 
A.RgbColorModelHex rgbColorModelHex2 = new A.RgbColorModelHex() { Val = "0070C0" };//Set Font-Color to Blue (Hex "0070C0"). 
solidFill2.Append(rgbColorModelHex2); 
runProperties2.Append(solidFill2); 
A.Text text2 = new A.Text(); 
text2.Text = " World"; 
run2.Append(runProperties2); 
run2.Append(text2); 

//This element specifies the text run properties that are to be used if another run is inserted after the last run specified. 
//This effectively saves the run property state so that it can be applied when the user enters additional text. 
//If this element is omitted, then the application can determine which default properties to apply. 
//It is recommended that this element be specified at the end of the list of text runs within the paragraph so that an orderly list is maintained. 
// Source: http://msdn.microsoft.com/en-us/library/documentformat.openxml.drawing.endparagraphrunproperties.aspx 
//Set the default formatting for words entered after "Hello World" with Font-Size 60x and Font-Color Blue. 
A.EndParagraphRunProperties endParagraphRunProperties5 = new A.EndParagraphRunProperties() { Language = "en-US", FontSize = 6000, Dirty = false };//Set Font-Size to 60px. 
A.SolidFill solidFill3 = new A.SolidFill(); 
A.RgbColorModelHex rgbColorModelHex3 = new A.RgbColorModelHex() { Val = "0070C0" };//Set Font-Color to Blue (Hex "0070C0"). 
solidFill3.Append(rgbColorModelHex3); 
endParagraphRunProperties5.Append(solidFill3); 

paragraph5.Append(run1);//Append Run: "Hello". 
paragraph5.Append(run2);//Append Run: " World". 
paragraph5.Append(endParagraphRunProperties5);//Append formmatting for any text the user may enter after the words "Hello World". 
textBody5.Append(bodyProperties5);//Created but not modified. 
textBody5.Append(listStyle5);//Created but not modified. 
textBody5.Append(paragraph5);//Append Paragraph: "Hello World" 

//TableCell Properties. Set Background-Color to Red (Hex "FF0000"). 
A.TableCellProperties tableCellProperties3 = new A.TableCellProperties(); 
A.SolidFill solidFill4 = new A.SolidFill(); 
A.RgbColorModelHex rgbColorModelHex4 = new A.RgbColorModelHex() { Val = "FF0000" };//Red Background for Single TableCell. 
solidFill4.Append(rgbColorModelHex4); 
tableCellProperties3.Append(solidFill4);//Append Red Background. 

tableCell3.Append(textBody5); 
tableCell3.Append(tableCellProperties3); 

hice trampa y utilizamos el "Open XML SDK 2.0 Productivity Tool for Microsoft Office".
Simplemente creé un nuevo archivo de PowerPoint, agregué una tabla y edité la tercera celda.
Luego ejecuté la herramienta SDK y reflejé el código en "[] /ppt/presentation.xml".
Agregué comentarios al código reflejado para que pueda entenderlo mejor.

0

Una vez que tenga el objeto para la ejecución o el párrafo que desea manipular, puede agregar el estilo que desee a las propiedades de ejecución o párrafo.

4

Como señaló otro usuario, esto es posible en ML. Aquí es una solución que utiliza para resolver este problema:

// Assume we are adding a A.TableCell to A.TableRow... 
A.TableCell tc = new A.TableCell(
new A.TextBody(
new A.BodyProperties(), 
new A.Paragraph(new A.Run( 
// -> Add the RunProperties as additional Element to A.Run constructor: 
new A.RunProperties() { FontSize = 600 }, new A.Text("some text")))), 
new A.TableCellProperties()); 

// Now add the cell to a A.TableRow instance... 

Al crear una célula A.TableCell para anexar a la fila de un A.Table, he añadido un elemento RunProperty a la A.Run anidando el A. Texto para la celda, y lo instancia con el atributo FontSize establecido en consecuencia: { FontSize = 600 }.

Espero que ayude a alguien.

Cuestiones relacionadas