![](/img/trans.png)
[英]Get width of an Excel column in pixels instead of the default unit of measurement
[英]How to get dynamic width of column in StackedColumn chart
我正在一个项目中工作,我需要使用 Aspose.Slides 库处理 StackedColumn 图表。 对于图表的每一列,都有一个对应的计数器值,我需要像在此示例幻灯片中一样显示它。
基本上,每个标签都应与相应列宽度的中间对称显示。
有 5 列,标签像模板一样显示得很好。 但是,如果少于该数量,标签将显示为这样。
这是一段代码,负责为系列添加数据点并为每个数据点添加标签。
dataSeries.DataPoints.AddDataPointForBarSeries(itemValueCell);
dataSeries.Format.Fill.FillType = fillType;
dataSeries.Format.Fill.SolidFillColor.Color = fillColour;
dataSeries.ParentSeriesGroup.Overlap = 100;
dataSeries.ParentSeriesGroup.GapWidth = 75;
var counter = workbook.GetCell(index, rowIndex, 7, item.Counter);
dataSeries.DataPoints[index - 1].Label.ValueFromCell = itemNameCell;
slide.Shapes.AddAutoShape(ShapeType.Rectangle, startX + dataSeries.GapWidth / 4.0f + (index - 1) * dataSeries.GapWidth * 1.85f, startY, dataSeries.GapWidth / 2.0f, 20);
var label = ((AutoShape)slide.Shapes[slide.Shapes.Count() - 1]);
label.TextFrame.Text = counter.Value.ToString();
label.FillFormat.FillType = FillType.NoFill;
label.LineFormat.FillFormat.FillType = FillType.NoFill;
label.TextFrame.TextFrameFormat.CenterText = NullableBool.True;
label.TextFrame.TextFrameFormat.AutofitType = TextAutofitType.Normal;
label.TextFrame.Paragraphs[0].Portions[0].PortionFormat.FillFormat.FillType = FillType.Solid;
label.TextFrame.Paragraphs[0].Portions[0].PortionFormat.FillFormat.SolidFillColor.Color = Color.FromArgb(0, 173, 219);
我试图获取每个数据点的 ActualWidth 但只得到零值。 似乎该字段的值只会在整个图表(或者可能是整个 powerpoint 文件)呈现后才被设置。 有谁知道如何从代码中获取每列的动态宽度值(甚至在呈现之前)?
没关系。 我自己得到了答案。 在获得实际宽度之前调用它。
chart.validateChartLayout();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.