Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ExportSymbolicDataAnalysisSolutions/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/3.1.3/EPPlus-3.1.3/Table/PivotTable/ExcelPivotTable.cs @ 9580

Last change on this file since 9580 was 9580, checked in by sforsten, 11 years ago

#1730:

  • added SymbolicDataAnalysisExpressionExcelFormatter
  • changed modifiers in SymbolicExpressionTreeChart of methods SaveImageAsBitmap and SaveImageAsEmf to public
  • added menu item ExportSymbolicSolutionToExcelMenuItem to export a symbolic solution to an excel file
  • added EPPlus-3.1.3 to ExtLibs
File size: 31.2 KB
Line 
1/*******************************************************************************
2 * You may amend and distribute as you like, but don't remove this header!
3 *
4 * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
5 * See http://www.codeplex.com/EPPlus for details.
6 *
7 * Copyright (C) 2011  Jan Källman
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
17 * See the GNU Lesser General Public License for more details.
18 *
19 * The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php
20 * If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html
21 *
22 * All code and executables are provided "as is" with no warranty either express or implied.
23 * The author accepts no liability for any damage or loss of business that this product may cause.
24 *
25 * Code change notes:
26 *
27 * Author             Change            Date
28 * ******************************************************************************
29 * Jan Källman    Added   21-MAR-2011
30 * Jan Källman    License changed GPL-->LGPL 2011-12-16
31 *******************************************************************************/
32using System;
33using System.Collections.Generic;
34using System.Text;
35using System.Xml;
36using System.IO.Packaging;
37using System.Text.RegularExpressions;
38using OfficeOpenXml.Table;
39
40namespace OfficeOpenXml.Table.PivotTable
41{
42    /// <summary>
43    /// An Excel Pivottable
44    /// </summary>
45    public class ExcelPivotTable : XmlHelper
46    {
47        internal ExcelPivotTable(PackageRelationship rel, ExcelWorksheet sheet) :
48            base(sheet.NameSpaceManager)
49        {
50            WorkSheet = sheet;
51            PivotTableUri = PackUriHelper.ResolvePartUri(rel.SourceUri, rel.TargetUri);
52            Relationship = rel;
53            var pck = sheet._package.Package;
54            Part=pck.GetPart(PivotTableUri);
55
56            PivotTableXml = new XmlDocument();
57            LoadXmlSafe(PivotTableXml, Part.GetStream());
58            init();
59            TopNode = PivotTableXml.DocumentElement;
60            Address = new ExcelAddressBase(GetXmlNodeString("d:location/@ref"));
61
62            _cacheDefinition = new ExcelPivotCacheDefinition(sheet.NameSpaceManager, this);
63            LoadFields();
64
65            //Add row fields.
66            foreach (XmlElement rowElem in TopNode.SelectNodes("d:rowFields/d:field", NameSpaceManager))
67            {
68                int x;
69                if (int.TryParse(rowElem.GetAttribute("x"), out x) && x >= 0)
70                {
71                    RowFields.AddInternal(Fields[x]);
72                }
73                else
74                {
75                    rowElem.ParentNode.RemoveChild(rowElem);
76                }
77            }
78
79            ////Add column fields.
80            foreach (XmlElement colElem in TopNode.SelectNodes("d:colFields/d:field", NameSpaceManager))
81            {
82                int x;
83                if(int.TryParse(colElem.GetAttribute("x"),out x) && x >= 0)
84                {
85                    ColumnFields.AddInternal(Fields[x]);
86                }
87                else
88                {
89                    colElem.ParentNode.RemoveChild(colElem);
90                }
91            }
92
93            //Add Page elements
94            //int index = 0;
95            foreach (XmlElement pageElem in TopNode.SelectNodes("d:pageFields/d:pageField", NameSpaceManager))
96            {
97                int fld;
98                if (int.TryParse(pageElem.GetAttribute("fld"), out fld) && fld >= 0)
99                {
100                    var field = Fields[fld];
101                    field._pageFieldSettings = new ExcelPivotTablePageFieldSettings(NameSpaceManager, pageElem, field, fld);
102                    PageFields.AddInternal(field);
103                }
104            }
105
106            //Add data elements
107            //index = 0;
108            foreach (XmlElement dataElem in TopNode.SelectNodes("d:dataFields/d:dataField", NameSpaceManager))
109            {
110                int fld;
111                if (int.TryParse(dataElem.GetAttribute("fld"), out fld) && fld >= 0)
112                {
113                    var field = Fields[fld];
114                    var dataField = new ExcelPivotTableDataField(NameSpaceManager, dataElem, field);
115                    DataFields.AddInternal(dataField);
116                }
117            }
118        }
119        /// <summary>
120        /// Add a new pivottable
121        /// </summary>
122        /// <param name="sheet">The worksheet</param>
123        /// <param name="address">the address of the pivottable</param>
124        /// <param name="sourceAddress">The address of the Source data</param>
125        /// <param name="name"></param>
126        /// <param name="tblId"></param>
127        internal ExcelPivotTable(ExcelWorksheet sheet, ExcelAddressBase address,ExcelRangeBase sourceAddress, string name, int tblId) :
128            base(sheet.NameSpaceManager)
129      {
130            WorkSheet = sheet;
131            Address = address;
132            var pck = sheet._package.Package;
133
134            PivotTableXml = new XmlDocument();
135            LoadXmlSafe(PivotTableXml, GetStartXml(name, tblId, address, sourceAddress), Encoding.UTF8);
136            TopNode = PivotTableXml.DocumentElement;
137            PivotTableUri =  GetNewUri(pck, "/xl/pivotTables/pivotTable{0}.xml", tblId);
138            init();
139
140            Part = pck.CreatePart(PivotTableUri, ExcelPackage.schemaPivotTable);
141            PivotTableXml.Save(Part.GetStream());
142           
143            //Worksheet-Pivottable relationship
144            Relationship = sheet.Part.CreateRelationship(PackUriHelper.ResolvePartUri(sheet.WorksheetUri, PivotTableUri), TargetMode.Internal, ExcelPackage.schemaRelationships + "/pivotTable");
145
146            _cacheDefinition = new ExcelPivotCacheDefinition(sheet.NameSpaceManager, this, sourceAddress, tblId);
147            _cacheDefinition.Relationship=Part.CreateRelationship(PackUriHelper.ResolvePartUri(PivotTableUri, _cacheDefinition.CacheDefinitionUri), TargetMode.Internal, ExcelPackage.schemaRelationships + "/pivotCacheDefinition");
148
149            sheet.Workbook.AddPivotTable(CacheID.ToString(), _cacheDefinition.CacheDefinitionUri);
150
151            LoadFields();
152
153            using (var r=sheet.Cells[address.Address])
154            {
155                r.Clear();
156            }
157        }
158        private void init()
159        {
160            SchemaNodeOrder = new string[] { "location", "pivotFields", "rowFields", "rowItems", "colFields", "colItems", "pageFields", "pageItems", "dataFields", "dataItems", "formats", "pivotTableStyleInfo" };
161        }
162        private void LoadFields()
163        {
164            //Fields.Clear();
165            //int ix=0;
166            //foreach(XmlElement fieldNode in PivotXml.SelectNodes("//d:pivotFields/d:pivotField",NameSpaceManager))
167            //{
168            //    Fields.AddInternal(new ExcelPivotTableField(NameSpaceManager, fieldNode, this, ix++));
169            //}
170
171            int index = 0;
172            //Add fields.
173            foreach (XmlElement fieldElem in TopNode.SelectNodes("d:pivotFields/d:pivotField", NameSpaceManager))
174            {
175                var fld = new ExcelPivotTableField(NameSpaceManager, fieldElem, this, index, index++);
176                Fields.AddInternal(fld);
177            }
178
179            //Add fields.
180            index = 0;
181            foreach (XmlElement fieldElem in _cacheDefinition.TopNode.SelectNodes("d:cacheFields/d:cacheField", NameSpaceManager))
182            {
183                var fld = Fields[index++];
184                fld.SetCacheFieldNode(fieldElem);
185            }
186
187
188        }
189        private string GetStartXml(string name, int id, ExcelAddressBase address, ExcelAddressBase sourceAddress)
190        {
191            string xml = string.Format("<pivotTableDefinition xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" name=\"{0}\" cacheId=\"{1}\" dataOnRows=\"1\" applyNumberFormats=\"0\" applyBorderFormats=\"0\" applyFontFormats=\"0\" applyPatternFormats=\"0\" applyAlignmentFormats=\"0\" applyWidthHeightFormats=\"1\" dataCaption=\"Data\"  createdVersion=\"4\" showMemberPropertyTips=\"0\" useAutoFormatting=\"1\" itemPrintTitles=\"1\" indent=\"0\" compact=\"0\" compactData=\"0\" gridDropZones=\"1\">", name, id);
192
193            xml += string.Format("<location ref=\"{0}\" firstHeaderRow=\"1\" firstDataRow=\"1\" firstDataCol=\"1\" /> ", address.FirstAddress);
194            xml += string.Format("<pivotFields count=\"{0}\">", sourceAddress._toCol-sourceAddress._fromCol+1);
195            for (int col = sourceAddress._fromCol; col <= sourceAddress._toCol; col++)
196            {
197                xml += "<pivotField showAll=\"0\" />"; //compact=\"0\" outline=\"0\" subtotalTop=\"0\" includeNewItemsInFilter=\"1\"     
198            }
199
200            xml += "</pivotFields>";
201            xml += "<pivotTableStyleInfo name=\"PivotStyleMedium9\" showRowHeaders=\"1\" showColHeaders=\"1\" showRowStripes=\"0\" showColStripes=\"0\" showLastColumn=\"1\" />";
202            xml += "</pivotTableDefinition>";
203            return xml;
204        }
205        internal PackagePart Part
206        {
207            get;
208            set;
209        }
210        /// <summary>
211        /// Provides access to the XML data representing the pivottable in the package.
212        /// </summary>
213        public XmlDocument PivotTableXml { get; private set; }
214        /// <summary>
215        /// The package internal URI to the pivottable Xml Document.
216        /// </summary>
217        public Uri PivotTableUri
218        {
219            get;
220            internal set;
221        }
222        internal PackageRelationship Relationship
223        {
224            get;
225            set;
226        }
227        const string ID_PATH = "@id";
228        internal int Id
229        {
230            get
231            {
232                return GetXmlNodeInt(ID_PATH);
233            }
234            set
235            {
236                SetXmlNodeString(ID_PATH, value.ToString());
237            }
238        }
239        const string NAME_PATH = "@name";
240        const string DISPLAY_NAME_PATH = "@displayName";
241        /// <summary>
242        /// Name of the pivottable object in Excel
243        /// </summary>
244        public string Name
245        {
246            get
247            {
248                return GetXmlNodeString(NAME_PATH);
249            }
250            set
251            {
252                if (WorkSheet.Workbook.ExistsTableName(value))
253                {
254                    throw (new ArgumentException("PivotTable name is not unique"));
255                }
256                string prevName = Name;
257                if (WorkSheet.Tables._tableNames.ContainsKey(prevName))
258                {
259                    int ix = WorkSheet.Tables._tableNames[prevName];
260                    WorkSheet.Tables._tableNames.Remove(prevName);
261                    WorkSheet.Tables._tableNames.Add(value, ix);
262                }
263                SetXmlNodeString(NAME_PATH, value);
264                SetXmlNodeString(DISPLAY_NAME_PATH, cleanDisplayName(value));
265            }
266        }       
267        ExcelPivotCacheDefinition _cacheDefinition = null;
268        /// <summary>
269        /// Reference to the pivot table cache definition object
270        /// </summary>
271        public ExcelPivotCacheDefinition CacheDefinition
272        {
273            get
274            {
275                if (_cacheDefinition == null)
276                {
277                    _cacheDefinition = new ExcelPivotCacheDefinition(NameSpaceManager, this, null, 1);
278                }
279                return _cacheDefinition;
280            }
281        }
282        private string cleanDisplayName(string name)
283        {
284            return Regex.Replace(name, @"[^\w\.-_]", "_");
285        }
286        #region "Public Properties"
287
288        /// <summary>
289        /// The worksheet where the pivottable is located
290        /// </summary>
291        public ExcelWorksheet WorkSheet
292        {
293            get;
294            set;
295        }
296        /// <summary>
297        /// The location of the pivot table
298        /// </summary>
299        public ExcelAddressBase Address
300        {
301            get;
302            internal set;
303        }
304        /// <summary>
305        /// If multiple datafields are displayed in the row area or the column area
306        /// </summary>
307        public bool DataOnRows
308        {
309            get
310            {
311                return GetXmlNodeBool("@dataOnRows");
312            }
313            set
314            {
315                SetXmlNodeBool("@dataOnRows",value);
316            }
317        }
318        /// <summary>
319        /// if true apply legacy table autoformat number format properties.
320        /// </summary>
321        public bool ApplyNumberFormats
322        {
323            get
324            {
325                return GetXmlNodeBool("@applyNumberFormats");
326            }
327            set
328            {
329                SetXmlNodeBool("@applyNumberFormats",value);
330            }
331        }
332        /// <summary>
333        /// If true apply legacy table autoformat border properties
334        /// </summary>
335        public bool ApplyBorderFormats
336        {
337            get
338            {
339                return GetXmlNodeBool("@applyBorderFormats");
340            }
341            set
342            {
343                SetXmlNodeBool("@applyBorderFormats",value);
344            }
345        }
346        /// <summary>
347        /// If true apply legacy table autoformat font properties
348        /// </summary>
349        public bool ApplyFontFormats
350        {
351            get
352            {
353                return GetXmlNodeBool("@applyFontFormats");
354            }
355            set
356            {
357                SetXmlNodeBool("@applyFontFormats",value);
358            }
359        }
360        /// <summary>
361        /// If true apply legacy table autoformat pattern properties
362        /// </summary>
363        public bool ApplyPatternFormats
364        {
365            get
366            {
367                return GetXmlNodeBool("@applyPatternFormats");
368            }
369            set
370            {
371                SetXmlNodeBool("@applyPatternFormats",value);
372            }
373        }
374        /// <summary>
375        /// If true apply legacy table autoformat width/height properties.
376        /// </summary>
377        public bool ApplyWidthHeightFormats
378        {
379            get
380            {
381                return GetXmlNodeBool("@applyWidthHeightFormats");
382            }
383            set
384            {
385                SetXmlNodeBool("@applyWidthHeightFormats",value);
386            }
387        }
388        /// <summary>
389        /// Show member property information
390        /// </summary>
391        public bool ShowMemberPropertyTips
392        {
393            get
394            {
395                return GetXmlNodeBool("@showMemberPropertyTips");
396            }
397            set
398            {
399                SetXmlNodeBool("@showMemberPropertyTips",value);
400            }
401        }
402        /// <summary>
403        /// Show the drill indicators
404        /// </summary>
405        public bool ShowCalcMember
406        {
407            get
408            {
409                return GetXmlNodeBool("@showCalcMbrs");
410            }
411            set
412            {
413                SetXmlNodeBool("@showCalcMbrs", value);
414            }
415        }       
416        /// <summary>
417        /// If the user is prevented from drilling down on a PivotItem or aggregate value
418        /// </summary>
419        public bool EnableDrill
420        {
421            get
422            {
423                return GetXmlNodeBool("@enableDrill", true);
424            }
425            set
426            {
427                SetXmlNodeBool("@enableDrill", value);
428            }
429        }
430        /// <summary>
431        /// Show the drill down buttons
432        /// </summary>
433        public bool ShowDrill
434        {
435            get
436            {
437                return GetXmlNodeBool("@showDrill", true);
438            }
439            set
440            {
441                SetXmlNodeBool("@showDrill", value);
442            }
443        }
444        /// <summary>
445        /// If the tooltips should be displayed for PivotTable data cells.
446        /// </summary>
447        public bool ShowDataTips
448        {
449            get
450            {
451                return GetXmlNodeBool("@showDataTips", true);
452            }
453            set
454            {
455                SetXmlNodeBool("@showDataTips", value, true);
456            }
457        }
458        /// <summary>
459        /// If the row and column titles from the PivotTable should be printed.
460        /// </summary>
461        public bool FieldPrintTitles
462        {
463            get
464            {
465                return GetXmlNodeBool("@fieldPrintTitles");
466            }
467            set
468            {
469                SetXmlNodeBool("@fieldPrintTitles", value);
470            }
471        }
472        /// <summary>
473        /// If the row and column titles from the PivotTable should be printed.
474        /// </summary>
475        public bool ItemPrintTitles
476        {
477            get
478            {
479                return GetXmlNodeBool("@itemPrintTitles");
480            }
481            set
482            {
483                SetXmlNodeBool("@itemPrintTitles", value);
484            }
485        }
486        /// <summary>
487        /// If the grand totals should be displayed for the PivotTable columns
488        /// </summary>
489        public bool ColumGrandTotals
490        {
491            get
492            {
493                return GetXmlNodeBool("@colGrandTotals");
494            }
495            set
496            {
497                SetXmlNodeBool("@colGrandTotals", value);
498            }
499        }       
500        /// <summary>
501        /// If the grand totals should be displayed for the PivotTable rows
502        /// </summary>
503        public bool RowGrandTotals
504        {
505            get
506            {
507                return GetXmlNodeBool("@rowGrandTotals");
508            }
509            set
510            {
511                SetXmlNodeBool("@rowGrandTotals", value);
512            }
513        }       
514        /// <summary>
515        /// If the drill indicators expand collapse buttons should be printed.
516        /// </summary>
517        public bool PrintDrill
518        {
519            get
520            {
521                return GetXmlNodeBool("@printDrill");
522            }
523            set
524            {
525                SetXmlNodeBool("@printDrill", value);
526            }
527        }       
528        /// <summary>
529        /// Indicates whether to show error messages in cells.
530        /// </summary>
531        public bool ShowError
532        {
533            get
534            {
535                return GetXmlNodeBool("@showError");
536            }
537            set
538            {
539                SetXmlNodeBool("@showError", value);
540            }
541        }       
542        /// <summary>
543        /// The string to be displayed in cells that contain errors.
544        /// </summary>
545        public string ErrorCaption
546        {
547            get
548            {
549                return GetXmlNodeString("@errorCaption");
550            }
551            set
552            {
553                SetXmlNodeString("@errorCaption", value);
554            }
555        }       
556        /// <summary>
557        /// Specifies the name of the value area field header in the PivotTable.
558        /// This caption is shown when the PivotTable when two or more fields are in the values area.
559        /// </summary>
560        public string DataCaption
561        {
562            get
563            {
564                return GetXmlNodeString("@dataCaption");
565            }
566            set
567            {
568                SetXmlNodeString("@dataCaption", value);
569            }
570        }       
571        /// <summary>
572        /// Show field headers
573        /// </summary>
574        public bool ShowHeaders
575        {
576            get
577            {
578                return GetXmlNodeBool("@showHeaders");
579            }
580            set
581            {
582                SetXmlNodeBool("@showHeaders", value);
583            }
584        }
585        /// <summary>
586        /// The number of page fields to display before starting another row or column
587        /// </summary>
588        public int PageWrap
589        {
590            get
591            {
592                return GetXmlNodeInt("@pageWrap");
593            }
594            set
595            {
596                if(value<0)
597                {
598                    throw new Exception("Value can't be negative");
599                }
600                SetXmlNodeString("@pageWrap", value.ToString());
601            }
602        }
603        /// <summary>
604        /// A boolean that indicates whether legacy auto formatting has been applied to the PivotTable view
605        /// </summary>
606        public bool UseAutoFormatting
607        {
608            get
609            {
610                return GetXmlNodeBool("@useAutoFormatting");
611            }
612            set
613            {
614                SetXmlNodeBool("@useAutoFormatting",value);
615            }
616        }
617        /// <summary>
618        /// A boolean that indicates whether the in-grid drop zones should be displayed at runtime, and whether classic layout is applied
619        /// </summary>
620        public bool GridDropZones
621        {
622            get
623            {
624                return GetXmlNodeBool("@gridDropZones");
625            }
626            set
627            {
628                SetXmlNodeBool("@gridDropZones",value);
629            }
630        }
631        /// <summary>
632        /// Specifies the indentation increment for compact axis and can be used to set the Report Layout to Compact Form
633        /// </summary>
634        public int Indent
635        {
636            get
637            {
638                return GetXmlNodeInt("@indent");
639            }
640            set
641            {
642                SetXmlNodeString("@indent",value.ToString());
643            }
644        }
645        /// <summary>
646        /// A boolean that indicates whether data fields in the PivotTable should be displayed in outline form
647        /// </summary>
648        public bool OutlineData
649        {
650            get
651            {
652                return GetXmlNodeBool("@outlineData");
653            }
654            set
655            {
656                SetXmlNodeBool("@outlineData", value);
657            }
658        }
659        /// <summary>
660        /// a boolean that indicates whether new fields should have their outline flag set to true
661        /// </summary>
662        public bool Outline
663        {
664            get
665            {
666                return GetXmlNodeBool("@outline");
667            }
668            set
669            {
670                SetXmlNodeBool("@outline", value);
671            }
672        }
673        /// <summary>
674        /// A boolean that indicates whether the fields of a PivotTable can have multiple filters set on them
675        /// </summary>
676        public bool MultipleFieldFilters
677        {
678            get
679            {
680                return GetXmlNodeBool("@multipleFieldFilters");
681            }
682            set
683            {
684                SetXmlNodeBool("@multipleFieldFilters", value);
685            }
686        }
687        /// <summary>
688        /// A boolean that indicates whether new fields should have their compact flag set to true
689        /// </summary>
690        public bool Compact
691        {
692            get
693            {
694                return GetXmlNodeBool("@compact");
695            }
696            set
697            {
698                SetXmlNodeBool("@compact",value);
699            }
700        }       
701        /// <summary>
702        /// A boolean that indicates whether the field next to the data field in the PivotTable should be displayed in the same column of the spreadsheet
703        /// </summary>
704        public bool CompactData
705        {
706            get
707            {
708                return GetXmlNodeBool("@compactData");
709            }
710            set
711            {
712                SetXmlNodeBool("@compactData",value);
713            }
714        }
715        /// <summary>
716        /// Specifies the string to be displayed for grand totals.
717        /// </summary>
718        public string GrandTotalCaption
719        {
720            get
721            {
722                return GetXmlNodeString("@grandTotalCaption");
723            }
724            set
725            {
726                SetXmlNodeString("@grandTotalCaption", value);
727            }
728        }
729        /// <summary>
730        /// Specifies the string to be displayed in row header in compact mode.
731        /// </summary>
732        public string RowHeaderCaption
733        {
734            get
735            {
736                return GetXmlNodeString("@rowHeaderCaption");
737            }
738            set
739            {
740                SetXmlNodeString("@rowHeaderCaption", value);               
741            }
742        }
743        /// <summary>
744        /// Specifies the string to be displayed in cells with no value
745        /// </summary>
746        public string MissingCaption
747        {
748            get
749            {
750                return GetXmlNodeString("@missingCaption");
751            }
752            set
753            {
754                SetXmlNodeString("@missingCaption", value);               
755            }
756        }
757        const string FIRSTHEADERROW_PATH="d:location/@firstHeaderRow";
758        /// <summary>
759        /// Specifies the first row of the PivotTable header, relative to the top left cell in the ref value
760        /// </summary>
761        public int FirstHeaderRow
762        {
763            get
764            {
765                return GetXmlNodeInt(FIRSTHEADERROW_PATH);
766            }
767            set
768            {
769                SetXmlNodeString(FIRSTHEADERROW_PATH, value.ToString());
770            }
771        }
772        const string FIRSTDATAROW_PATH = "d:location/@firstDataRow";
773        /// <summary>
774        /// Specifies the first column of the PivotTable data, relative to the top left cell in the ref value
775        /// </summary>
776        public int FirstDataRow
777        {
778            get
779            {
780                return GetXmlNodeInt(FIRSTDATAROW_PATH);
781            }
782            set
783            {
784                SetXmlNodeString(FIRSTDATAROW_PATH, value.ToString());
785            }
786        }
787        const string FIRSTDATACOL_PATH = "d:location/@firstDataCol";
788        /// <summary>
789        /// Specifies the first column of the PivotTable data, relative to the top left cell in the ref value
790        /// </summary>
791        public int FirstDataCol
792        {
793            get
794            {
795                return GetXmlNodeInt(FIRSTDATACOL_PATH);
796            }
797            set
798            {
799                SetXmlNodeString(FIRSTDATACOL_PATH, value.ToString());
800            }
801        }
802        ExcelPivotTableFieldCollection _fields = null;
803        /// <summary>
804        /// The fields in the table
805        /// </summary>
806        public ExcelPivotTableFieldCollection Fields
807        {
808            get
809            {
810                if (_fields == null)
811                {
812                    _fields = new ExcelPivotTableFieldCollection(this, "");
813                }
814                return _fields;
815            }
816        }
817        ExcelPivotTableRowColumnFieldCollection _rowFields = null;
818        /// <summary>
819        /// Row label fields
820        /// </summary>
821        public ExcelPivotTableRowColumnFieldCollection RowFields
822        {
823            get
824            {
825                if (_rowFields == null)
826                {
827                    _rowFields = new ExcelPivotTableRowColumnFieldCollection(this, "rowFields");
828                }
829                return _rowFields;
830            }
831        }
832        ExcelPivotTableRowColumnFieldCollection _columnFields = null;
833        /// <summary>
834        /// Column label fields
835        /// </summary>
836        public ExcelPivotTableRowColumnFieldCollection ColumnFields
837        {
838            get
839            {
840                if (_columnFields == null)
841                {
842                    _columnFields = new ExcelPivotTableRowColumnFieldCollection(this, "colFields");
843                }
844                return _columnFields;
845            }
846        }
847        ExcelPivotTableDataFieldCollection _dataFields = null;
848        /// <summary>
849        /// Value fields
850        /// </summary>
851        public ExcelPivotTableDataFieldCollection DataFields
852        {
853            get
854            {
855                if (_dataFields == null)
856                {
857                    _dataFields = new ExcelPivotTableDataFieldCollection(this);
858                }
859                return _dataFields;
860            }
861        }
862        ExcelPivotTableRowColumnFieldCollection _pageFields = null;
863        /// <summary>
864        /// Report filter fields
865        /// </summary>
866        public ExcelPivotTableRowColumnFieldCollection PageFields
867        {
868            get
869            {
870                if (_pageFields == null)
871                {
872                    _pageFields = new ExcelPivotTableRowColumnFieldCollection(this, "pageFields");
873                }
874                return _pageFields;
875            }
876        }
877        const string STYLENAME_PATH = "d:pivotTableStyleInfo/@name";
878        /// <summary>
879        /// Pivot style name. Used for custom styles
880        /// </summary>
881        public string StyleName
882        {
883            get
884            {
885                return GetXmlNodeString(StyleName);
886            }
887            set
888            {
889                if (value.StartsWith("PivotStyle"))
890                {
891                    try
892                    {
893                        _tableStyle = (TableStyles)Enum.Parse(typeof(TableStyles), value.Substring(10, value.Length - 10), true);
894                    }
895                    catch
896                    {
897                        _tableStyle = TableStyles.Custom;
898                    }
899                }
900                else if (value == "None")
901                {
902                    _tableStyle = TableStyles.None;
903                    value = "";
904                }
905                else
906                {
907                    _tableStyle = TableStyles.Custom;
908                }
909                SetXmlNodeString(STYLENAME_PATH, value, true);
910            }
911        }
912        TableStyles _tableStyle = Table.TableStyles.Medium6;
913        /// <summary>
914        /// The table style. If this property is cusom the style from the StyleName propery is used.
915        /// </summary>
916        public TableStyles TableStyle
917        {
918            get
919            {
920                return _tableStyle;
921            }
922            set
923            {
924                _tableStyle=value;
925                if (value != TableStyles.Custom)
926                {
927                    SetXmlNodeString(STYLENAME_PATH, "PivotStyle" + value.ToString());
928                }
929            }
930        }
931
932        #endregion
933        #region "Internal Properties"
934        internal int CacheID
935        {
936                get
937                {
938                    return GetXmlNodeInt("@cacheId");
939                }
940                set
941                {
942                    SetXmlNodeString("@cacheId",value.ToString());
943                }
944        }
945
946        #endregion
947
948    }
949}
Note: See TracBrowser for help on using the repository browser.