Hello,
I’ve attached an Excel file that contains some gradients. If I use the following code, the resulting PowerPoint file has a different variant of the gradient.
var excelDocument = new Workbook(“Exl2010.xlsx”);
Color color1, color2;
int variant;
GradientStyleType gradientStyleType;
var cell = excelDocument.Worksheets[0].Cells[1, 1];
var style = cell.GetStyle();
style.GetTwoColorGradient(out color1, out color2, out gradientStyleType, out variant);
color1 = Color.FromArgb(255, color1);
color2 = Color.FromArgb(255, color2);
using (Presentation presentation = new Presentation())
{
ISlide slide = presentation.Slides[0];
ITable tbl = slide.Shapes.AddTable(0, 0, new double[] { 50 }, new double[] { 50 });
foreach (IRow row in tbl.Rows)
{
foreach (ICell pptCell in row)
{
switch (gradientStyleType)
{
case GradientStyleType.FromCorner:
pptCell.FillFormat.GradientFormat.GradientDirection = GradientDirection.FromCorner1;
break;
case GradientStyleType.FromCenter:
pptCell.FillFormat.GradientFormat.GradientDirection = GradientDirection.FromCenter;
break;
case GradientStyleType.Horizontal:
pptCell.FillFormat.GradientFormat.LinearGradientAngle = 90;
break;
case GradientStyleType.Vertical:
pptCell.FillFormat.GradientFormat.LinearGradientAngle = 0;
break;
case GradientStyleType.DiagonalDown:
pptCell.FillFormat.GradientFormat.LinearGradientAngle = 45;
break;
case GradientStyleType.DiagonalUp:
pptCell.FillFormat.GradientFormat.LinearGradientAngle = -45;
break;
}
pptCell.FillFormat.FillType = FillType.Gradient;
pptCell.FillFormat.GradientFormat.GradientShape = GradientShape.Linear;
pptCell.FillFormat.GradientFormat.GradientStops.Add((float)1.0, color1);
pptCell.FillFormat.GradientFormat.GradientStops.Add(0, color2);
}
presentation.Save(“c:\result.pptx”, SaveFormat.Pptx);
}
}
How can I set the variant so that the pptx gradient will match the xlsx?
Best regards,
George Radu
Software Developer
IBM Romania