コード例 #1
0
        public IRange GetRange(string formula)
        {
            bool result = ReferenceEncoder.TryDecodeRangeReference(
                formula,
                out string worksheetName,
                out uint?startColumn, out bool isStartColumnFixed,
                out uint?startRow, out bool isStartRowFixed,
                out uint?endColumn, out bool isEndColumnFixed,
                out uint?endRow, out bool isEndRowFixed
                );

            if (!result)
            {
                throw new FormatException();
            }

            if (worksheetName == null)
            {
                throw new ArgumentException("No worksheet specified");
            }

            if (!this.Worksheets.TryGetValue(worksheetName, out IWorksheet worksheet))
            {
                throw new ArgumentException("Invalid worksheet name.");
            }

            return(new OpenXmlRange(
                       worksheet as OpenXmlWorksheet,
                       startColumn, isStartColumnFixed,
                       startRow, isStartRowFixed,
                       endColumn, isEndColumnFixed,
                       endRow, isEndRowFixed
                       ));
        }
コード例 #2
0
 public static bool TryCreateCell(OpenXmlWorksheet worksheet, string reference, out OpenXmlCell cell)
 {
     if (ReferenceEncoder.TryDecodeCellReference(reference, out uint column, out bool isColumnFixed, out uint row, out bool isRowFixed))
     {
         cell = new OpenXmlCell(worksheet, column, isColumnFixed, row, isRowFixed);
         return(true);
     }
コード例 #3
0
        public IRange GetRange(string formula)
        {
            bool result = ReferenceEncoder.TryDecodeRangeReference(
                formula,
                out string worksheetName,
                out uint?startColumn, out bool isStartColumnFixed,
                out uint?startRow, out bool isStartRowFixed,
                out uint?endColumn, out bool isEndColumnFixed,
                out uint?endRow, out bool isEndRowFixed
                );

            if (!result)
            {
                throw new FormatException();
            }

            if (worksheetName != null && worksheetName != this.Name)
            {
                throw new ArgumentException("Referenced a different worksheet");
            }

            return(new OpenXmlRange(
                       this,
                       startColumn, isStartColumnFixed,
                       startRow, isStartRowFixed,
                       endColumn, isEndColumnFixed,
                       endRow, isEndRowFixed
                       ));
        }
コード例 #4
0
        public ILineChart InitializeFromRange(IRange labelRange, IRange categoryRange)
        {
            uint orderStart = (uint)this.chartSpace.Charts.TakeWhile(c => c != this).Sum(c => c.SeriesCount);

            this.lineChart.RemoveAllChildren <LineChartSeries>();

            IWorksheet worksheet = labelRange.Worksheet;

            if (labelRange.Width == 1 && labelRange.Height > 0 && categoryRange.Height == 1 && categoryRange.Width > 0)
            {
                for (uint labelIndex = 0; labelIndex < labelRange.Height; ++labelIndex)
                {
                    LineChartSeries series = this.lineChart.AppendChild(
                        new LineChartSeries()
                    {
                        Index = new Index()
                        {
                            Val = orderStart + labelIndex
                        },
                        Order = new Order()
                        {
                            Val = orderStart + labelIndex
                        }
                    }
                        );

                    series.AppendChild(
                        new Marker()
                    {
                        Symbol = new Symbol()
                        {
                            Val = MarkerStyleValues.None
                        }
                    }
                        );

                    series.AppendChild(
                        new SeriesText().AppendChildFluent(
                            new StringReference()
                    {
                        Formula     = new Formula(labelRange[0, labelIndex].Reference),
                        StringCache = new StringCache()
                                      .AppendChildFluent(new PointCount()
                        {
                            Val = 1
                        })
                                      .AppendChildFluent(new StringPoint()
                        {
                            Index = 0, NumericValue = new NumericValue()
                            {
                                Text = labelRange[0, labelIndex].InnerValue
                            }
                        })
                    }
                            )
                        );

                    series.AppendChild(
                        new CategoryAxisData().AppendChildFluent(
                            new StringReference()
                    {
                        Formula     = new Formula(categoryRange.Formula),
                        StringCache = new StringCache()
                                      .AppendChildFluent(new PointCount()
                        {
                            Val = (uint)categoryRange.Width.Value
                        })
                                      .AppendFluent(Enumerable.Range(0, categoryRange.Width.Value).Select(categoryIndex => new StringPoint()
                        {
                            Index = (uint)categoryIndex, NumericValue = new NumericValue()
                            {
                                Text = categoryRange[(uint)categoryIndex, 0].InnerValue
                            }
                        }))
                    }
                            )
                        );

                    string valuesFormula = ReferenceEncoder.EncodeRangeReference(
                        worksheet.Name,
                        categoryRange.StartColumn, false,
                        labelRange.StartRow + labelIndex, false,
                        categoryRange.EndColumn, false,
                        labelRange.StartRow + labelIndex, false
                        );

                    series.AppendChild(
                        new Values().AppendChildFluent(
                            new NumberReference()
                    {
                        Formula        = new Formula(valuesFormula),
                        NumberingCache = new NumberingCache()
                                         .AppendChildFluent(new PointCount()
                        {
                            Val = (uint)categoryRange.Width.Value
                        })
                                         .AppendFluent(Enumerable.Range(0, categoryRange.Width.Value).Select(categoryIndex => new NumericPoint()
                        {
                            Index = (uint)categoryIndex, NumericValue = new NumericValue()
                            {
                                Text = worksheet.Cells[categoryRange.StartColumn.Value + (uint)categoryIndex, labelRange.StartRow.Value + labelIndex].InnerValue
                            }
                        }))
                    }
                            )
                        );

                    series.AppendChild(new Smooth()
                    {
                        Val = false
                    });
                }
            }
            else if (labelRange.Height == 1 && labelRange.Width > 0 && categoryRange.Width == 1 && categoryRange.Height > 0)
            {
                for (uint labelIndex = 0; labelIndex < labelRange.Width; ++labelIndex)
                {
                    LineChartSeries series = this.lineChart.AppendChild(
                        new LineChartSeries()
                    {
                        Index = new Index()
                        {
                            Val = orderStart + labelIndex
                        },
                        Order = new Order()
                        {
                            Val = orderStart + labelIndex
                        }
                    }
                        );

                    series.AppendChild(
                        new Marker()
                    {
                        Symbol = new Symbol()
                        {
                            Val = MarkerStyleValues.None
                        }
                    }
                        );

                    series.AppendChild(
                        new SeriesText().AppendChildFluent(
                            new StringReference()
                    {
                        Formula     = new Formula(labelRange[labelIndex, 0].Reference),
                        StringCache = new StringCache()
                                      .AppendChildFluent(new PointCount()
                        {
                            Val = 1
                        })
                                      .AppendChildFluent(new StringPoint()
                        {
                            Index = 0, NumericValue = new NumericValue()
                            {
                                Text = labelRange[labelIndex, 0].InnerValue
                            }
                        })
                    }
                            )
                        );

                    series.AppendChild(
                        new CategoryAxisData().AppendChildFluent(
                            new StringReference()
                    {
                        Formula     = new Formula(categoryRange.Formula),
                        StringCache = new StringCache()
                                      .AppendChildFluent(new PointCount()
                        {
                            Val = (uint)categoryRange.Height.Value
                        })
                                      .AppendFluent(Enumerable.Range(0, categoryRange.Height.Value).Select(categoryIndex => new StringPoint()
                        {
                            Index = (uint)categoryIndex, NumericValue = new NumericValue()
                            {
                                Text = categoryRange[0, (uint)categoryIndex].InnerValue
                            }
                        }))
                    }
                            )
                        );

                    string valuesFormula = ReferenceEncoder.EncodeRangeReference(
                        worksheet.Name,
                        labelRange.StartColumn + labelIndex, false,
                        categoryRange.StartRow, false,
                        labelRange.StartColumn + labelIndex, false,
                        categoryRange.EndRow, false
                        );

                    series.AppendChild(
                        new Values().AppendChildFluent(
                            new NumberReference()
                    {
                        Formula        = new Formula(valuesFormula),
                        NumberingCache = new NumberingCache()
                                         .AppendChildFluent(new PointCount()
                        {
                            Val = (uint)categoryRange.Height.Value
                        })
                                         .AppendFluent(Enumerable.Range(0, categoryRange.Height.Value).Select(categoryIndex => new NumericPoint()
                        {
                            Index = (uint)categoryIndex, NumericValue = new NumericValue()
                            {
                                Text = worksheet.Cells[labelRange.StartColumn.Value + labelIndex, categoryRange.StartRow.Value + (uint)categoryIndex].InnerValue
                            }
                        }))
                    }
                            )
                        );

                    series.AppendChild(new Smooth()
                    {
                        Val = false
                    });
                }
            }
            else
            {
                throw new ArgumentException();
            }

            return(this);
        }