1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef SC_XLPIVOT_HXX 25 #define SC_XLPIVOT_HXX 26 27 #include <com/sun/star/sheet/GeneralFunction.hpp> 28 #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp> 29 #include <com/sun/star/sheet/DataPilotFieldSortMode.hpp> 30 #include <com/sun/star/sheet/DataPilotFieldShowItemsMode.hpp> 31 #include <com/sun/star/sheet/DataPilotFieldLayoutMode.hpp> 32 #include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp> 33 #include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp> 34 #include <tools/datetime.hxx> 35 #include "ftools.hxx" 36 #include "xladdress.hxx" 37 #include "dpobject.hxx" 38 39 #include <memory> 40 41 class XclImpStream; 42 class XclExpStream; 43 44 // Constants and Enumerations ================================================= 45 46 // misc ----------------------------------------------------------------------- 47 48 #define EXC_STORAGE_PTCACHE CREATE_STRING( "_SX_DB_CUR" ) 49 50 // strings 51 const sal_uInt16 EXC_PT_NOSTRING = 0xFFFF; 52 const sal_uInt16 EXC_PT_MAXSTRLEN = 0xFFFE; 53 54 // pivot cache fields 55 const size_t EXC_PC_MAXFIELDCOUNT = 0xFFFE; 56 const sal_uInt16 EXC_PC_NOFIELD = 0xFFFF; 57 const xub_StrLen EXC_PC_MAXSTRLEN = 255; 58 59 // pivot cache items 60 const size_t EXC_PC_MAXITEMCOUNT = 32500; 61 const sal_uInt16 EXC_PC_NOITEM = 0xFFFF; 62 63 // pivot table fields 64 const sal_uInt16 EXC_PT_MAXFIELDCOUNT = 0xFFFE; 65 const sal_uInt16 EXC_PT_MAXROWCOLCOUNT = EXC_PT_MAXFIELDCOUNT; 66 const sal_uInt16 EXC_PT_MAXPAGECOUNT = 256; 67 const sal_uInt16 EXC_PT_MAXDATACOUNT = 256; 68 69 // pivot table items 70 const sal_uInt16 EXC_PT_MAXITEMCOUNT = 32500; 71 72 const sal_uInt16 EXC_PT_AUTOFMT_HEADER = 0x810; 73 const sal_uInt16 EXC_PT_AUTOFMT_ZERO = 0; 74 const sal_uInt32 EXC_PT_AUTOFMT_FLAGS = 0x20; 75 76 /** Data type of a pivot cache item. */ 77 enum XclPCItemType 78 { 79 EXC_PCITEM_INVALID, /// Special state, not used in Excel files. 80 EXC_PCITEM_EMPTY, /// Empty cell. 81 EXC_PCITEM_TEXT, /// String data. 82 EXC_PCITEM_DOUBLE, /// Floating-point value. 83 EXC_PCITEM_DATETIME, /// Date/time. 84 EXC_PCITEM_INTEGER, /// 16-bit integer value. 85 EXC_PCITEM_BOOL, /// Boolean value. 86 EXC_PCITEM_ERROR /// Error code. 87 }; 88 89 /** Specifies the type of a pivot cache field. */ 90 enum XclPCFieldType 91 { 92 EXC_PCFIELD_STANDARD, /// Standard field without grouping. 93 EXC_PCFIELD_STDGROUP, /// Standard grouping field. 94 EXC_PCFIELD_NUMGROUP, /// Numeric grouping field. 95 EXC_PCFIELD_DATEGROUP, /// First date grouping field (opt. with child grouping field). 96 EXC_PCFIELD_DATECHILD, /// Additional date grouping field. 97 EXC_PCFIELD_CALCED, /// Calculated field. 98 EXC_PCFIELD_UNKNOWN /// Unknown field state, handled like standard field. 99 }; 100 101 // (0x0051,0x0052) DCONREF, DCONNAME ------------------------------------------ 102 103 const sal_uInt16 EXC_ID_DCONREF = 0x0051; 104 const sal_uInt16 EXC_ID_DCONNAME = 0x0052; 105 106 // (0x00B0) SXVIEW ------------------------------------------------------------ 107 108 const sal_uInt16 EXC_ID_SXVIEW = 0x00B0; 109 110 const sal_uInt16 EXC_SXVIEW_ROWGRAND = 0x0001; 111 const sal_uInt16 EXC_SXVIEW_COLGRAND = 0x0002; 112 const sal_uInt16 EXC_SXVIEW_DEFAULTFLAGS = 0x0208; 113 114 const sal_uInt16 EXC_SXVIEW_DATALAST = 0xFFFF; 115 const sal_uInt16 EXC_SXVIEW_AUTOFMT = 0x0001; 116 117 // (0x00B1) SXVD -------------------------------------------------------------- 118 119 const sal_uInt16 EXC_ID_SXVD = 0x00B1; 120 121 const sal_uInt16 EXC_SXVD_AXIS_NONE = 0x0000; 122 const sal_uInt16 EXC_SXVD_AXIS_ROW = 0x0001; 123 const sal_uInt16 EXC_SXVD_AXIS_COL = 0x0002; 124 const sal_uInt16 EXC_SXVD_AXIS_PAGE = 0x0004; 125 const sal_uInt16 EXC_SXVD_AXIS_DATA = 0x0008; 126 const sal_uInt16 EXC_SXVD_AXIS_ROWCOL = EXC_SXVD_AXIS_ROW | EXC_SXVD_AXIS_COL; 127 const sal_uInt16 EXC_SXVD_AXIS_ROWCOLPAGE = EXC_SXVD_AXIS_ROWCOL | EXC_SXVD_AXIS_PAGE; 128 129 const sal_uInt16 EXC_SXVD_SUBT_NONE = 0x0000; 130 const sal_uInt16 EXC_SXVD_SUBT_DEFAULT = 0x0001; 131 const sal_uInt16 EXC_SXVD_SUBT_SUM = 0x0002; 132 const sal_uInt16 EXC_SXVD_SUBT_COUNT = 0x0004; 133 const sal_uInt16 EXC_SXVD_SUBT_AVERAGE = 0x0008; 134 const sal_uInt16 EXC_SXVD_SUBT_MAX = 0x0010; 135 const sal_uInt16 EXC_SXVD_SUBT_MIN = 0x0020; 136 const sal_uInt16 EXC_SXVD_SUBT_PROD = 0x0040; 137 const sal_uInt16 EXC_SXVD_SUBT_COUNTNUM = 0x0080; 138 const sal_uInt16 EXC_SXVD_SUBT_STDDEV = 0x0100; 139 const sal_uInt16 EXC_SXVD_SUBT_STDDEVP = 0x0200; 140 const sal_uInt16 EXC_SXVD_SUBT_VAR = 0x0400; 141 const sal_uInt16 EXC_SXVD_SUBT_VARP = 0x0800; 142 143 const sal_uInt16 EXC_SXVD_DEFAULT_CACHE = EXC_PC_NOFIELD; 144 145 // (0x00B2) SXVI -------------------------------------------------------------- 146 147 const sal_uInt16 EXC_ID_SXVI = 0x00B2; 148 149 const sal_uInt16 EXC_SXVI_TYPE_PAGE = 0x00FE; 150 const sal_uInt16 EXC_SXVI_TYPE_NULL = 0x00FF; 151 const sal_uInt16 EXC_SXVI_TYPE_DATA = 0x0000; 152 const sal_uInt16 EXC_SXVI_TYPE_DEFAULT = 0x0001; 153 const sal_uInt16 EXC_SXVI_TYPE_SUM = 0x0002; 154 const sal_uInt16 EXC_SXVI_TYPE_COUNT = 0x0003; 155 const sal_uInt16 EXC_SXVI_TYPE_AVERAGE = 0x0004; 156 const sal_uInt16 EXC_SXVI_TYPE_MAX = 0x0005; 157 const sal_uInt16 EXC_SXVI_TYPE_MIN = 0x0006; 158 const sal_uInt16 EXC_SXVI_TYPE_PROD = 0x0007; 159 const sal_uInt16 EXC_SXVI_TYPE_COUNTNUM = 0x0008; 160 const sal_uInt16 EXC_SXVI_TYPE_STDDEV = 0x0009; 161 const sal_uInt16 EXC_SXVI_TYPE_STDDEVP = 0x000A; 162 const sal_uInt16 EXC_SXVI_TYPE_VAR = 0x000B; 163 const sal_uInt16 EXC_SXVI_TYPE_VARP = 0x000C; 164 const sal_uInt16 EXC_SXVI_TYPE_GRAND = 0x000D; 165 166 const sal_uInt16 EXC_SXVI_DEFAULTFLAGS = 0x0000; 167 const sal_uInt16 EXC_SXVI_HIDDEN = 0x0001; 168 const sal_uInt16 EXC_SXVI_HIDEDETAIL = 0x0002; 169 const sal_uInt16 EXC_SXVI_FORMULA = 0x0004; 170 const sal_uInt16 EXC_SXVI_MISSING = 0x0008; 171 172 const sal_uInt16 EXC_SXVI_DEFAULT_CACHE = EXC_PC_NOFIELD; 173 174 // (0x00B4) SXIVD ------------------------------------------------------------- 175 176 const sal_uInt16 EXC_ID_SXIVD = 0x00B4; 177 const sal_uInt16 EXC_SXIVD_DATA = 0xFFFE; 178 179 // (0x00B5) SXLI -------------------------------------------------------------- 180 181 const sal_uInt16 EXC_ID_SXLI = 0x00B5; 182 const sal_uInt16 EXC_SXLI_DEFAULTFLAGS = 0x0000; 183 184 // (0x00B6) SXPI -------------------------------------------------------------- 185 186 const sal_uInt16 EXC_ID_SXPI = 0x00B6; 187 const sal_uInt16 EXC_SXPI_ALLITEMS = 0x7FFD; 188 189 // (0x00C5) SXDI -------------------------------------------------------------- 190 191 const sal_uInt16 EXC_ID_SXDI = 0x00C5; 192 193 const sal_uInt16 EXC_SXDI_FUNC_SUM = 0x0000; 194 const sal_uInt16 EXC_SXDI_FUNC_COUNT = 0x0001; 195 const sal_uInt16 EXC_SXDI_FUNC_AVERAGE = 0x0002; 196 const sal_uInt16 EXC_SXDI_FUNC_MAX = 0x0003; 197 const sal_uInt16 EXC_SXDI_FUNC_MIN = 0x0004; 198 const sal_uInt16 EXC_SXDI_FUNC_PRODUCT = 0x0005; 199 const sal_uInt16 EXC_SXDI_FUNC_COUNTNUM = 0x0006; 200 const sal_uInt16 EXC_SXDI_FUNC_STDDEV = 0x0007; 201 const sal_uInt16 EXC_SXDI_FUNC_STDDEVP = 0x0008; 202 const sal_uInt16 EXC_SXDI_FUNC_VAR = 0x0009; 203 const sal_uInt16 EXC_SXDI_FUNC_VARP = 0x000A; 204 205 const sal_uInt16 EXC_SXDI_REF_NORMAL = 0x0000; 206 const sal_uInt16 EXC_SXDI_REF_DIFF = 0x0001; 207 const sal_uInt16 EXC_SXDI_REF_PERC = 0x0002; 208 const sal_uInt16 EXC_SXDI_REF_PERC_DIFF = 0x0003; 209 const sal_uInt16 EXC_SXDI_REF_RUN_TOTAL = 0x0004; 210 const sal_uInt16 EXC_SXDI_REF_PERC_ROW = 0x0005; 211 const sal_uInt16 EXC_SXDI_REF_PERC_COL = 0x0006; 212 const sal_uInt16 EXC_SXDI_REF_PERC_TOTAL = 0x0007; 213 const sal_uInt16 EXC_SXDI_REF_INDEX = 0x0008; 214 215 const sal_uInt16 EXC_SXDI_PREVITEM = 0x7FFB; 216 const sal_uInt16 EXC_SXDI_NEXTITEM = 0x7FFC; 217 218 // (0x00C6) SXDB -------------------------------------------------------------- 219 220 const sal_uInt16 EXC_ID_SXDB = 0x00C6; 221 222 const sal_uInt16 EXC_SXDB_SAVEDATA = 0x0001; 223 const sal_uInt16 EXC_SXDB_INVALID = 0x0002; 224 const sal_uInt16 EXC_SXDB_REFRESH_LOAD = 0x0004; 225 const sal_uInt16 EXC_SXDB_OPT_CACHE = 0x0008; 226 const sal_uInt16 EXC_SXDB_BG_QUERY = 0x0010; 227 const sal_uInt16 EXC_SXDB_ENABLE_REFRESH = 0x0020; 228 const sal_uInt16 EXC_SXDB_DEFAULTFLAGS = EXC_SXDB_SAVEDATA | EXC_SXDB_ENABLE_REFRESH; 229 230 const sal_uInt16 EXC_SXDB_BLOCKRECS = 0x1FFF; 231 232 const sal_uInt16 EXC_SXDB_SRC_SHEET = 0x0001; 233 const sal_uInt16 EXC_SXDB_SRC_EXTERN = 0x0002; 234 const sal_uInt16 EXC_SXDB_SRC_CONSOLID = 0x0004; 235 const sal_uInt16 EXC_SXDB_SRC_SCENARIO = 0x0008; 236 237 // (0x00C7) SXFIELD ----------------------------------------------------------- 238 239 const sal_uInt16 EXC_ID_SXFIELD = 0x00C7; 240 241 const sal_uInt16 EXC_SXFIELD_HASITEMS = 0x0001; 242 const sal_uInt16 EXC_SXFIELD_POSTPONE = 0x0002; 243 const sal_uInt16 EXC_SXFIELD_CALCED = 0x0004; 244 const sal_uInt16 EXC_SXFIELD_HASCHILD = 0x0008; 245 const sal_uInt16 EXC_SXFIELD_NUMGROUP = 0x0010; 246 const sal_uInt16 EXC_SXFIELD_16BIT = 0x0200; 247 248 const sal_uInt16 EXC_SXFIELD_DATA_MASK = 0x0DE0; 249 // known data types 250 const sal_uInt16 EXC_SXFIELD_DATA_NONE = 0x0000; /// Special state for groupings. 251 const sal_uInt16 EXC_SXFIELD_DATA_STR = 0x0480; /// Only strings, nothing else. 252 const sal_uInt16 EXC_SXFIELD_DATA_INT = 0x0520; /// Only integers, opt. with doubles. 253 const sal_uInt16 EXC_SXFIELD_DATA_DBL = 0x0560; /// Only doubles, nothing else. 254 const sal_uInt16 EXC_SXFIELD_DATA_STR_INT = 0x05A0; /// Only strings and integers, opt. with doubles. 255 const sal_uInt16 EXC_SXFIELD_DATA_STR_DBL = 0x05E0; /// Only strings and doubles, nothing else. 256 const sal_uInt16 EXC_SXFIELD_DATA_DATE = 0x0900; /// Only dates, nothing else. 257 const sal_uInt16 EXC_SXFIELD_DATA_DATE_EMP = 0x0980; /// Dates and empty strings, nothing else (?). 258 const sal_uInt16 EXC_SXFIELD_DATA_DATE_NUM = 0x0D00; /// Dates with integers or doubles without strings. 259 const sal_uInt16 EXC_SXFIELD_DATA_DATE_STR = 0x0D80; /// Dates and strings, opt. with integers or doubles. 260 261 const sal_uInt16 EXC_SXFIELD_INDEX_MIN = 0; /// List index for minimum item in groupings. 262 const sal_uInt16 EXC_SXFIELD_INDEX_MAX = 1; /// List index for maximum item in groupings. 263 const sal_uInt16 EXC_SXFIELD_INDEX_STEP = 2; /// List index for step item in groupings. 264 265 // (0x00C8) SXINDEXLIST ------------------------------------------------------- 266 267 const sal_uInt16 EXC_ID_SXINDEXLIST = 0x00C8; 268 269 // (0x00C9) SXDOUBLE ---------------------------------------------------------- 270 271 const sal_uInt16 EXC_ID_SXDOUBLE = 0x00C9; 272 273 // (0x00CA) SXBOOLEAN --------------------------------------------------------- 274 275 const sal_uInt16 EXC_ID_SXBOOLEAN = 0x00CA; 276 277 // (0x00CB) SXERROR ----------------------------------------------------------- 278 279 const sal_uInt16 EXC_ID_SXERROR = 0x00CB; 280 281 // (0x00CC) SXINTEGER --------------------------------------------------------- 282 283 const sal_uInt16 EXC_ID_SXINTEGER = 0x00CC; 284 285 // (0x00CD) SXSTRING ---------------------------------------------------------- 286 287 const sal_uInt16 EXC_ID_SXSTRING = 0x00CD; 288 289 // (0x00CE) SXDATETIME -------------------------------------------------------- 290 291 const sal_uInt16 EXC_ID_SXDATETIME = 0x00CE; 292 293 // (0x00CF) SXEMPTY ----------------------------------------------------------- 294 295 const sal_uInt16 EXC_ID_SXEMPTY = 0x00CF; 296 297 // (0x00D5) SXIDSTM ----------------------------------------------------------- 298 299 const sal_uInt16 EXC_ID_SXIDSTM = 0x00D5; 300 301 // (0x00D8) SXNUMGROUP -------------------------------------------------------- 302 303 const sal_uInt16 EXC_ID_SXNUMGROUP = 0x00D8; 304 305 const sal_uInt16 EXC_SXNUMGROUP_AUTOMIN = 0x0001; 306 const sal_uInt16 EXC_SXNUMGROUP_AUTOMAX = 0x0002; 307 308 const sal_uInt16 EXC_SXNUMGROUP_TYPE_SEC = 1; 309 const sal_uInt16 EXC_SXNUMGROUP_TYPE_MIN = 2; 310 const sal_uInt16 EXC_SXNUMGROUP_TYPE_HOUR = 3; 311 const sal_uInt16 EXC_SXNUMGROUP_TYPE_DAY = 4; 312 const sal_uInt16 EXC_SXNUMGROUP_TYPE_MONTH = 5; 313 const sal_uInt16 EXC_SXNUMGROUP_TYPE_QUART = 6; 314 const sal_uInt16 EXC_SXNUMGROUP_TYPE_YEAR = 7; 315 const sal_uInt16 EXC_SXNUMGROUP_TYPE_NUM = 8; 316 317 // (0x00D9) SXGROUPINFO ------------------------------------------------------- 318 319 const sal_uInt16 EXC_ID_SXGROUPINFO = 0x00D9; 320 321 // (0x00DC) SXEXT ------------------------------------------------------------- 322 323 const sal_uInt16 EXC_ID_SXEXT = 0x00DC; 324 325 // (0x00E3) SXVS -------------------------------------------------------------- 326 327 const sal_uInt16 EXC_ID_SXVS = 0x00E3; 328 329 const sal_uInt16 EXC_SXVS_UNKNOWN = 0x0000; 330 const sal_uInt16 EXC_SXVS_SHEET = 0x0001; 331 const sal_uInt16 EXC_SXVS_EXTERN = 0x0002; 332 const sal_uInt16 EXC_SXVS_CONSOLID = 0x0004; 333 const sal_uInt16 EXC_SXVS_PIVOTTAB = 0x0008; 334 const sal_uInt16 EXC_SXVS_SCENARIO = 0x0010; 335 336 // (0x00F0) SXRULE ------------------------------------------------------------ 337 338 const sal_uInt16 EXC_ID_SXRULE = 0x00F0; 339 340 // (0x00F1) SXEX -------------------------------------------------------------- 341 342 const sal_uInt16 EXC_ID_SXEX = 0x00F1; 343 344 const sal_uInt32 EXC_SXEX_DRILLDOWN = 0x00020000; 345 const sal_uInt32 EXC_SXEX_DEFAULTFLAGS = 0x004F0200; 346 347 // (0x00F2) SXFILT ------------------------------------------------------------ 348 349 const sal_uInt16 EXC_ID_SXFILT = 0x00F2; 350 351 // (0x00F5) ------------------------------------------------------------------- 352 353 const sal_uInt16 EXC_ID_00F5 = 0x00F5; /// Unknown record 354 355 // (0x00F6) SXNAME ------------------------------------------------------------ 356 357 const sal_uInt16 EXC_ID_SXNAME = 0x00F6; 358 359 // (0x00F8) SXPAIR ------------------------------------------------------------ 360 361 const sal_uInt16 EXC_ID_SXPAIR = 0x00F8; 362 363 // (0x00F9) SXFMLA ------------------------------------------------------------ 364 365 const sal_uInt16 EXC_ID_SXFMLA = 0x00F9; 366 367 // (0x0100) SXVDEX ------------------------------------------------------------ 368 369 const sal_uInt16 EXC_ID_SXVDEX = 0x0100; 370 371 const sal_uInt32 EXC_SXVDEX_SHOWALL = 0x00000001; 372 const sal_uInt32 EXC_SXVDEX_SORT = 0x00000200; 373 const sal_uInt32 EXC_SXVDEX_SORT_ASC = 0x00000400; 374 const sal_uInt32 EXC_SXVDEX_AUTOSHOW = 0x00000800; 375 const sal_uInt32 EXC_SXVDEX_AUTOSHOW_ASC = 0x00001000; 376 const sal_uInt32 EXC_SXVDEX_LAYOUT_REPORT = 0x00200000; 377 const sal_uInt32 EXC_SXVDEX_LAYOUT_BLANK = 0x00400000; 378 const sal_uInt32 EXC_SXVDEX_LAYOUT_TOP = 0x00800000; 379 const sal_uInt32 EXC_SXVDEX_DEFAULTFLAGS = 0x0A00001E | EXC_SXVDEX_SORT_ASC | EXC_SXVDEX_AUTOSHOW_ASC; 380 381 const sal_uInt16 EXC_SXVDEX_SORT_OWN = 0xFFFF; 382 const sal_uInt16 EXC_SXVDEX_SHOW_NONE = 0xFFFF; 383 const sal_uInt16 EXC_SXVDEX_FORMAT_NONE = 0x0000; 384 385 // (0x0103) SXFORMULA --------------------------------------------------------- 386 387 const sal_uInt16 EXC_ID_SXFORMULA = 0x0103; 388 389 // (0x0122) SXDBEX ------------------------------------------------------------ 390 391 const sal_uInt16 EXC_ID_SXDBEX = 0x0122; 392 const double EXC_SXDBEX_CREATION_DATE = 51901.029652778; 393 394 // (0x01BB) SXFDBTYPE --------------------------------------------------------- 395 396 const sal_uInt16 EXC_ID_SXFDBTYPE = 0x01BB; 397 const sal_uInt16 EXC_SXFDBTYPE_DEFAULT = 0x0000; 398 399 // (0x0810) SXVIEWEX9 --------------------------------------------------------- 400 const sal_uInt16 EXC_ID_SXVIEWEX9 = 0x0810; 401 402 // ============================================================================ 403 // Pivot cache 404 // ============================================================================ 405 406 /** Represents a data item of any type in a pivot cache. Supposed as base class for import and export. */ 407 class XclPCItem 408 { 409 public: 410 explicit XclPCItem(); 411 virtual ~XclPCItem(); 412 413 /** Sets the item to 'empty' type. */ 414 void SetEmpty(); 415 /** Sets the item to 'text' type and adds the passed text. */ 416 void SetText( const String& rText ); 417 /** Sets the item to 'double' type and adds the passed value. */ 418 void SetDouble( double fValue ); 419 /** Sets the item to 'date/time' type and adds the passed date. */ 420 void SetDateTime( const DateTime& rDateTime ); 421 /** Sets the item to 'integer' type and adds the passed value. */ 422 void SetInteger( sal_Int16 nValue ); 423 /** Sets the item to 'error' type and adds the passed Excel error code. */ 424 void SetError( sal_uInt16 nError ); 425 /** Sets the item to 'boolean' type and adds the passed Boolean value. */ 426 void SetBool( bool bValue ); 427 428 /** Returns the current item type. */ 429 inline XclPCItemType GetType() const { return meType; } 430 /** Returns the text representation of the item. */ 431 inline const String& ConvertToText() const { return maText; } 432 433 /** Returns true, if the passed iterm equals this item. */ 434 bool IsEqual( const XclPCItem& rItem ) const; 435 436 /** Returns true, if the item type is 'empty'. */ 437 bool IsEmpty() const; 438 /** Returns pointer to text, if the item type is 'text', otherwise 0. */ 439 const String* GetText() const; 440 /** Returns pointer to value, if the item type is 'double', otherwise 0. */ 441 const double* GetDouble() const; 442 /** Returns pointer to date, if the item type is 'date/time', otherwise 0. */ 443 const DateTime* GetDateTime() const; 444 /** Returns pointer to integer, if the item type is 'integer', otherwise 0. */ 445 const sal_Int16* GetInteger() const; 446 /** Returns pointer to error code, if the item type is 'error', otherwise 0. */ 447 const sal_uInt16* GetError() const; 448 /** Returns pointer to Boolean value, if the item type is 'boolean', otherwise 0. */ 449 const bool* GetBool() const; 450 451 private: 452 XclPCItemType meType; /// Type of the item. 453 String maText; /// Text representation of the item. 454 DateTime maDateTime; /// Value of a date/time item. 455 union 456 { 457 double mfValue; /// Value of a floating-point item. 458 sal_Int16 mnValue; /// Value of an integer item. 459 sal_uInt16 mnError; /// Error code of an error item. 460 bool mbValue; /// Value of a boolean item. 461 }; 462 }; 463 464 inline bool operator==( const XclPCItem& rLeft, const XclPCItem& rRight ) { return rLeft.IsEqual( rRight ); } 465 inline bool operator!=( const XclPCItem& rLeft, const XclPCItem& rRight ) { return !(rLeft == rRight); } 466 467 // Field settings ============================================================= 468 469 /** Contains data for a pivot cache field (SXFIELD record). */ 470 struct XclPCFieldInfo 471 { 472 String maName; /// Name of the pivot cache field. 473 sal_uInt16 mnFlags; /// Various flags. 474 sal_uInt16 mnGroupChild; /// Field containing grouping info for this field. 475 sal_uInt16 mnGroupBase; /// Base field if this field contains grouping info. 476 sal_uInt16 mnVisItems; /// Number of visible items for this field. 477 sal_uInt16 mnGroupItems; /// Number of special items in a grouping field. 478 sal_uInt16 mnBaseItems; /// Number of items in the base field. 479 sal_uInt16 mnOrigItems; /// Number of original source data items. 480 481 explicit XclPCFieldInfo(); 482 }; 483 484 XclImpStream& operator>>( XclImpStream& rStrm, XclPCFieldInfo& rInfo ); 485 XclExpStream& operator<<( XclExpStream& rStrm, const XclPCFieldInfo& rInfo ); 486 487 // Numeric grouping field settings ============================================ 488 489 /** Contains data for a numeric grouping field (SXNUMGROUP record). */ 490 struct XclPCNumGroupInfo 491 { 492 sal_uInt16 mnFlags; /// Various flags. 493 494 explicit XclPCNumGroupInfo(); 495 496 void SetNumType(); 497 498 sal_Int32 GetScDateType() const; 499 void SetScDateType( sal_Int32 nScType ); 500 501 sal_uInt16 GetXclDataType() const; 502 void SetXclDataType( sal_uInt16 nXclType ); 503 }; 504 505 XclImpStream& operator>>( XclImpStream& rStrm, XclPCNumGroupInfo& rInfo ); 506 XclExpStream& operator<<( XclExpStream& rStrm, const XclPCNumGroupInfo& rInfo ); 507 508 // Base class for pivot cache fields ========================================== 509 510 /** Represents a field in a pivot cache. Supposed as base class for import and export. */ 511 class XclPCField 512 { 513 public: 514 explicit XclPCField( XclPCFieldType eFieldType, sal_uInt16 nFieldIdx ); 515 virtual ~XclPCField(); 516 517 /** Returns the index of this field in the containing pivot cache. */ 518 inline sal_uInt16 GetFieldIndex() const { return mnFieldIdx; } 519 520 /** Returns true, if the type of the field is supported by Calc. */ 521 bool IsSupportedField() const; 522 523 /** Returns true, if this is a standard field build directly from source data. */ 524 bool IsStandardField() const; 525 526 //UNUSED2008-05 /** Returns true, if the items of the field are calculated from a formula. */ 527 //UNUSED2008-05 bool IsCalculatedField() const; 528 529 /** Returns true, if this field is a grouping field. */ 530 bool IsStdGroupField() const; 531 /** Returns true, if this field is a numeric grouping field. */ 532 bool IsNumGroupField() const; 533 /** Returns true, if this field is a date/time grouping field. */ 534 bool IsDateGroupField() const; 535 /** Returns true, if this field is a grouping field of any type. */ 536 bool IsGroupField() const; 537 538 /** Returns true, if this field has a child field in a grouping. */ 539 bool IsGroupBaseField() const; 540 /** Returns true, if this field is a child field in a grouping (it has a base field). */ 541 bool IsGroupChildField() const; 542 /** Returns the index of the base field, if exists, otherwise the own index. */ 543 sal_uInt16 GetBaseFieldIndex() const; 544 545 /** Returns true, if the field is based on a column in the source data area. */ 546 bool HasOrigItems() const; 547 /** Returns true, if any items are stored after the SXFIELD record. */ 548 bool HasInlineItems() const; 549 /** Returns true, if the items are stored separately after the last field. */ 550 bool HasPostponedItems() const; 551 /** Returns true, if the item indexes in the SXINDEXLIST record are stored as 16-bit values. */ 552 bool Has16BitIndexes() const; 553 554 protected: 555 XclPCFieldInfo maFieldInfo; /// Pivot cache field info (SXFIELD record). 556 XclPCFieldType meFieldType; /// Type of this pivot cache field. 557 sal_uInt16 mnFieldIdx; /// Own field index in pivot cache. 558 ScfUInt16Vec maGroupOrder; /// Order of items in a grouping field (SXGROUPINFO record). 559 XclPCNumGroupInfo maNumGroupInfo; /// Info for numeric grouping (SXNUMGROUP record). 560 }; 561 562 // Pivot cache settings ======================================================= 563 564 /** Contains data for a pivot cache (SXDB record). */ 565 struct XclPCInfo 566 { 567 sal_uInt32 mnSrcRecs; /// Records in source database. 568 sal_uInt16 mnStrmId; /// Stream identifier. 569 sal_uInt16 mnFlags; /// Flags for the cache. 570 sal_uInt16 mnBlockRecs; /// Records in a source database block. 571 sal_uInt16 mnStdFields; /// Number of standard pivot cache fields. 572 sal_uInt16 mnTotalFields; /// Number of all fields (standard, grouped, calculated). 573 sal_uInt16 mnSrcType; /// Database type. 574 String maUserName; /// Name of user who last modified the cache. 575 576 explicit XclPCInfo(); 577 }; 578 579 XclImpStream& operator>>( XclImpStream& rStrm, XclPCInfo& rInfo ); 580 XclExpStream& operator<<( XclExpStream& rStrm, const XclPCInfo& rInfo ); 581 582 // ============================================================================ 583 // Pivot table 584 // ============================================================================ 585 586 // cached name ================================================================ 587 588 /** A name for various pivot table info structs. Includes 'use cache' state. */ 589 struct XclPTCachedName 590 { 591 String maName; /// The visible name, if used. 592 bool mbUseCache; /// true = Use name in cache instead of maName. 593 594 inline explicit XclPTCachedName() : mbUseCache( true ) {} 595 }; 596 597 XclImpStream& operator>>( XclImpStream& rStrm, XclPTCachedName& rCachedName ); 598 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTCachedName& rCachedName ); 599 600 // ---------------------------------------------------------------------------- 601 602 /** Base struct for named info structs. Supports explicit naming and using the cache. */ 603 struct XclPTVisNameInfo 604 { 605 XclPTCachedName maVisName; /// The displayed name of the item. 606 607 /** Returns true, if the name is set explicitly (maVisName.mbUseCache is false). */ 608 inline bool HasVisName() const { return !maVisName.mbUseCache; } 609 /** Returns the name, if set explicitly (maVisName.mbUseCache is false). */ 610 const String* GetVisName() const; 611 /** Sets the visible name and enables usage of cache if name is empty. */ 612 void SetVisName( const String& rName ); 613 }; 614 615 // Field item settings ======================================================== 616 617 /** Contains data for a pivot table data item (SXVI record). */ 618 struct XclPTItemInfo : public XclPTVisNameInfo 619 { 620 sal_uInt16 mnType; /// Type of the item (e.g. data, function, grand total). 621 sal_uInt16 mnFlags; /// Several flags. 622 sal_uInt16 mnCacheIdx; /// Index into cache for item name. 623 624 explicit XclPTItemInfo(); 625 }; 626 627 XclImpStream& operator>>( XclImpStream& rStrm, XclPTItemInfo& rInfo ); 628 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTItemInfo& rInfo ); 629 630 // General field settings ===================================================== 631 632 typedef ::std::vector< sal_uInt16 > XclPTSubtotalVec; 633 634 /** Contains data for a pivot table field (SXVD record). */ 635 struct XclPTFieldInfo : public XclPTVisNameInfo 636 { 637 sal_uInt16 mnAxes; /// Flags for axes this field is part of. 638 sal_uInt16 mnSubtCount; /// Number of subtotal functions. 639 sal_uInt16 mnSubtotals; /// Bitfield for subtotal functions. 640 sal_uInt16 mnItemCount; /// Number of items of this field. 641 sal_uInt16 mnCacheIdx; /// Index into cache for field name (not part of record). 642 643 explicit XclPTFieldInfo(); 644 645 /** Returns the API enum representing the orientation (first of row/col/page/data). 646 @param nMask Restricts the axes taken into account. 647 @return The first found axis orientation, that is allowed in nMask parameter. */ 648 ::com::sun::star::sheet::DataPilotFieldOrientation GetApiOrient( sal_uInt16 nMask ) const; 649 /** Adds the axis orientation represented by the passed API enum. */ 650 void AddApiOrient( ::com::sun::star::sheet::DataPilotFieldOrientation eOrient ); 651 652 /** Returns a vector of all set subtotal functions. */ 653 void GetSubtotals( XclPTSubtotalVec& rSubtotals ) const; 654 /** Sets the subtotal functions contained in the passed sequence. */ 655 void SetSubtotals( const XclPTSubtotalVec& rSubtotals ); 656 }; 657 658 XclImpStream& operator>>( XclImpStream& rStrm, XclPTFieldInfo& rInfo ); 659 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTFieldInfo& rInfo ); 660 661 // Extended field settings ==================================================== 662 663 /** Contains extended data for a pivot table field (SXVDEX record). */ 664 struct XclPTFieldExtInfo 665 { 666 sal_uInt32 mnFlags; /// Several flags and number of items for AutoShow. 667 sal_uInt16 mnSortField; /// Index to data field sorting bases on. 668 sal_uInt16 mnShowField; /// Index to data field AutoShow bases on. 669 sal_uInt16 mnNumFmt; 670 ::std::auto_ptr<rtl::OUString> mpFieldTotalName; 671 672 explicit XclPTFieldExtInfo(); 673 674 /** Returns the API constant representing the sorting mode. */ 675 sal_Int32 GetApiSortMode() const; 676 /** Sets the sorting mode represented by the passed API constant. */ 677 void SetApiSortMode( sal_Int32 nSortMode ); 678 679 /** Returns the API constant representing the AutoShow mode. */ 680 sal_Int32 GetApiAutoShowMode() const; 681 /** Sets the AutoShow mode represented by the passed API constant. */ 682 void SetApiAutoShowMode( sal_Int32 nShowMode ); 683 684 /** Returns the number of items to be shown in AutoShow mode. */ 685 sal_Int32 GetApiAutoShowCount() const; 686 /** Sets the number of items to be shown in AutoShow mode. */ 687 void SetApiAutoShowCount( sal_Int32 nShowCount ); 688 689 /** Returns the API constant representing the layout mode. */ 690 sal_Int32 GetApiLayoutMode() const; 691 /** Sets the layout mode represented by the passed API constant. */ 692 void SetApiLayoutMode( sal_Int32 nLayoutMode ); 693 }; 694 695 XclImpStream& operator>>( XclImpStream& rStrm, XclPTFieldExtInfo& rInfo ); 696 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTFieldExtInfo& rInfo ); 697 698 // Page field settings ======================================================== 699 700 /** Contains data for a pivot table page field (part of SXPI record). */ 701 struct XclPTPageFieldInfo 702 { 703 sal_uInt16 mnField; /// Base field for this page info. 704 sal_uInt16 mnSelItem; /// Index to selected item. 705 sal_uInt16 mnObjId; /// Escher object ID of dropdown listbox. 706 707 explicit XclPTPageFieldInfo(); 708 }; 709 710 XclImpStream& operator>>( XclImpStream& rStrm, XclPTPageFieldInfo& rInfo ); 711 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTPageFieldInfo& rInfo ); 712 713 // Data field settings ======================================================== 714 715 /** Contains data for a pivot table data field (SXDI record). */ 716 struct XclPTDataFieldInfo : public XclPTVisNameInfo 717 { 718 sal_uInt16 mnField; /// Base field for this data info. 719 sal_uInt16 mnAggFunc; /// Data aggregation function. 720 sal_uInt16 mnRefType; /// Result reference type. 721 sal_uInt16 mnRefField; /// Index to SXVD of referred field used for the results. 722 sal_uInt16 mnRefItem; /// Index to SXVI of referred item of the used field. 723 sal_uInt16 mnNumFmt; /// Number format of the results. 724 725 explicit XclPTDataFieldInfo(); 726 727 /** Returns the API enum representing the aggregation function. */ 728 ::com::sun::star::sheet::GeneralFunction GetApiAggFunc() const; 729 /** Sets the aggregation function represented by the passed API enum. */ 730 void SetApiAggFunc( ::com::sun::star::sheet::GeneralFunction eAggFunc ); 731 732 /** Returns the API constant representing the result reference type. */ 733 sal_Int32 GetApiRefType() const; 734 /** Sets the result reference type represented by the passed API constant. */ 735 void SetApiRefType( sal_Int32 nRefType ); 736 737 /** Returns the API constant representing the result reference item type. */ 738 sal_Int32 GetApiRefItemType() const; 739 /** Sets the result reference item type represented by the passed API constant. */ 740 void SetApiRefItemType( sal_Int32 nRefItemType ); 741 }; 742 743 XclImpStream& operator>>( XclImpStream& rStrm, XclPTDataFieldInfo& rInfo ); 744 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTDataFieldInfo& rInfo ); 745 746 // Pivot table settings ======================================================= 747 748 /** Contains data for a pivot table (SXVIEW record). */ 749 struct XclPTInfo 750 { 751 String maTableName; /// The name of the pivot table. 752 String maDataName; /// The visible name of the data field. 753 XclRange maOutXclRange; /// Output range. 754 XclAddress maDataXclPos; /// First cell containing data. 755 sal_uInt16 mnFirstHeadRow; /// First heading row. 756 sal_uInt16 mnCacheIdx; /// 0-based index of the pivot cache. 757 sal_uInt16 mnDataAxis; /// Orientation of data fields. 758 sal_uInt16 mnDataPos; /// Position of data fields. 759 sal_uInt16 mnFields; /// Number of all fields. 760 sal_uInt16 mnRowFields; /// Number of row fields. 761 sal_uInt16 mnColFields; /// Number of column fields. 762 sal_uInt16 mnPageFields; /// Number of page fields. 763 sal_uInt16 mnDataFields; /// Number of data fields. 764 sal_uInt16 mnDataRows; /// Number of rows containing data. 765 sal_uInt16 mnDataCols; /// Number of columns containing data. 766 sal_uInt16 mnFlags; /// Flags for the entire pivot table. 767 sal_uInt16 mnAutoFmtIdx; /// Index to pivot table autoformat. 768 769 explicit XclPTInfo(); 770 }; 771 772 XclImpStream& operator>>( XclImpStream& rStrm, XclPTInfo& rInfo ); 773 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTInfo& rInfo ); 774 775 // Extended pivot table settings ============================================== 776 777 /** Extended information about a pivot table (SXEX record). */ 778 struct XclPTExtInfo 779 { 780 sal_uInt16 mnSxformulaRecs; /// Number of SXFORMULA records. 781 sal_uInt16 mnSxselectRecs; /// Number of SXSELECT records. 782 sal_uInt16 mnPagePerRow; /// Number of page fields per row. 783 sal_uInt16 mnPagePerCol; /// Number of page fields per column. 784 sal_uInt32 mnFlags; /// Flags for the entire pivot table. 785 786 explicit XclPTExtInfo(); 787 }; 788 789 XclImpStream& operator>>( XclImpStream& rStrm, XclPTExtInfo& rInfo ); 790 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTExtInfo& rInfo ); 791 792 // ============================================================================ 793 794 // Pivot table autoformat settings ============================================== 795 796 /** Pivot table autoformat settings (SXVIEWEX9 record). */ 797 struct XclPTViewEx9Info 798 { 799 sal_uInt32 mbReport; /// 2 for report* fmts ? 800 sal_uInt8 mnAutoFormat; /// AutoFormat ID 801 sal_uInt8 mnGridLayout; /// 0 == gridlayout, 0x10 == modern 802 String maGrandTotalName; 803 804 explicit XclPTViewEx9Info(); 805 void Init( const ScDPObject& rDPObj ); 806 }; 807 808 XclImpStream& operator>>( XclImpStream& rStrm, XclPTViewEx9Info& rInfo ); 809 XclExpStream& operator<<( XclExpStream& rStrm, const XclPTViewEx9Info& rInfo ); 810 811 // ============================================================================ 812 #endif 813 814