internal C.NumberLiteral ToNumberLiteral()
        {
            C.NumberLiteral nl = new C.NumberLiteral();
            nl.FormatCode = new C.FormatCode(this.FormatCode);
            nl.PointCount = new C.PointCount() { Val = this.PointCount };
            for (int i = 0; i < this.Points.Count; ++i)
            {
                nl.Append(this.Points[i].ToNumericPoint());
            }

            return nl;
        }
Beispiel #2
0
        internal C.NumberLiteral ToNumberLiteral()
        {
            C.NumberLiteral nl = new C.NumberLiteral();
            nl.FormatCode = new C.FormatCode(this.FormatCode);
            nl.PointCount = new C.PointCount()
            {
                Val = this.PointCount
            };
            for (int i = 0; i < this.Points.Count; ++i)
            {
                nl.Append(this.Points[i].ToNumericPoint());
            }

            return(nl);
        }
Beispiel #3
0
        internal C.NumberLiteral ToNumberLiteral()
        {
            var nl = new C.NumberLiteral();

            nl.FormatCode = new C.FormatCode(FormatCode);
            nl.PointCount = new C.PointCount {
                Val = PointCount
            };
            for (var i = 0; i < Points.Count; ++i)
            {
                nl.Append(Points[i].ToNumericPoint());
            }

            return(nl);
        }
