Преглед изворни кода

Charts finally working in Word 2013. Fixes to crashes and axis issue.

Patch provided by Source2702
master
MadBoy_cp пре 10 година
родитељ
комит
a9a5b65d0c
2 измењених фајлова са 37 додато и 12 уклоњено
  1. 35
    10
      DocX/Charts/Chart.cs
  2. 2
    2
      DocX/Properties/AssemblyInfo.cs

+ 35
- 10
DocX/Charts/Chart.cs Прегледај датотеку

get get
{ {
List<Series> series = new List<Series>(); List<Series> series = new List<Series>();
int indx = 1;
foreach (XElement element in ChartXml.Elements(XName.Get("ser", DocX.c.NamespaceName))) foreach (XElement element in ChartXml.Elements(XName.Get("ser", DocX.c.NamespaceName)))
{ {
element.Add(new XElement(XName.Get("idx", DocX.c.NamespaceName)), (indx++).ToString());
series.Add(new Series(element)); series.Add(new Series(element));
} }
return series; return series;
/// </summary> /// </summary>
public void AddSeries(Series series) public void AddSeries(Series series)
{ {
if (ChartXml.Elements(XName.Get("ser", DocX.c.NamespaceName)).Count() == MaxSeriesCount)
int serCount = ChartXml.Elements(XName.Get("ser", DocX.c.NamespaceName)).Count();
if (serCount == MaxSeriesCount)
throw new InvalidOperationException("Maximum series for this chart is" + MaxSeriesCount.ToString() + "and have exceeded!"); throw new InvalidOperationException("Maximum series for this chart is" + MaxSeriesCount.ToString() + "and have exceeded!");
// Sourceman 16.04.2015 - Every Series needs to have an order and index element for being processed by Word 2013
series.Xml.AddFirst(
new XElement(XName.Get("order", DocX.c.NamespaceName),
new XAttribute(XName.Get("val"), (serCount + 1).ToString())));
series.Xml.AddFirst(
new XElement(XName.Get("idx", DocX.c.NamespaceName),
new XAttribute(XName.Get("val"), (serCount + 1).ToString())));
ChartXml.Add(series.Xml); ChartXml.Add(series.Xml);
} }
if (Legend != null) if (Legend != null)
RemoveLegend(); RemoveLegend();
Legend = new ChartLegend(position, overlay); Legend = new ChartLegend(position, overlay);
ChartRootXml.Add(Legend.Xml);
//ChartRootXml.Add(Legend.Xml);
// Sourceman: seems to be necessary to keep track of the order of elements as defined in the schema (Word 2013)
ChartRootXml.Element(XName.Get("plotArea", DocX.c.NamespaceName)).AddAfterSelf(Legend.Xml);
} }
/// <summary> /// <summary>
XElement axIDvalXml = XElement.Parse(String.Format( XElement axIDvalXml = XElement.Parse(String.Format(
@"<c:axId val=""{0}"" xmlns:c=""http://schemas.openxmlformats.org/drawingml/2006/chart""/>", ValueAxis.Id)); @"<c:axId val=""{0}"" xmlns:c=""http://schemas.openxmlformats.org/drawingml/2006/chart""/>", ValueAxis.Id));
ChartXml.Add(axIDcatXml);
ChartXml.Add(axIDvalXml);
// Sourceman: seems to be necessary to keep track of the order of elements as defined in the schema (Word 2013)
var insertPoint = ChartXml.Element(XName.Get("gapWidth", DocX.c.NamespaceName));
if (insertPoint != null) {
insertPoint.AddAfterSelf(axIDvalXml);
insertPoint.AddAfterSelf(axIDcatXml);
} else {
ChartXml.Add(axIDcatXml);
ChartXml.Add(axIDvalXml);
}
plotAreaXml.Add(CategoryAxis.Xml); plotAreaXml.Add(CategoryAxis.Xml);
plotAreaXml.Add(ValueAxis.Xml); plotAreaXml.Add(ValueAxis.Xml);
} }
ChartRootXml = Xml.Root.Element(XName.Get("chart", DocX.c.NamespaceName)); ChartRootXml = Xml.Root.Element(XName.Get("chart", DocX.c.NamespaceName));
ChartRootXml.Add(plotAreaXml);
//ChartRootXml.Add(plotAreaXml);
ChartRootXml.Element(XName.Get("autoTitleDeleted", DocX.c.NamespaceName)).AddAfterSelf(plotAreaXml);
} }
/// <summary> /// <summary>
new XElement( new XElement(
XName.Get("srgbClr", DocX.a.NamespaceName), XName.Get("srgbClr", DocX.a.NamespaceName),
new XAttribute(XName.Get("val"), value.ToHex())))); new XAttribute(XName.Get("val"), value.ToHex()))));
Xml.Add(colorElement);
Xml.Element(XName.Get("tx", DocX.c.NamespaceName)).AddAfterSelf(colorElement);
} }
} }
XName.Get("tx", DocX.c.NamespaceName), XName.Get("tx", DocX.c.NamespaceName),
new XElement( new XElement(
XName.Get("strRef", DocX.c.NamespaceName), XName.Get("strRef", DocX.c.NamespaceName),
new XElement(XName.Get("f", DocX.c.NamespaceName), ""),
new XElement( new XElement(
XName.Get("strCache", DocX.c.NamespaceName), XName.Get("strCache", DocX.c.NamespaceName),
new XElement( new XElement(
new XElement(XName.Get("invertIfNegative", DocX.c.NamespaceName), "0"), new XElement(XName.Get("invertIfNegative", DocX.c.NamespaceName), "0"),
new XElement( new XElement(
XName.Get("cat", DocX.c.NamespaceName), XName.Get("cat", DocX.c.NamespaceName),
new XElement(XName.Get("strRef", DocX.c.NamespaceName), strCache)),
new XElement(XName.Get("strRef", DocX.c.NamespaceName),
new XElement(XName.Get("f", DocX.c.NamespaceName), ""),
strCache)),
new XElement( new XElement(
XName.Get("val", DocX.c.NamespaceName), XName.Get("val", DocX.c.NamespaceName),
new XElement(XName.Get("numRef", DocX.c.NamespaceName), numCache))
new XElement(XName.Get("numRef", DocX.c.NamespaceName),
new XElement(XName.Get("f", DocX.c.NamespaceName), ""),
numCache))
); );
} }
numCache.RemoveAll(); numCache.RemoveAll();
strCache.Add(ptCount); strCache.Add(ptCount);
numCache.Add(ptCount);
numCache.Add(formatCode); numCache.Add(formatCode);
numCache.Add(ptCount);
Int32 index = 0; Int32 index = 0;
XElement pt; XElement pt;
numCache.RemoveAll(); numCache.RemoveAll();
strCache.Add(ptCount); strCache.Add(ptCount);
numCache.Add(ptCount);
numCache.Add(formatCode); numCache.Add(formatCode);
numCache.Add(ptCount);
XElement pt; XElement pt;
for (int index = 0; index < categories.Count; index++) for (int index = 0; index < categories.Count; index++)

+ 2
- 2
DocX/Properties/AssemblyInfo.cs Прегледај датотеку

// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.17")]
[assembly: AssemblyFileVersion("1.0.0.17")]
[assembly: AssemblyVersion("1.0.0.18")]
[assembly: AssemblyFileVersion("1.0.0.18")]

Loading…
Откажи
Сачувај