C# 在OpenXML条形图上添加自定义文本

C# 在OpenXML条形图上添加自定义文本,c#,bar-chart,openxml,C#,Bar Chart,Openxml,我想在条形图上添加如下自定义文本: 如何使用OpenXML实现这一点哪一个功能 请帮助这可以通过在不属于图表的形状上添加文本来实现。可以通过定位电子表格行来放置它。以下是示例代码: string[] strGenerator = new string[] { "2213969", "2213963", "2213979", "2213969", "2213963", &q

我想在条形图上添加如下自定义文本:

如何使用OpenXML实现这一点哪一个功能


请帮助

这可以通过在不属于图表的形状上添加文本来实现。可以通过定位电子表格行来放置它。以下是示例代码:

            string[] strGenerator = new string[] { "2213969", "2213963", "2213979", "2213969", "2213963", "2213979" };
            string[] strRowId = new string[] { "22", "20", "18","18","20","22" };
            string[] strColumnId = new string[] { "1", "1", "1", "10", "10", "10" };
            string[] strRowOffset = new string[] { "18000", "27000", "27000", "50000", "50000", "50000" }; //{ "80000", "186266", "95036", "81643", "27214", "136071" };
            string[] strColumnOffset = new string[] { "489858", "508606", "520699", "497453", "497453", "497453" }; //{ "489858", "508606", "520699", "197453", "182032", "163285" };

            for (i = 0; i < 6; i++)
            {
                Xdr.OneCellAnchor oneCellAnchor6 = new Xdr.OneCellAnchor();

                Xdr.FromMarker fromMarker8 = new Xdr.FromMarker();
                Xdr.ColumnId columnId10 = new Xdr.ColumnId();
                columnId10.Text = strColumnId[i]; // "1";
                Xdr.ColumnOffset columnOffset10 = new Xdr.ColumnOffset();
                columnOffset10.Text = strColumnOffset[i]; // "520699"
                Xdr.RowId rowId10 = new Xdr.RowId();
                rowId10.Text = strRowId[i]; //"16";
                Xdr.RowOffset rowOffset10 = new Xdr.RowOffset();
                rowOffset10.Text = strRowOffset[i];//"95036"; // Convert.ToString(95036*(i+1));// "95036";

                fromMarker8.Append(columnId10);
                fromMarker8.Append(columnOffset10);
                fromMarker8.Append(rowId10);
                fromMarker8.Append(rowOffset10);
                //Xdr.Extent extent6 = new Xdr.Extent() { Cx = 1782535L, Cy = 204108L };

                Xdr.Extent extent6 = new Xdr.Extent() { Cx = 1782535L, Cy = 204108L };

                Xdr.Shape shape6 = new Xdr.Shape() { Macro = "", TextLink = "" };

                Xdr.NonVisualShapeProperties nonVisualShapeProperties6 = new Xdr.NonVisualShapeProperties();

                Xdr.NonVisualDrawingProperties nonVisualDrawingProperties8 = new Xdr.NonVisualDrawingProperties() { Id = (UInt32Value)21U, Name = "TextBox 20" };

                A.NonVisualDrawingPropertiesExtensionList nonVisualDrawingPropertiesExtensionList8 = new A.NonVisualDrawingPropertiesExtensionList();

                A.NonVisualDrawingPropertiesExtension nonVisualDrawingPropertiesExtension8 = new A.NonVisualDrawingPropertiesExtension() { Uri = "{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}" };

                OpenXmlUnknownElement openXmlUnknownElement9 = OpenXmlUnknownElement.CreateOpenXmlUnknownElement("<a16:creationId xmlns:a16=\"http://schemas.microsoft.com/office/drawing/2014/main\" id=\"{6230E3EC-6B4D-47AE-A392-192F8AB4F7CE}\" />");

                nonVisualDrawingPropertiesExtension8.Append(openXmlUnknownElement9);

                nonVisualDrawingPropertiesExtensionList8.Append(nonVisualDrawingPropertiesExtension8);

                nonVisualDrawingProperties8.Append(nonVisualDrawingPropertiesExtensionList8);
                Xdr.NonVisualShapeDrawingProperties nonVisualShapeDrawingProperties6 = new Xdr.NonVisualShapeDrawingProperties() { TextBox = true };

                nonVisualShapeProperties6.Append(nonVisualDrawingProperties8);
                nonVisualShapeProperties6.Append(nonVisualShapeDrawingProperties6);

                Xdr.ShapeProperties shapeProperties6 = new Xdr.ShapeProperties();

                A.Transform2D transform2D6 = new A.Transform2D();
                A.Offset offset8 = new A.Offset() { X = 1130299L, Y = 3276903L };
                A.Extents extents8 = new A.Extents() { Cx = 1782535L, Cy = 204108L };

                //A.Offset offset8 = new A.Offset() { X = 0, Y = 0 };
                //A.Extents extents8 = new A.Extents() { Cx = 0, Cy = 0 };

                transform2D6.Append(offset8);
                transform2D6.Append(extents8);

                A.PresetGeometry presetGeometry6 = new A.PresetGeometry() { Preset = A.ShapeTypeValues.Rectangle };
                A.AdjustValueList adjustValueList6 = new A.AdjustValueList();

                presetGeometry6.Append(adjustValueList6);
                A.NoFill noFill6 = new A.NoFill();

                shapeProperties6.Append(transform2D6);
                shapeProperties6.Append(presetGeometry6);
                shapeProperties6.Append(noFill6);

                Xdr.ShapeStyle shapeStyle6 = new Xdr.ShapeStyle();

                A.LineReference lineReference6 = new A.LineReference() { Index = (UInt32Value)0U };
                A.RgbColorModelPercentage rgbColorModelPercentage16 = new A.RgbColorModelPercentage() { RedPortion = 0, GreenPortion = 0, BluePortion = 0 };

                lineReference6.Append(rgbColorModelPercentage16);

                A.FillReference fillReference6 = new A.FillReference() { Index = (UInt32Value)0U };
                A.RgbColorModelPercentage rgbColorModelPercentage17 = new A.RgbColorModelPercentage() { RedPortion = 0, GreenPortion = 0, BluePortion = 0 };

                fillReference6.Append(rgbColorModelPercentage17);

                A.EffectReference effectReference6 = new A.EffectReference() { Index = (UInt32Value)0U };
                A.RgbColorModelPercentage rgbColorModelPercentage18 = new A.RgbColorModelPercentage() { RedPortion = 0, GreenPortion = 0, BluePortion = 0 };

                effectReference6.Append(rgbColorModelPercentage18);

                A.FontReference fontReference6 = new A.FontReference() { Index = A.FontCollectionIndexValues.Minor };
                A.SchemeColor schemeColor29 = new A.SchemeColor() { Val = A.SchemeColorValues.Text1 };

                fontReference6.Append(schemeColor29);

                shapeStyle6.Append(lineReference6);
                shapeStyle6.Append(fillReference6);
                shapeStyle6.Append(effectReference6);
                shapeStyle6.Append(fontReference6);

                Xdr.TextBody textBody6 = new Xdr.TextBody();

                A.BodyProperties bodyProperties6;
                // if (i == 2)
                // {
                //     bodyProperties6 = new A.BodyProperties() { VerticalOverflow = A.TextVerticalOverflowValues.Clip, HorizontalOverflow = A.TextHorizontalOverflowValues.Clip, Wrap = A.TextWrappingValues.Square, RightToLeftColumns = false, Anchor = A.TextAnchoringTypeValues.Bottom };
                //  }
                // else
                //  {
                bodyProperties6 = new A.BodyProperties() { VerticalOverflow = A.TextVerticalOverflowValues.Clip, HorizontalOverflow = A.TextHorizontalOverflowValues.Clip, Wrap = A.TextWrappingValues.Square, RightToLeftColumns = false, Anchor = A.TextAnchoringTypeValues.Top };
                // }

                A.NoAutoFit noAutoFit6 = new A.NoAutoFit();

                bodyProperties6.Append(noAutoFit6);
                A.ListStyle listStyle6 = new A.ListStyle();

                A.Paragraph paragraph6 = new A.Paragraph();
                A.ParagraphProperties paragraphProperties3 = new A.ParagraphProperties() { Alignment = A.TextAlignmentTypeValues.Left };

                A.Run run9 = new A.Run();

                A.RunProperties runProperties9 = new A.RunProperties() { Language = "en-US", FontSize = 1100, Bold = false, Italic = false, Underline = A.TextUnderlineValues.None, Strike = A.TextStrikeValues.NoStrike };

                A.SolidFill solidFill15 = new A.SolidFill();
                A.SchemeColor schemeColor30 = new A.SchemeColor() { Val = A.SchemeColorValues.Background1 };

                solidFill15.Append(schemeColor30);
                A.EffectList effectList7 = new A.EffectList();
                A.LatinFont latinFont6 = new A.LatinFont() { Typeface = "+mn-lt" };
                A.EastAsianFont eastAsianFont6 = new A.EastAsianFont() { Typeface = "+mn-ea" };
                A.ComplexScriptFont complexScriptFont6 = new A.ComplexScriptFont() { Typeface = "+mn-cs" };

                runProperties9.Append(solidFill15);
                runProperties9.Append(effectList7);
                runProperties9.Append(latinFont6);
                runProperties9.Append(eastAsianFont6);
                runProperties9.Append(complexScriptFont6);
                A.Text text9 = new A.Text();
                text9.Text = strGenerator[i];

                run9.Append(runProperties9);
                run9.Append(text9);

                A.Run run10 = new A.Run();

                A.RunProperties runProperties10 = new A.RunProperties() { Language = "en-US", FontSize = 1200 };

                A.SolidFill solidFill16 = new A.SolidFill();
                A.SchemeColor schemeColor31 = new A.SchemeColor() { Val = A.SchemeColorValues.Background1 };

                solidFill16.Append(schemeColor31);

                runProperties10.Append(solidFill16);
                A.Text text10 = new A.Text();
                text10.Text = "";

                run10.Append(runProperties10);
                run10.Append(text10);

                paragraph6.Append(paragraphProperties3);
                paragraph6.Append(run9);
                paragraph6.Append(run10);

                textBody6.Append(bodyProperties6);
                textBody6.Append(listStyle6);
                textBody6.Append(paragraph6);

                shape6.Append(nonVisualShapeProperties6);
                shape6.Append(shapeProperties6);
                shape6.Append(shapeStyle6);
                shape6.Append(textBody6);
                Xdr.ClientData clientData8 = new Xdr.ClientData();

                oneCellAnchor6.Append(fromMarker8);
                oneCellAnchor6.Append(extent6);
                oneCellAnchor6.Append(shape6);
                oneCellAnchor6.Append(clientData8);
                drawingspart.WorksheetDrawing.Append(oneCellAnchor6);
            }
