[12074] | 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 | *******************************************************************************/
|
---|
| 32 | using System;
|
---|
| 33 | using System.Collections.Generic;
|
---|
| 34 | using System.Text;
|
---|
| 35 | using System.Xml;
|
---|
| 36 | using System.Text.RegularExpressions;
|
---|
| 37 | using OfficeOpenXml.Table;
|
---|
| 38 | using OfficeOpenXml.Utils;
|
---|
| 39 |
|
---|
| 40 | namespace OfficeOpenXml.Table.PivotTable
|
---|
| 41 | {
|
---|
| 42 | /// <summary>
|
---|
| 43 | /// An Excel Pivottable
|
---|
| 44 | /// </summary>
|
---|
| 45 | public class ExcelPivotTable : XmlHelper
|
---|
| 46 | {
|
---|
| 47 | internal ExcelPivotTable(Packaging.ZipPackageRelationship rel, ExcelWorksheet sheet) :
|
---|
| 48 | base(sheet.NameSpaceManager)
|
---|
| 49 | {
|
---|
| 50 | WorkSheet = sheet;
|
---|
| 51 | PivotTableUri = UriHelper.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(UriHelper.ResolvePartUri(sheet.WorksheetUri, PivotTableUri), Packaging.TargetMode.Internal, ExcelPackage.schemaRelationships + "/pivotTable");
|
---|
| 145 |
|
---|
| 146 | _cacheDefinition = new ExcelPivotCacheDefinition(sheet.NameSpaceManager, this, sourceAddress, tblId);
|
---|
| 147 | _cacheDefinition.Relationship=Part.CreateRelationship(UriHelper.ResolvePartUri(PivotTableUri, _cacheDefinition.CacheDefinitionUri), Packaging.TargetMode.Internal, ExcelPackage.schemaRelationships + "/pivotCacheDefinition");
|
---|
| 148 |
|
---|
| 149 | sheet.Workbook.AddPivotTable(CacheID.ToString(), _cacheDefinition.CacheDefinitionUri);
|
---|
| 150 |
|
---|
| 151 | LoadFields();
|
---|
| 152 |
|
---|
[12707] | 153 | sheet.Cells[address.Address].Clear();
|
---|
[12074] | 154 | }
|
---|
| 155 | private void init()
|
---|
| 156 | {
|
---|
| 157 | SchemaNodeOrder = new string[] { "location", "pivotFields", "rowFields", "rowItems", "colFields", "colItems", "pageFields", "pageItems", "dataFields", "dataItems", "formats", "pivotTableStyleInfo" };
|
---|
| 158 | }
|
---|
| 159 | private void LoadFields()
|
---|
| 160 | {
|
---|
| 161 | //Fields.Clear();
|
---|
| 162 | //int ix=0;
|
---|
| 163 | //foreach(XmlElement fieldNode in PivotXml.SelectNodes("//d:pivotFields/d:pivotField",NameSpaceManager))
|
---|
| 164 | //{
|
---|
| 165 | // Fields.AddInternal(new ExcelPivotTableField(NameSpaceManager, fieldNode, this, ix++));
|
---|
| 166 | //}
|
---|
| 167 |
|
---|
| 168 | int index = 0;
|
---|
| 169 | //Add fields.
|
---|
| 170 | foreach (XmlElement fieldElem in TopNode.SelectNodes("d:pivotFields/d:pivotField", NameSpaceManager))
|
---|
| 171 | {
|
---|
| 172 | var fld = new ExcelPivotTableField(NameSpaceManager, fieldElem, this, index, index++);
|
---|
| 173 | Fields.AddInternal(fld);
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | //Add fields.
|
---|
| 177 | index = 0;
|
---|
| 178 | foreach (XmlElement fieldElem in _cacheDefinition.TopNode.SelectNodes("d:cacheFields/d:cacheField", NameSpaceManager))
|
---|
| 179 | {
|
---|
| 180 | var fld = Fields[index++];
|
---|
| 181 | fld.SetCacheFieldNode(fieldElem);
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 |
|
---|
| 185 | }
|
---|
| 186 | private string GetStartXml(string name, int id, ExcelAddressBase address, ExcelAddressBase sourceAddress)
|
---|
| 187 | {
|
---|
| 188 | 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);
|
---|
| 189 |
|
---|
| 190 | xml += string.Format("<location ref=\"{0}\" firstHeaderRow=\"1\" firstDataRow=\"1\" firstDataCol=\"1\" /> ", address.FirstAddress);
|
---|
| 191 | xml += string.Format("<pivotFields count=\"{0}\">", sourceAddress._toCol-sourceAddress._fromCol+1);
|
---|
| 192 | for (int col = sourceAddress._fromCol; col <= sourceAddress._toCol; col++)
|
---|
| 193 | {
|
---|
| 194 | xml += "<pivotField showAll=\"0\" />"; //compact=\"0\" outline=\"0\" subtotalTop=\"0\" includeNewItemsInFilter=\"1\"
|
---|
| 195 | }
|
---|
| 196 |
|
---|
| 197 | xml += "</pivotFields>";
|
---|
| 198 | xml += "<pivotTableStyleInfo name=\"PivotStyleMedium9\" showRowHeaders=\"1\" showColHeaders=\"1\" showRowStripes=\"0\" showColStripes=\"0\" showLastColumn=\"1\" />";
|
---|
| 199 | xml += "</pivotTableDefinition>";
|
---|
| 200 | return xml;
|
---|
| 201 | }
|
---|
| 202 | internal Packaging.ZipPackagePart Part
|
---|
| 203 | {
|
---|
| 204 | get;
|
---|
| 205 | set;
|
---|
| 206 | }
|
---|
| 207 | /// <summary>
|
---|
| 208 | /// Provides access to the XML data representing the pivottable in the package.
|
---|
| 209 | /// </summary>
|
---|
| 210 | public XmlDocument PivotTableXml { get; private set; }
|
---|
| 211 | /// <summary>
|
---|
| 212 | /// The package internal URI to the pivottable Xml Document.
|
---|
| 213 | /// </summary>
|
---|
| 214 | public Uri PivotTableUri
|
---|
| 215 | {
|
---|
| 216 | get;
|
---|
| 217 | internal set;
|
---|
| 218 | }
|
---|
| 219 | internal Packaging.ZipPackageRelationship Relationship
|
---|
| 220 | {
|
---|
| 221 | get;
|
---|
| 222 | set;
|
---|
| 223 | }
|
---|
| 224 | const string ID_PATH = "@id";
|
---|
| 225 | internal int Id
|
---|
| 226 | {
|
---|
| 227 | get
|
---|
| 228 | {
|
---|
| 229 | return GetXmlNodeInt(ID_PATH);
|
---|
| 230 | }
|
---|
| 231 | set
|
---|
| 232 | {
|
---|
| 233 | SetXmlNodeString(ID_PATH, value.ToString());
|
---|
| 234 | }
|
---|
| 235 | }
|
---|
| 236 | const string NAME_PATH = "@name";
|
---|
| 237 | const string DISPLAY_NAME_PATH = "@displayName";
|
---|
| 238 | /// <summary>
|
---|
| 239 | /// Name of the pivottable object in Excel
|
---|
| 240 | /// </summary>
|
---|
| 241 | public string Name
|
---|
| 242 | {
|
---|
| 243 | get
|
---|
| 244 | {
|
---|
| 245 | return GetXmlNodeString(NAME_PATH);
|
---|
| 246 | }
|
---|
| 247 | set
|
---|
| 248 | {
|
---|
| 249 | if (WorkSheet.Workbook.ExistsTableName(value))
|
---|
| 250 | {
|
---|
| 251 | throw (new ArgumentException("PivotTable name is not unique"));
|
---|
| 252 | }
|
---|
| 253 | string prevName = Name;
|
---|
| 254 | if (WorkSheet.Tables._tableNames.ContainsKey(prevName))
|
---|
| 255 | {
|
---|
| 256 | int ix = WorkSheet.Tables._tableNames[prevName];
|
---|
| 257 | WorkSheet.Tables._tableNames.Remove(prevName);
|
---|
| 258 | WorkSheet.Tables._tableNames.Add(value, ix);
|
---|
| 259 | }
|
---|
| 260 | SetXmlNodeString(NAME_PATH, value);
|
---|
| 261 | SetXmlNodeString(DISPLAY_NAME_PATH, cleanDisplayName(value));
|
---|
| 262 | }
|
---|
| 263 | }
|
---|
| 264 | ExcelPivotCacheDefinition _cacheDefinition = null;
|
---|
| 265 | /// <summary>
|
---|
| 266 | /// Reference to the pivot table cache definition object
|
---|
| 267 | /// </summary>
|
---|
| 268 | public ExcelPivotCacheDefinition CacheDefinition
|
---|
| 269 | {
|
---|
| 270 | get
|
---|
| 271 | {
|
---|
| 272 | if (_cacheDefinition == null)
|
---|
| 273 | {
|
---|
| 274 | _cacheDefinition = new ExcelPivotCacheDefinition(NameSpaceManager, this, null, 1);
|
---|
| 275 | }
|
---|
| 276 | return _cacheDefinition;
|
---|
| 277 | }
|
---|
| 278 | }
|
---|
| 279 | private string cleanDisplayName(string name)
|
---|
| 280 | {
|
---|
| 281 | return Regex.Replace(name, @"[^\w\.-_]", "_");
|
---|
| 282 | }
|
---|
| 283 | #region "Public Properties"
|
---|
| 284 |
|
---|
| 285 | /// <summary>
|
---|
| 286 | /// The worksheet where the pivottable is located
|
---|
| 287 | /// </summary>
|
---|
| 288 | public ExcelWorksheet WorkSheet
|
---|
| 289 | {
|
---|
| 290 | get;
|
---|
| 291 | set;
|
---|
| 292 | }
|
---|
| 293 | /// <summary>
|
---|
| 294 | /// The location of the pivot table
|
---|
| 295 | /// </summary>
|
---|
| 296 | public ExcelAddressBase Address
|
---|
| 297 | {
|
---|
| 298 | get;
|
---|
| 299 | internal set;
|
---|
| 300 | }
|
---|
| 301 | /// <summary>
|
---|
| 302 | /// If multiple datafields are displayed in the row area or the column area
|
---|
| 303 | /// </summary>
|
---|
| 304 | public bool DataOnRows
|
---|
| 305 | {
|
---|
| 306 | get
|
---|
| 307 | {
|
---|
| 308 | return GetXmlNodeBool("@dataOnRows");
|
---|
| 309 | }
|
---|
| 310 | set
|
---|
| 311 | {
|
---|
| 312 | SetXmlNodeBool("@dataOnRows",value);
|
---|
| 313 | }
|
---|
| 314 | }
|
---|
| 315 | /// <summary>
|
---|
| 316 | /// if true apply legacy table autoformat number format properties.
|
---|
| 317 | /// </summary>
|
---|
| 318 | public bool ApplyNumberFormats
|
---|
| 319 | {
|
---|
| 320 | get
|
---|
| 321 | {
|
---|
| 322 | return GetXmlNodeBool("@applyNumberFormats");
|
---|
| 323 | }
|
---|
| 324 | set
|
---|
| 325 | {
|
---|
| 326 | SetXmlNodeBool("@applyNumberFormats",value);
|
---|
| 327 | }
|
---|
| 328 | }
|
---|
| 329 | /// <summary>
|
---|
| 330 | /// If true apply legacy table autoformat border properties
|
---|
| 331 | /// </summary>
|
---|
| 332 | public bool ApplyBorderFormats
|
---|
| 333 | {
|
---|
| 334 | get
|
---|
| 335 | {
|
---|
| 336 | return GetXmlNodeBool("@applyBorderFormats");
|
---|
| 337 | }
|
---|
| 338 | set
|
---|
| 339 | {
|
---|
| 340 | SetXmlNodeBool("@applyBorderFormats",value);
|
---|
| 341 | }
|
---|
| 342 | }
|
---|
| 343 | /// <summary>
|
---|
| 344 | /// If true apply legacy table autoformat font properties
|
---|
| 345 | /// </summary>
|
---|
| 346 | public bool ApplyFontFormats
|
---|
| 347 | {
|
---|
| 348 | get
|
---|
| 349 | {
|
---|
| 350 | return GetXmlNodeBool("@applyFontFormats");
|
---|
| 351 | }
|
---|
| 352 | set
|
---|
| 353 | {
|
---|
| 354 | SetXmlNodeBool("@applyFontFormats",value);
|
---|
| 355 | }
|
---|
| 356 | }
|
---|
| 357 | /// <summary>
|
---|
| 358 | /// If true apply legacy table autoformat pattern properties
|
---|
| 359 | /// </summary>
|
---|
| 360 | public bool ApplyPatternFormats
|
---|
| 361 | {
|
---|
| 362 | get
|
---|
| 363 | {
|
---|
| 364 | return GetXmlNodeBool("@applyPatternFormats");
|
---|
| 365 | }
|
---|
| 366 | set
|
---|
| 367 | {
|
---|
| 368 | SetXmlNodeBool("@applyPatternFormats",value);
|
---|
| 369 | }
|
---|
| 370 | }
|
---|
| 371 | /// <summary>
|
---|
| 372 | /// If true apply legacy table autoformat width/height properties.
|
---|
| 373 | /// </summary>
|
---|
| 374 | public bool ApplyWidthHeightFormats
|
---|
| 375 | {
|
---|
| 376 | get
|
---|
| 377 | {
|
---|
| 378 | return GetXmlNodeBool("@applyWidthHeightFormats");
|
---|
| 379 | }
|
---|
| 380 | set
|
---|
| 381 | {
|
---|
| 382 | SetXmlNodeBool("@applyWidthHeightFormats",value);
|
---|
| 383 | }
|
---|
| 384 | }
|
---|
| 385 | /// <summary>
|
---|
| 386 | /// Show member property information
|
---|
| 387 | /// </summary>
|
---|
| 388 | public bool ShowMemberPropertyTips
|
---|
| 389 | {
|
---|
| 390 | get
|
---|
| 391 | {
|
---|
| 392 | return GetXmlNodeBool("@showMemberPropertyTips");
|
---|
| 393 | }
|
---|
| 394 | set
|
---|
| 395 | {
|
---|
| 396 | SetXmlNodeBool("@showMemberPropertyTips",value);
|
---|
| 397 | }
|
---|
| 398 | }
|
---|
| 399 | /// <summary>
|
---|
| 400 | /// Show the drill indicators
|
---|
| 401 | /// </summary>
|
---|
| 402 | public bool ShowCalcMember
|
---|
| 403 | {
|
---|
| 404 | get
|
---|
| 405 | {
|
---|
| 406 | return GetXmlNodeBool("@showCalcMbrs");
|
---|
| 407 | }
|
---|
| 408 | set
|
---|
| 409 | {
|
---|
| 410 | SetXmlNodeBool("@showCalcMbrs", value);
|
---|
| 411 | }
|
---|
| 412 | }
|
---|
| 413 | /// <summary>
|
---|
| 414 | /// If the user is prevented from drilling down on a PivotItem or aggregate value
|
---|
| 415 | /// </summary>
|
---|
| 416 | public bool EnableDrill
|
---|
| 417 | {
|
---|
| 418 | get
|
---|
| 419 | {
|
---|
| 420 | return GetXmlNodeBool("@enableDrill", true);
|
---|
| 421 | }
|
---|
| 422 | set
|
---|
| 423 | {
|
---|
| 424 | SetXmlNodeBool("@enableDrill", value);
|
---|
| 425 | }
|
---|
| 426 | }
|
---|
| 427 | /// <summary>
|
---|
| 428 | /// Show the drill down buttons
|
---|
| 429 | /// </summary>
|
---|
| 430 | public bool ShowDrill
|
---|
| 431 | {
|
---|
| 432 | get
|
---|
| 433 | {
|
---|
| 434 | return GetXmlNodeBool("@showDrill", true);
|
---|
| 435 | }
|
---|
| 436 | set
|
---|
| 437 | {
|
---|
| 438 | SetXmlNodeBool("@showDrill", value);
|
---|
| 439 | }
|
---|
| 440 | }
|
---|
| 441 | /// <summary>
|
---|
| 442 | /// If the tooltips should be displayed for PivotTable data cells.
|
---|
| 443 | /// </summary>
|
---|
| 444 | public bool ShowDataTips
|
---|
| 445 | {
|
---|
| 446 | get
|
---|
| 447 | {
|
---|
| 448 | return GetXmlNodeBool("@showDataTips", true);
|
---|
| 449 | }
|
---|
| 450 | set
|
---|
| 451 | {
|
---|
| 452 | SetXmlNodeBool("@showDataTips", value, true);
|
---|
| 453 | }
|
---|
| 454 | }
|
---|
| 455 | /// <summary>
|
---|
| 456 | /// If the row and column titles from the PivotTable should be printed.
|
---|
| 457 | /// </summary>
|
---|
| 458 | public bool FieldPrintTitles
|
---|
| 459 | {
|
---|
| 460 | get
|
---|
| 461 | {
|
---|
| 462 | return GetXmlNodeBool("@fieldPrintTitles");
|
---|
| 463 | }
|
---|
| 464 | set
|
---|
| 465 | {
|
---|
| 466 | SetXmlNodeBool("@fieldPrintTitles", value);
|
---|
| 467 | }
|
---|
| 468 | }
|
---|
| 469 | /// <summary>
|
---|
| 470 | /// If the row and column titles from the PivotTable should be printed.
|
---|
| 471 | /// </summary>
|
---|
| 472 | public bool ItemPrintTitles
|
---|
| 473 | {
|
---|
| 474 | get
|
---|
| 475 | {
|
---|
| 476 | return GetXmlNodeBool("@itemPrintTitles");
|
---|
| 477 | }
|
---|
| 478 | set
|
---|
| 479 | {
|
---|
| 480 | SetXmlNodeBool("@itemPrintTitles", value);
|
---|
| 481 | }
|
---|
| 482 | }
|
---|
| 483 | /// <summary>
|
---|
| 484 | /// If the grand totals should be displayed for the PivotTable columns
|
---|
| 485 | /// </summary>
|
---|
| 486 | public bool ColumGrandTotals
|
---|
| 487 | {
|
---|
| 488 | get
|
---|
| 489 | {
|
---|
| 490 | return GetXmlNodeBool("@colGrandTotals");
|
---|
| 491 | }
|
---|
| 492 | set
|
---|
| 493 | {
|
---|
| 494 | SetXmlNodeBool("@colGrandTotals", value);
|
---|
| 495 | }
|
---|
| 496 | }
|
---|
| 497 | /// <summary>
|
---|
| 498 | /// If the grand totals should be displayed for the PivotTable rows
|
---|
| 499 | /// </summary>
|
---|
| 500 | public bool RowGrandTotals
|
---|
| 501 | {
|
---|
| 502 | get
|
---|
| 503 | {
|
---|
| 504 | return GetXmlNodeBool("@rowGrandTotals");
|
---|
| 505 | }
|
---|
| 506 | set
|
---|
| 507 | {
|
---|
| 508 | SetXmlNodeBool("@rowGrandTotals", value);
|
---|
| 509 | }
|
---|
| 510 | }
|
---|
| 511 | /// <summary>
|
---|
| 512 | /// If the drill indicators expand collapse buttons should be printed.
|
---|
| 513 | /// </summary>
|
---|
| 514 | public bool PrintDrill
|
---|
| 515 | {
|
---|
| 516 | get
|
---|
| 517 | {
|
---|
| 518 | return GetXmlNodeBool("@printDrill");
|
---|
| 519 | }
|
---|
| 520 | set
|
---|
| 521 | {
|
---|
| 522 | SetXmlNodeBool("@printDrill", value);
|
---|
| 523 | }
|
---|
| 524 | }
|
---|
| 525 | /// <summary>
|
---|
| 526 | /// Indicates whether to show error messages in cells.
|
---|
| 527 | /// </summary>
|
---|
| 528 | public bool ShowError
|
---|
| 529 | {
|
---|
| 530 | get
|
---|
| 531 | {
|
---|
| 532 | return GetXmlNodeBool("@showError");
|
---|
| 533 | }
|
---|
| 534 | set
|
---|
| 535 | {
|
---|
| 536 | SetXmlNodeBool("@showError", value);
|
---|
| 537 | }
|
---|
| 538 | }
|
---|
| 539 | /// <summary>
|
---|
| 540 | /// The string to be displayed in cells that contain errors.
|
---|
| 541 | /// </summary>
|
---|
| 542 | public string ErrorCaption
|
---|
| 543 | {
|
---|
| 544 | get
|
---|
| 545 | {
|
---|
| 546 | return GetXmlNodeString("@errorCaption");
|
---|
| 547 | }
|
---|
| 548 | set
|
---|
| 549 | {
|
---|
| 550 | SetXmlNodeString("@errorCaption", value);
|
---|
| 551 | }
|
---|
| 552 | }
|
---|
| 553 | /// <summary>
|
---|
| 554 | /// Specifies the name of the value area field header in the PivotTable.
|
---|
| 555 | /// This caption is shown when the PivotTable when two or more fields are in the values area.
|
---|
| 556 | /// </summary>
|
---|
| 557 | public string DataCaption
|
---|
| 558 | {
|
---|
| 559 | get
|
---|
| 560 | {
|
---|
| 561 | return GetXmlNodeString("@dataCaption");
|
---|
| 562 | }
|
---|
| 563 | set
|
---|
| 564 | {
|
---|
| 565 | SetXmlNodeString("@dataCaption", value);
|
---|
| 566 | }
|
---|
| 567 | }
|
---|
| 568 | /// <summary>
|
---|
| 569 | /// Show field headers
|
---|
| 570 | /// </summary>
|
---|
| 571 | public bool ShowHeaders
|
---|
| 572 | {
|
---|
| 573 | get
|
---|
| 574 | {
|
---|
| 575 | return GetXmlNodeBool("@showHeaders");
|
---|
| 576 | }
|
---|
| 577 | set
|
---|
| 578 | {
|
---|
| 579 | SetXmlNodeBool("@showHeaders", value);
|
---|
| 580 | }
|
---|
| 581 | }
|
---|
| 582 | /// <summary>
|
---|
| 583 | /// The number of page fields to display before starting another row or column
|
---|
| 584 | /// </summary>
|
---|
| 585 | public int PageWrap
|
---|
| 586 | {
|
---|
| 587 | get
|
---|
| 588 | {
|
---|
| 589 | return GetXmlNodeInt("@pageWrap");
|
---|
| 590 | }
|
---|
| 591 | set
|
---|
| 592 | {
|
---|
| 593 | if(value<0)
|
---|
| 594 | {
|
---|
| 595 | throw new Exception("Value can't be negative");
|
---|
| 596 | }
|
---|
| 597 | SetXmlNodeString("@pageWrap", value.ToString());
|
---|
| 598 | }
|
---|
| 599 | }
|
---|
| 600 | /// <summary>
|
---|
| 601 | /// A boolean that indicates whether legacy auto formatting has been applied to the PivotTable view
|
---|
| 602 | /// </summary>
|
---|
| 603 | public bool UseAutoFormatting
|
---|
| 604 | {
|
---|
| 605 | get
|
---|
| 606 | {
|
---|
| 607 | return GetXmlNodeBool("@useAutoFormatting");
|
---|
| 608 | }
|
---|
| 609 | set
|
---|
| 610 | {
|
---|
| 611 | SetXmlNodeBool("@useAutoFormatting",value);
|
---|
| 612 | }
|
---|
| 613 | }
|
---|
| 614 | /// <summary>
|
---|
| 615 | /// A boolean that indicates whether the in-grid drop zones should be displayed at runtime, and whether classic layout is applied
|
---|
| 616 | /// </summary>
|
---|
| 617 | public bool GridDropZones
|
---|
| 618 | {
|
---|
| 619 | get
|
---|
| 620 | {
|
---|
| 621 | return GetXmlNodeBool("@gridDropZones");
|
---|
| 622 | }
|
---|
| 623 | set
|
---|
| 624 | {
|
---|
| 625 | SetXmlNodeBool("@gridDropZones",value);
|
---|
| 626 | }
|
---|
| 627 | }
|
---|
| 628 | /// <summary>
|
---|
| 629 | /// Specifies the indentation increment for compact axis and can be used to set the Report Layout to Compact Form
|
---|
| 630 | /// </summary>
|
---|
| 631 | public int Indent
|
---|
| 632 | {
|
---|
| 633 | get
|
---|
| 634 | {
|
---|
| 635 | return GetXmlNodeInt("@indent");
|
---|
| 636 | }
|
---|
| 637 | set
|
---|
| 638 | {
|
---|
| 639 | SetXmlNodeString("@indent",value.ToString());
|
---|
| 640 | }
|
---|
| 641 | }
|
---|
| 642 | /// <summary>
|
---|
| 643 | /// A boolean that indicates whether data fields in the PivotTable should be displayed in outline form
|
---|
| 644 | /// </summary>
|
---|
| 645 | public bool OutlineData
|
---|
| 646 | {
|
---|
| 647 | get
|
---|
| 648 | {
|
---|
| 649 | return GetXmlNodeBool("@outlineData");
|
---|
| 650 | }
|
---|
| 651 | set
|
---|
| 652 | {
|
---|
| 653 | SetXmlNodeBool("@outlineData", value);
|
---|
| 654 | }
|
---|
| 655 | }
|
---|
| 656 | /// <summary>
|
---|
| 657 | /// a boolean that indicates whether new fields should have their outline flag set to true
|
---|
| 658 | /// </summary>
|
---|
| 659 | public bool Outline
|
---|
| 660 | {
|
---|
| 661 | get
|
---|
| 662 | {
|
---|
| 663 | return GetXmlNodeBool("@outline");
|
---|
| 664 | }
|
---|
| 665 | set
|
---|
| 666 | {
|
---|
| 667 | SetXmlNodeBool("@outline", value);
|
---|
| 668 | }
|
---|
| 669 | }
|
---|
| 670 | /// <summary>
|
---|
| 671 | /// A boolean that indicates whether the fields of a PivotTable can have multiple filters set on them
|
---|
| 672 | /// </summary>
|
---|
| 673 | public bool MultipleFieldFilters
|
---|
| 674 | {
|
---|
| 675 | get
|
---|
| 676 | {
|
---|
| 677 | return GetXmlNodeBool("@multipleFieldFilters");
|
---|
| 678 | }
|
---|
| 679 | set
|
---|
| 680 | {
|
---|
| 681 | SetXmlNodeBool("@multipleFieldFilters", value);
|
---|
| 682 | }
|
---|
| 683 | }
|
---|
| 684 | /// <summary>
|
---|
| 685 | /// A boolean that indicates whether new fields should have their compact flag set to true
|
---|
| 686 | /// </summary>
|
---|
| 687 | public bool Compact
|
---|
| 688 | {
|
---|
| 689 | get
|
---|
| 690 | {
|
---|
| 691 | return GetXmlNodeBool("@compact");
|
---|
| 692 | }
|
---|
| 693 | set
|
---|
| 694 | {
|
---|
| 695 | SetXmlNodeBool("@compact",value);
|
---|
| 696 | }
|
---|
| 697 | }
|
---|
| 698 | /// <summary>
|
---|
| 699 | /// 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
|
---|
| 700 | /// </summary>
|
---|
| 701 | public bool CompactData
|
---|
| 702 | {
|
---|
| 703 | get
|
---|
| 704 | {
|
---|
| 705 | return GetXmlNodeBool("@compactData");
|
---|
| 706 | }
|
---|
| 707 | set
|
---|
| 708 | {
|
---|
| 709 | SetXmlNodeBool("@compactData",value);
|
---|
| 710 | }
|
---|
| 711 | }
|
---|
| 712 | /// <summary>
|
---|
| 713 | /// Specifies the string to be displayed for grand totals.
|
---|
| 714 | /// </summary>
|
---|
| 715 | public string GrandTotalCaption
|
---|
| 716 | {
|
---|
| 717 | get
|
---|
| 718 | {
|
---|
| 719 | return GetXmlNodeString("@grandTotalCaption");
|
---|
| 720 | }
|
---|
| 721 | set
|
---|
| 722 | {
|
---|
| 723 | SetXmlNodeString("@grandTotalCaption", value);
|
---|
| 724 | }
|
---|
| 725 | }
|
---|
| 726 | /// <summary>
|
---|
| 727 | /// Specifies the string to be displayed in row header in compact mode.
|
---|
| 728 | /// </summary>
|
---|
| 729 | public string RowHeaderCaption
|
---|
| 730 | {
|
---|
| 731 | get
|
---|
| 732 | {
|
---|
| 733 | return GetXmlNodeString("@rowHeaderCaption");
|
---|
| 734 | }
|
---|
| 735 | set
|
---|
| 736 | {
|
---|
| 737 | SetXmlNodeString("@rowHeaderCaption", value);
|
---|
| 738 | }
|
---|
| 739 | }
|
---|
| 740 | /// <summary>
|
---|
| 741 | /// Specifies the string to be displayed in cells with no value
|
---|
| 742 | /// </summary>
|
---|
| 743 | public string MissingCaption
|
---|
| 744 | {
|
---|
| 745 | get
|
---|
| 746 | {
|
---|
| 747 | return GetXmlNodeString("@missingCaption");
|
---|
| 748 | }
|
---|
| 749 | set
|
---|
| 750 | {
|
---|
| 751 | SetXmlNodeString("@missingCaption", value);
|
---|
| 752 | }
|
---|
| 753 | }
|
---|
| 754 | const string FIRSTHEADERROW_PATH="d:location/@firstHeaderRow";
|
---|
| 755 | /// <summary>
|
---|
| 756 | /// Specifies the first row of the PivotTable header, relative to the top left cell in the ref value
|
---|
| 757 | /// </summary>
|
---|
| 758 | public int FirstHeaderRow
|
---|
| 759 | {
|
---|
| 760 | get
|
---|
| 761 | {
|
---|
| 762 | return GetXmlNodeInt(FIRSTHEADERROW_PATH);
|
---|
| 763 | }
|
---|
| 764 | set
|
---|
| 765 | {
|
---|
| 766 | SetXmlNodeString(FIRSTHEADERROW_PATH, value.ToString());
|
---|
| 767 | }
|
---|
| 768 | }
|
---|
| 769 | const string FIRSTDATAROW_PATH = "d:location/@firstDataRow";
|
---|
| 770 | /// <summary>
|
---|
| 771 | /// Specifies the first column of the PivotTable data, relative to the top left cell in the ref value
|
---|
| 772 | /// </summary>
|
---|
| 773 | public int FirstDataRow
|
---|
| 774 | {
|
---|
| 775 | get
|
---|
| 776 | {
|
---|
| 777 | return GetXmlNodeInt(FIRSTDATAROW_PATH);
|
---|
| 778 | }
|
---|
| 779 | set
|
---|
| 780 | {
|
---|
| 781 | SetXmlNodeString(FIRSTDATAROW_PATH, value.ToString());
|
---|
| 782 | }
|
---|
| 783 | }
|
---|
| 784 | const string FIRSTDATACOL_PATH = "d:location/@firstDataCol";
|
---|
| 785 | /// <summary>
|
---|
| 786 | /// Specifies the first column of the PivotTable data, relative to the top left cell in the ref value
|
---|
| 787 | /// </summary>
|
---|
| 788 | public int FirstDataCol
|
---|
| 789 | {
|
---|
| 790 | get
|
---|
| 791 | {
|
---|
| 792 | return GetXmlNodeInt(FIRSTDATACOL_PATH);
|
---|
| 793 | }
|
---|
| 794 | set
|
---|
| 795 | {
|
---|
| 796 | SetXmlNodeString(FIRSTDATACOL_PATH, value.ToString());
|
---|
| 797 | }
|
---|
| 798 | }
|
---|
| 799 | ExcelPivotTableFieldCollection _fields = null;
|
---|
| 800 | /// <summary>
|
---|
| 801 | /// The fields in the table
|
---|
| 802 | /// </summary>
|
---|
| 803 | public ExcelPivotTableFieldCollection Fields
|
---|
| 804 | {
|
---|
| 805 | get
|
---|
| 806 | {
|
---|
| 807 | if (_fields == null)
|
---|
| 808 | {
|
---|
| 809 | _fields = new ExcelPivotTableFieldCollection(this, "");
|
---|
| 810 | }
|
---|
| 811 | return _fields;
|
---|
| 812 | }
|
---|
| 813 | }
|
---|
| 814 | ExcelPivotTableRowColumnFieldCollection _rowFields = null;
|
---|
| 815 | /// <summary>
|
---|
| 816 | /// Row label fields
|
---|
| 817 | /// </summary>
|
---|
| 818 | public ExcelPivotTableRowColumnFieldCollection RowFields
|
---|
| 819 | {
|
---|
| 820 | get
|
---|
| 821 | {
|
---|
| 822 | if (_rowFields == null)
|
---|
| 823 | {
|
---|
| 824 | _rowFields = new ExcelPivotTableRowColumnFieldCollection(this, "rowFields");
|
---|
| 825 | }
|
---|
| 826 | return _rowFields;
|
---|
| 827 | }
|
---|
| 828 | }
|
---|
| 829 | ExcelPivotTableRowColumnFieldCollection _columnFields = null;
|
---|
| 830 | /// <summary>
|
---|
| 831 | /// Column label fields
|
---|
| 832 | /// </summary>
|
---|
| 833 | public ExcelPivotTableRowColumnFieldCollection ColumnFields
|
---|
| 834 | {
|
---|
| 835 | get
|
---|
| 836 | {
|
---|
| 837 | if (_columnFields == null)
|
---|
| 838 | {
|
---|
| 839 | _columnFields = new ExcelPivotTableRowColumnFieldCollection(this, "colFields");
|
---|
| 840 | }
|
---|
| 841 | return _columnFields;
|
---|
| 842 | }
|
---|
| 843 | }
|
---|
| 844 | ExcelPivotTableDataFieldCollection _dataFields = null;
|
---|
| 845 | /// <summary>
|
---|
| 846 | /// Value fields
|
---|
| 847 | /// </summary>
|
---|
| 848 | public ExcelPivotTableDataFieldCollection DataFields
|
---|
| 849 | {
|
---|
| 850 | get
|
---|
| 851 | {
|
---|
| 852 | if (_dataFields == null)
|
---|
| 853 | {
|
---|
| 854 | _dataFields = new ExcelPivotTableDataFieldCollection(this);
|
---|
| 855 | }
|
---|
| 856 | return _dataFields;
|
---|
| 857 | }
|
---|
| 858 | }
|
---|
| 859 | ExcelPivotTableRowColumnFieldCollection _pageFields = null;
|
---|
| 860 | /// <summary>
|
---|
| 861 | /// Report filter fields
|
---|
| 862 | /// </summary>
|
---|
| 863 | public ExcelPivotTableRowColumnFieldCollection PageFields
|
---|
| 864 | {
|
---|
| 865 | get
|
---|
| 866 | {
|
---|
| 867 | if (_pageFields == null)
|
---|
| 868 | {
|
---|
| 869 | _pageFields = new ExcelPivotTableRowColumnFieldCollection(this, "pageFields");
|
---|
| 870 | }
|
---|
| 871 | return _pageFields;
|
---|
| 872 | }
|
---|
| 873 | }
|
---|
| 874 | const string STYLENAME_PATH = "d:pivotTableStyleInfo/@name";
|
---|
| 875 | /// <summary>
|
---|
| 876 | /// Pivot style name. Used for custom styles
|
---|
| 877 | /// </summary>
|
---|
| 878 | public string StyleName
|
---|
| 879 | {
|
---|
| 880 | get
|
---|
| 881 | {
|
---|
| 882 | return GetXmlNodeString(STYLENAME_PATH);
|
---|
| 883 | }
|
---|
| 884 | set
|
---|
| 885 | {
|
---|
| 886 | if (value.StartsWith("PivotStyle"))
|
---|
| 887 | {
|
---|
| 888 | try
|
---|
| 889 | {
|
---|
| 890 | _tableStyle = (TableStyles)Enum.Parse(typeof(TableStyles), value.Substring(10, value.Length - 10), true);
|
---|
| 891 | }
|
---|
| 892 | catch
|
---|
| 893 | {
|
---|
| 894 | _tableStyle = TableStyles.Custom;
|
---|
| 895 | }
|
---|
| 896 | }
|
---|
| 897 | else if (value == "None")
|
---|
| 898 | {
|
---|
| 899 | _tableStyle = TableStyles.None;
|
---|
| 900 | value = "";
|
---|
| 901 | }
|
---|
| 902 | else
|
---|
| 903 | {
|
---|
| 904 | _tableStyle = TableStyles.Custom;
|
---|
| 905 | }
|
---|
| 906 | SetXmlNodeString(STYLENAME_PATH, value, true);
|
---|
| 907 | }
|
---|
| 908 | }
|
---|
| 909 | TableStyles _tableStyle = Table.TableStyles.Medium6;
|
---|
| 910 | /// <summary>
|
---|
| 911 | /// The table style. If this property is cusom the style from the StyleName propery is used.
|
---|
| 912 | /// </summary>
|
---|
| 913 | public TableStyles TableStyle
|
---|
| 914 | {
|
---|
| 915 | get
|
---|
| 916 | {
|
---|
| 917 | return _tableStyle;
|
---|
| 918 | }
|
---|
| 919 | set
|
---|
| 920 | {
|
---|
| 921 | _tableStyle=value;
|
---|
| 922 | if (value != TableStyles.Custom)
|
---|
| 923 | {
|
---|
| 924 | SetXmlNodeString(STYLENAME_PATH, "PivotStyle" + value.ToString());
|
---|
| 925 | }
|
---|
| 926 | }
|
---|
| 927 | }
|
---|
| 928 |
|
---|
| 929 | #endregion
|
---|
| 930 | #region "Internal Properties"
|
---|
| 931 | internal int CacheID
|
---|
| 932 | {
|
---|
| 933 | get
|
---|
| 934 | {
|
---|
| 935 | return GetXmlNodeInt("@cacheId");
|
---|
| 936 | }
|
---|
| 937 | set
|
---|
| 938 | {
|
---|
| 939 | SetXmlNodeString("@cacheId",value.ToString());
|
---|
| 940 | }
|
---|
| 941 | }
|
---|
| 942 |
|
---|
| 943 | #endregion
|
---|
| 944 |
|
---|
| 945 | }
|
---|
| 946 | }
|
---|