Beispiel #4
0
        //gavdcodeend 10

        //gavdcodebegin 11
        private static void ExcelOpenXmlInsertChart()
        {
            Dictionary <string, int> chartData = new Dictionary <string, int>();

            chartData.Add("abc", 1);
            chartData.Add("def", 2);
            chartData.Add("ghi", 1);

            using (SpreadsheetDocument myExcelDoc =
                       SpreadsheetDocument.Open(@"C:\Temporary\ExcelDoc01.xlsx", true))
            {
                // Use the name of the sheet
                IEnumerable <Sheet> mySheets = myExcelDoc.WorkbookPart.Workbook.
                                               Descendants <Sheet>().Where(s => s.Name == "NewSheet");
                if (mySheets.Count() == 0)
                {
                    return;
                }
                WorksheetPart myWorksheetPart =
                    (WorksheetPart)myExcelDoc.WorkbookPart.
                    GetPartById(mySheets.First().Id);

                // Add a new drawing to the worksheet
                DrawingsPart myDrawingsPart = myWorksheetPart.AddNewPart <DrawingsPart>();
                myWorksheetPart.Worksheet.Append(new
                                                 DocumentFormat.OpenXml.Spreadsheet.Drawing()
                {
                    Id = myWorksheetPart.GetIdOfPart(myDrawingsPart)
                });
                myWorksheetPart.Worksheet.Save();

                // Add a new chart and set the chart language to English-US
                ChartPart myChartPart = myDrawingsPart.AddNewPart <ChartPart>();
                myChartPart.ChartSpace = new DrCh.ChartSpace();
                myChartPart.ChartSpace.Append(new DrCh.EditingLanguage()
                {
                    Val = new StringValue("en-US")
                });
                DrCh.Chart myChart =
                    myChartPart.ChartSpace.AppendChild <DrCh.Chart>(new DrCh.Chart());

                // Create a new clustered column chart
                DrCh.PlotArea plotArea = myChart.AppendChild <DrCh.PlotArea>(
                    new DrCh.PlotArea());
                DrCh.Layout   layout   = plotArea.AppendChild <DrCh.Layout>(new DrCh.Layout());
                DrCh.BarChart barChart = plotArea.AppendChild <DrCh.BarChart>(
                    new DrCh.BarChart(new DrCh.BarDirection()
                {
                    Val = new EnumValue <DrCh.BarDirectionValues>
                              (DrCh.BarDirectionValues.Column)
                },
                                      new DrCh.BarGrouping()
                {
                    Val = new EnumValue <DrCh.BarGroupingValues>
                              (DrCh.BarGroupingValues.Clustered)
                }));

                uint myIndex = 0;

                foreach (string oneKey in chartData.Keys)
                {
                    DrCh.BarChartSeries barChartSeries = barChart.AppendChild
                                                         <DrCh.BarChartSeries>(new DrCh.BarChartSeries(new DrCh.Index()
                    {
                        Val = new UInt32Value(myIndex)
                    },
                                                                                                       new DrCh.Order()
                    {
                        Val = new UInt32Value(myIndex)
                    },
                                                                                                       new DrCh.SeriesText(new DrCh.NumericValue()
                    {
                        Text = oneKey
                    })));

                    DrCh.StringLiteral strLit = barChartSeries.AppendChild <DrCh.
                                                                            CategoryAxisData>(new DrCh.CategoryAxisData()).
                                                AppendChild <DrCh.StringLiteral>(new DrCh.StringLiteral());
                    strLit.Append(new DrCh.PointCount()
                    {
                        Val = new UInt32Value(1U)
                    });
                    // Use the title for the graphic
                    strLit.AppendChild <DrCh.StringPoint>(new DrCh.StringPoint()
                    {
                        Index = new UInt32Value(0U)
                    }).
                    Append(new DrCh.NumericValue("My New Graphic"));

                    DrCh.NumberLiteral numLit = barChartSeries.AppendChild
                                                <DocumentFormat.OpenXml.Drawing.Charts.Values>(
                        new DocumentFormat.OpenXml.Drawing.Charts.Values()).
                                                AppendChild <DrCh.NumberLiteral>(new DrCh.NumberLiteral());
                    numLit.Append(new DrCh.FormatCode("General"));
                    numLit.Append(new DrCh.PointCount()
                    {
                        Val = new UInt32Value(1U)
                    });
                    numLit.AppendChild <DrCh.NumericPoint>(new DrCh.NumericPoint()
                    {
                        Index = new UInt32Value(0u)
                    }).Append
                        (new DrCh.NumericValue(chartData[oneKey].ToString()));

                    myIndex++;
                }

                barChart.Append(new DrCh.AxisId()
                {
                    Val = new UInt32Value(48650112u)
                });
                barChart.Append(new DrCh.AxisId()
                {
                    Val = new UInt32Value(48672768u)
                });

                // Add the Category Axis.
                DrCh.CategoryAxis catAx = plotArea.AppendChild <DrCh.CategoryAxis>
                                              (new DrCh.CategoryAxis(new DrCh.AxisId()
                {
                    Val = new UInt32Value(48650112u)
                },
                                                                     new DrCh.Scaling(new DrCh.Orientation()
                {
                    Val = new EnumValue <DocumentFormat.
                                         OpenXml.Drawing.Charts.OrientationValues>(
                        DrCh.OrientationValues.MinMax)
                }),
                                                                     new DrCh.AxisPosition()
                {
                    Val = new EnumValue <DrCh.AxisPositionValues>
                              (DrCh.AxisPositionValues.Bottom)
                },
                                                                     new DrCh.TickLabelPosition()
                {
                    Val = new EnumValue <DrCh.TickLabelPositionValues>
                              (DrCh.TickLabelPositionValues.NextTo)
                },
                                                                     new DrCh.CrossingAxis()
                {
                    Val = new UInt32Value(48672768U)
                },
                                                                     new DrCh.Crosses()
                {
                    Val = new EnumValue <DrCh.CrossesValues>(
                        DrCh.CrossesValues.AutoZero)
                },
                                                                     new DrCh.AutoLabeled()
                {
                    Val = new BooleanValue(true)
                },
                                                                     new DrCh.LabelAlignment()
                {
                    Val = new EnumValue <DrCh.LabelAlignmentValues>(
                        DrCh.LabelAlignmentValues.Center)
                },
                                                                     new DrCh.LabelOffset()
                {
                    Val = new UInt16Value((ushort)100)
                }));

                // Add the Value Axis.
                DrCh.ValueAxis valAx = plotArea.AppendChild <DrCh.ValueAxis>(
                    new DrCh.ValueAxis(new DrCh.AxisId()
                {
                    Val = new UInt32Value(48672768u)
                },
                                       new DrCh.Scaling(new DrCh.Orientation()
                {
                    Val = new EnumValue <DrCh.OrientationValues>(
                        DrCh.OrientationValues.MinMax)
                }),
                                       new DrCh.AxisPosition()
                {
                    Val = new EnumValue <DrCh.AxisPositionValues>(
                        DrCh.AxisPositionValues.Left)
                },
                                       new DrCh.MajorGridlines(),
                                       new DrCh.NumberingFormat()
                {
                    FormatCode   = new StringValue("General"),
                    SourceLinked = new BooleanValue(true)
                },
                                       new DrCh.TickLabelPosition()
                {
                    Val = new EnumValue <DrCh.TickLabelPositionValues>
                              (DrCh.TickLabelPositionValues.NextTo)
                },
                                       new DrCh.CrossingAxis()
                {
                    Val = new UInt32Value(48650112U)
                },
                                       new DrCh.Crosses()
                {
                    Val = new EnumValue <DrCh.CrossesValues>
                              (DrCh.CrossesValues.AutoZero)
                },
                                       new DrCh.CrossBetween()
                {
                    Val = new EnumValue <DrCh.CrossBetweenValues>
                              (DrCh.CrossBetweenValues.Between)
                }));

                // Add the chart Legend.
                DrCh.Legend myLegend = myChart.AppendChild <DrCh.Legend>(
                    new DrCh.Legend(new DrCh.LegendPosition()
                {
                    Val = new EnumValue <DrCh.LegendPositionValues>
                              (DrCh.LegendPositionValues.Right)
                },
                                    new DrCh.Layout()));

                myChart.Append(new DrCh.PlotVisibleOnly()
                {
                    Val = new BooleanValue(true)
                });

                myChartPart.ChartSpace.Save();

                // Position the chart on the worksheet using a TwoCellAnchor object.
                myDrawingsPart.WorksheetDrawing = new DrSp.WorksheetDrawing();
                DrSp.TwoCellAnchor twoCellAnchor = myDrawingsPart.WorksheetDrawing.
                                                   AppendChild <DrSp.TwoCellAnchor>(
                    new DrSp.TwoCellAnchor());
                twoCellAnchor.Append(new DrSp.FromMarker(new DrSp.ColumnId("9"),
                                                         new DrSp.ColumnOffset("581025"),
                                                         new DrSp.RowId("17"),
                                                         new DrSp.RowOffset("114300")));
                twoCellAnchor.Append(new DrSp.ToMarker(new DrSp.ColumnId("17"),
                                                       new DrSp.ColumnOffset("276225"),
                                                       new DrSp.RowId("32"),
                                                       new DrSp.RowOffset("0")));

                // Append a GraphicFrame to the TwoCellAnchor object.
                DrSp.GraphicFrame myGraphicFrame =
                    twoCellAnchor.AppendChild <DrSp.GraphicFrame>(new DrSp.GraphicFrame());
                myGraphicFrame.Macro = "";

                myGraphicFrame.Append(new DrSp.NonVisualGraphicFrameProperties(
                                          new DrSp.NonVisualDrawingProperties()
                {
                    Id   = new UInt32Value(2u),
                    Name = "Chart 1"
                },
                                          new DrSp.NonVisualGraphicFrameDrawingProperties()));

                myGraphicFrame.Append(new DrSp.Transform(
                                          new DocumentFormat.OpenXml.Drawing.Offset()
                {
                    X = 0L,
                    Y = 0L
                },
                                          new DocumentFormat.OpenXml.Drawing.Extents()
                {
                    Cx = 0L,
                    Cy = 0L
                }));

                myGraphicFrame.Append(
                    new DocumentFormat.OpenXml.Drawing.Graphic(
                        new DocumentFormat.OpenXml.Drawing.GraphicData(
                            new DrCh.ChartReference()
                {
                    Id = myDrawingsPart.GetIdOfPart(myChartPart)
                })
                {
                    Uri = "http://schemas.openxmlformats.org/drawingml/2006/chart"
                }));

                twoCellAnchor.Append(new DrSp.ClientData());

                myDrawingsPart.WorksheetDrawing.Save();
            }
        }