Пример #1
0
        public override Object Clone()
        {
            BeginRecord br = new BeginRecord();

            // No data so nothing to copy
            return(br);
        }
Пример #2
0
        public HSSFSeries CreateSeries()
        {
            List<RecordBase> seriesTemplate = new List<RecordBase>();
            bool seriesTemplateFilled = false;

            int idx = 0;
            int deep = 0;
            int chartRecordIdx = -1;
            int chartDeep = -1;
            int lastSeriesDeep = -1;
            int endSeriesRecordIdx = -1;
            int seriesIdx = 0;
            IList records = sheet.Sheet.Records;

            /* store first series as template and find last series index */
            foreach (RecordBase record in records)
            {

                idx++;

                if (record is BeginRecord)
                {
                    deep++;
                }
                else if (record is EndRecord)
                {
                    deep--;

                    if (lastSeriesDeep == deep)
                    {
                        lastSeriesDeep = -1;
                        endSeriesRecordIdx = idx;
                        if (!seriesTemplateFilled)
                        {
                            seriesTemplate.Add(record);
                            seriesTemplateFilled = true;
                        }
                    }

                    if (chartDeep == deep)
                    {
                        break;
                    }
                }

                if (record is ChartRecord)
                {
                    if (record == chartRecord)
                    {
                        chartRecordIdx = idx;
                        chartDeep = deep;
                    }
                }
                else if (record is SeriesRecord)
                {
                    if (chartRecordIdx != -1)
                    {
                        seriesIdx++;
                        lastSeriesDeep = deep;
                    }
                }

                if (lastSeriesDeep != -1 && !seriesTemplateFilled)
                {
                    seriesTemplate.Add(record);
                }
            }

            /* check if a series was found */
            if (endSeriesRecordIdx == -1)
            {
                return null;
            }

            /* next index in the records list where the new series can be inserted */
            idx = endSeriesRecordIdx + 1;

            HSSFSeries newSeries = null;

            /* duplicate record of the template series */
            List<RecordBase> ClonedRecords = new List<RecordBase>();
            foreach (RecordBase record in seriesTemplate)
            {

                Record newRecord = null;

                if (record is BeginRecord)
                {
                    newRecord = new BeginRecord();
                }
                else if (record is EndRecord)
                {
                    newRecord = new EndRecord();
                }
                else if (record is SeriesRecord)
                {
                    SeriesRecord seriesRecord = (SeriesRecord)((SeriesRecord)record).Clone();
                    newSeries = new HSSFSeries(seriesRecord);
                    newRecord = seriesRecord;
                }
                else if (record is LinkedDataRecord)
                {
                    LinkedDataRecord linkedDataRecord = (LinkedDataRecord)((LinkedDataRecord)record).Clone();
                    if (newSeries != null)
                    {
                        newSeries.InsertData(linkedDataRecord);
                    }
                    newRecord = linkedDataRecord;
                }
                else if (record is DataFormatRecord)
                {
                    DataFormatRecord dataFormatRecord = (DataFormatRecord)((DataFormatRecord)record).Clone();

                    dataFormatRecord.SeriesIndex = ((short)seriesIdx);
                    dataFormatRecord.SeriesNumber = ((short)seriesIdx);

                    newRecord = dataFormatRecord;
                }
                else if (record is SeriesTextRecord)
                {
                    SeriesTextRecord seriesTextRecord = (SeriesTextRecord)((SeriesTextRecord)record).Clone();
                    if (newSeries != null)
                    {
                        newSeries.SetSeriesTitleText(seriesTextRecord);
                    }
                    newRecord = seriesTextRecord;
                }
                else if (record is Record)
                {
                    newRecord = (Record)((Record)record).Clone();
                }

                if (newRecord != null)
                {
                    ClonedRecords.Add(newRecord);
                }
            }

            /* check if a user model series object was Created */
            if (newSeries == null)
            {
                return null;
            }

            /* transfer series to record list */
            foreach (RecordBase record in ClonedRecords)
            {
                records.Insert(idx++, record);
            }

            return newSeries;
        }
Пример #3
0
 public override Object Clone()
 {
     BeginRecord br = new BeginRecord();
     // No data so nothing to copy
     return br;
 }