简体   繁体   English

在EPPlus / Office Open Xml中设置图表间隙宽度

[英]Setting chart gap width in EPPlus / Office Open Xml

How can I set the Gap Width value on a column/bar chart in EPPlus? 如何在EPPlus的柱形图/条形图中设置间隙宽度值?

I have not found a built-in property for this and am expecting I will need to manipulate the chart's Xml, but I've been unable to find the Office Open Xml syntax for doing this. 我没有为此找到内置属性,并且希望我需要操纵图表的Xml,但是我无法找到用于执行此操作的Office Open Xml语法。

This is supported in EPPLus. EPPLus支持此功能。 For example: 例如:

var barChart = chart.PlotArea.ChartTypes[0] as ExcelBarChart;
barChart.GapWidth = 0;

I found the answer by creating what I wanted in a standard Excel sheet, and then looking at the underlying XML it had crated. 通过在标准Excel工作表中创建所需的内容,然后查看它创建的底层XML,我找到了答案。

I set the Gap Width on an existing chart using the Excel, saved the workbook, renamed the file extension to .zip, and found the corresponding chart XML file within the Zip. 我使用Excel在现有图表上设置了“间隙宽度”,保存了工作簿,将文件扩展名重命名为.zip,并在Zip中找到了相应的图表XML文件。

In this case I found the element <c:gapWidth val="15" /> at the following location in the chart's XML: c:chartSpace/c:chart/c:plotArea/c:barChart 在这种情况下,我在图表的XML的以下位置找到了元素<c:gapWidth val="15" />c:chartSpace/c:chart/c:plotArea/c:barChart

I highly recommend this method for solving similar OOXML syntax queries, as the documentation I've seen so far is very dense and not easy to navigate, whereas learning by example in this way helped me find the answer in seconds. 我强烈建议使用这种方法来解决类似的OOXML语法查询,因为到目前为止我看到的文档非常密集并且不易浏览,而通过示例学习以这种方式可以帮助我在几秒钟内找到答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM