Slides Gradient different from Excel

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

Hi George,


I have checked the requirement shared by you and have worked with the sample code shared by you and request you to please try using the below code sample for setting the gradient style for the the first cell.

public static void TestPresGradient()
{
var excelDocument = new Aspose.Cells.Workbook(“Exl2010.xlsx”);
Color color1, color2;
int variant;
Aspose.Cells.Drawing.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,50,50,50,50,50 });
foreach (IRow row in tbl.Rows)
{
foreach (ICell pptCell in row)
{
switch (gradientStyleType)
{
case Aspose.Cells.Drawing.GradientStyleType.FromCorner:
pptCell.FillFormat.GradientFormat.GradientDirection = GradientDirection.FromCorner1;
break;

case Aspose.Cells.Drawing.GradientStyleType.FromCenter:
pptCell.FillFormat.GradientFormat.GradientDirection = GradientDirection.FromCenter;
break;

case Aspose.Cells.Drawing.GradientStyleType.Horizontal:
pptCell.FillFormat.GradientFormat.LinearGradientAngle = 270;
break;

case Aspose.Cells.Drawing.GradientStyleType.Vertical:
pptCell.FillFormat.GradientFormat.LinearGradientAngle = 0;
break;

case Aspose.Cells.Drawing.GradientStyleType.DiagonalDown:
pptCell.FillFormat.GradientFormat.LinearGradientAngle = 45;
break;

case Aspose.Cells.Drawing.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(“result.pptx”, SaveFormat.Pptx);
}
}

I hope this will be helpful.

Best Regards,

Hi Adnan,


Thank you for your response. The changes you provided only work for the first cell - [1,1].
If you change the cell, let’s say [6,1] you will see that the result is still different.
I see now that I haven’t mentioned, but the pptx gradient should match the xlsx gradient in all the cases present in the attached xlsx.

Best regards,
George Radu
Software Developer
IBM Romania

Hi George Radu,

I like to share that I am working over your issue and need some in its implementation. I will get back to you with a response ASAP in this regard.

Many Thanks,

Hi George Radu,

I have worked over your requirements and have created the sample code for generating the equivalent slide shapes gradient effects as shared in excel sheet. Please try using the following sample code on your end to serve the purpsoe. Please share, if I may help you further in this regard.

public static void TestPresGradient2()
{
using (Presentation p = new Presentation())
{
p.Slides[0].Shapes.Clear();
ITable tbl = p.Slides[0].Shapes.AddTable(10, 10, new double[] { 50 }, new double[] { 25, 25, 25, 25, 25, 25 });

tbl[0, 0].FillFormat.FillType = FillType.Gradient;
tbl[0, 0].FillFormat.GradientFormat.GradientShape = GradientShape.Linear;
tbl[0, 0].FillFormat.GradientFormat.GradientStops.Add(0f, Color.Blue);
tbl[0, 0].FillFormat.GradientFormat.GradientStops.Add(1f, Color.Yellow);
tbl[0, 0].FillFormat.GradientFormat.LinearGradientAngle = 90;

tbl[0, 1].FillFormat.FillType = FillType.Gradient;
tbl[0, 1].FillFormat.GradientFormat.GradientShape = GradientShape.Linear;
tbl[0, 1].FillFormat.GradientFormat.GradientStops.Add(0f, Color.Blue);
tbl[0, 1].FillFormat.GradientFormat.GradientStops.Add(0.5f, Color.Yellow);
tbl[0, 1].FillFormat.GradientFormat.GradientStops.Add(1.2f, Color.Blue);

tbl[0, 2].FillFormat.FillType = FillType.Gradient;
tbl[0, 2].FillFormat.GradientFormat.GradientShape = GradientShape.Linear;
tbl[0, 2].FillFormat.GradientFormat.GradientStops.Add(0f, Color.Blue);
tbl[0, 2].FillFormat.GradientFormat.GradientStops.Add(1f, Color.Yellow);
tbl[0, 2].FillFormat.GradientFormat.LinearGradientAngle = 45;

tbl[0, 3].FillFormat.FillType = FillType.Gradient;
tbl[0, 3].FillFormat.GradientFormat.GradientShape = GradientShape.Linear;
tbl[0, 3].FillFormat.GradientFormat.GradientStops.Add(0f, Color.Blue);
tbl[0, 3].FillFormat.GradientFormat.GradientStops.Add(1f, Color.Yellow);
tbl[0, 3].FillFormat.GradientFormat.LinearGradientAngle = 135;

tbl[0, 4].FillFormat.FillType = FillType.Gradient;
tbl[0, 4].FillFormat.GradientFormat.GradientShape = GradientShape.Rectangle;
tbl[0, 4].FillFormat.GradientFormat.GradientDirection = GradientDirection.FromCorner2;
tbl[0, 4].FillFormat.GradientFormat.GradientStops.Add(0f, Color.Blue);
tbl[0, 4].FillFormat.GradientFormat.GradientStops.Add(1f, Color.Yellow);

tbl[0, 5].FillFormat.FillType = FillType.Gradient;
tbl[0, 5].FillFormat.GradientFormat.GradientShape = GradientShape.Rectangle;
tbl[0, 5].FillFormat.GradientFormat.GradientDirection = GradientDirection.FromCenter;
tbl[0, 5].FillFormat.GradientFormat.GradientStops.Add(0f, Color.Yellow);
tbl[0, 5].FillFormat.GradientFormat.GradientStops.Add(1f, Color.Blue);

p.Save(“D:\Aspose Data\gradient.pptx”, SaveFormat.Pptx);
}
}

Many Thanks,