string[]strGenerator=新字符串[]{“2213969”、“2213963”、“2213979”、“2213969”、“2213963”、“2213979”};
字符串[]strRowId=新字符串[]{“22”、“20”、“18”、“18”、“20”、“22”};
字符串[]strColumnId=新字符串[]{“1”、“1”、“1”、“10”、“10”、“10”};
字符串[]strRowOffset=新字符串[]{“18000”、“27000”、“27000”、“50000”、“50000”}//{ "80000", "186266", "95036", "81643", "27214", "136071" };
字符串[]strColumnCoffset=新字符串[]{“489858”、“508606”、“520699”、“497453”、“497453”、“497453”}//{ "489858", "508606", "520699", "197453", "182032", "163285" };
对于(i=0;i<6;i++)
{
Xdr.OneCellAnchor oneCellAnchor6=新的Xdr.OneCellAnchor();
Xdr.FromMarker fromMarker8=新的Xdr.FromMarker();
Xdr.ColumnId columnId10=新的Xdr.ColumnId();
columnId10.Text=strColumnId[i];/“1”;
Xdr.columnPoset columnPoset10=新的Xdr.columnPoset();
columnOffset10.Text=strColumnOffset[i];/“520699”
Xdr.RowId rowId10=新的Xdr.RowId();
rowId10.Text=strRowId[i];/“16”;
Xdr.RowOffset rowOffset10=新的Xdr.RowOffset();
rowOffset10.Text=strRowOffset[i];//“95036”;//Convert.ToString(95036*(i+1));//“95036”;
fromMarker8.Append(columnId10);
fromMarker8.Append(columnOffset10);
fromMarker8.Append(第10行);
fromMarker8.Append(rowOffset10);
//Xdr.Extent ext6=新的Xdr.Extent(){Cx=1782535L,Cy=204108L};
Xdr.Extent ext6=新的Xdr.Extent(){Cx=1782535L,Cy=204108L};
Xdr.Shape shape6=新的Xdr.Shape(){Macro=”“,TextLink=“”};
Xdr.NonVisualShapeProperties NonVisualShapeProperties 6=新的Xdr.NonVisualShapeProperties();
Xdr.NonVisualDrawingProperties NonVisualDrawingProperties 8=新的Xdr.NonVisualDrawingProperties(){Id=(UINT32值)21U,Name=“TextBox 20”};
A.NonVisualDrawingPropertiesExtensionList nonVisualDrawingPropertiesExtensionList8=新的A.NonVisualDrawingPropertiesExtensionList();
A.NonVisualDrawingPropertiesExtension NonVisualDrawingPropertiesExtension 8=新的A.NonVisualDrawingPropertiesExtension(){Uri=“{FF2B5EF4-FFF2-40B4-BE49-F238E27FC236}”;
OpenXmlUnknowneElement OpenXmlUnknowneElement9=OpenXmlUnknowneElement.CreateOpenXmlUnknowneElement(“”);
非可视绘图属性扩展8.Append(openXmlUnknownElement9);
nonVisualDrawingPropertiesExtensionList8.Append(nonVisualDrawingPropertiesExtension8);
nonVisualDrawingProperties8.Append(nonVisualDrawingPropertiesExtensionList8);
Xdr.NonVisualShapeDrawingProperties NonVisualShapeDrawingProperties 6=新Xdr.NonVisualShapeDrawingProperties(){TextBox=true};
非可视化图形属性6.附加(非可视化绘图属性8);
非可视形状属性6.附加(非可视形状属性6);
Xdr.ShapeProperties ShapeProperties 6=新的Xdr.ShapeProperties();
A.Transform2D transform2D6=新的A.Transform2D();
A.Offset offset8=新的A.Offset(){X=1130299L,Y=3276903L};
A.extents8=新的A.Extents(){Cx=1782535L,Cy=204108L};
//A.Offset offset8=新的A.Offset(){X=0,Y=0};
//A.extents8=新的A.Extents(){Cx=0,Cy=0};
转换2d6.追加(抵销8);
transform2D6.Append(extents8);
A.PresetGeometry presetGeometry6=新建A.PresetGeometry(){Preset=A.ShapeTypeValues.Rectangle};
A.AdjustValueList AdjustValueList 6=新的A.AdjustValueList();
预设几何6.追加(调整值列表6);
A.NoFill noFill6=新的A.NoFill();
shapeProperties 6.Append(transform2D6);
ShapeProperties 6.追加(预设几何量6);
shapeProperties 6.Append(noFill6);
Xdr.ShapeStyle shapeStyle6=新的Xdr.ShapeStyle();
A.LineReference lineReference6=新的A.LineReference(){Index=(uint32值)0U};
A.RgbColorModelPercentage RgbColorModelPercentage 16=新的A.RgbColorModelPercentage(){redparty=0,greenpart=0,bluepart=0};
lineReference6.Append(rgbColorModelPercentage16);
A.FillReference fillReference6=新的A.FillReference(){Index=(uint32值)0U};
A.RgbColorModelPercentage RgbColorModelPercentage 17=新的A.RgbColorModelPercentage(){redparty=0,greenpart=0,bluepart=0};
fillReference6.Append(rgbColorModelPercentage17);
A.EffectReference effectReference6=新的A.EffectReference(){Index=(uint32值)0U};
A.RgbColorModelPercentage RgbColorModelPercentage 18=新的A.RgbColorModelPercentage(){redparty=0,greenpart=0,bluepart=0};
效应参考6.追加(RGBColormodelPercentage 18);
A.FontReference fontReference6=新的A.FontReference(){Index=A.FontCollectionIndexValues.Minor};
A.SchemeColor schemeColor29=新的A.SchemeColor(){Val=A.SchemeColorValues.Text1};
fontReference6.追加(schemeColor29);
shapeStyle6.Append(lineReference6);
shapeStyle6.Append(fillReference6);
shapeStyle6.Append(effectReference6);
形状样式6