Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions oox/source/token/tokens.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2284,6 +2284,7 @@ filetime
fill
fillColor
fillClrLst
fillDownLabels
fillFormulas
fillId
fillOverlay
Expand Down
1 change: 1 addition & 0 deletions sc/Library_sc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
sc/source/core/data/dpobject \
sc/source/core/data/dpoutput \
sc/source/core/data/dpoutputgeometry \
sc/source/core/data/dppivotstyle \
sc/source/core/data/dpresfilter \
sc/source/core/data/dpsave \
sc/source/core/data/dpsdbtab \
Expand Down
10 changes: 10 additions & 0 deletions sc/inc/dpobject.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ private:
bool mbEnableGetPivotData : 1;
bool mbHideHeader : 1 = false;

OUString maRowHeaderCaption; // OOXML <x:pivotTableDefinition rowHeaderCaption="…">
OUString maColHeaderCaption; // OOXML <x:pivotTableDefinition colHeaderCaption="…">

sc::PivotTableStyleInfo maStyleInfo;

void CreateObjects();
Expand Down Expand Up @@ -183,6 +186,13 @@ public:
SC_DLLPUBLIC void SetHideHeader(bool bHideHeader);
bool GetHideHeader() const { return mbHideHeader; }

/// Override for the row-fields multi-field cell ("Row Labels" by default).
/// From OOXML <x:pivotTableDefinition rowHeaderCaption="…">.
void SetRowHeaderCaption(const OUString& rCaption) { maRowHeaderCaption = rCaption; }
const OUString& GetRowHeaderCaption() const { return maRowHeaderCaption; }
void SetColHeaderCaption(const OUString& rCaption) { maColHeaderCaption = rCaption; }
const OUString& GetColHeaderCaption() const { return maColHeaderCaption; }

SC_DLLPUBLIC void SetSheetDesc(const ScSheetSourceDesc& rDesc);
void SetImportDesc(const ScImportSourceDesc& rDesc);
void SetServiceData(const ScDPServiceDesc& rDesc);
Expand Down
52 changes: 51 additions & 1 deletion sc/inc/dpoutput.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ private:
// Number format related parameters
std::unique_ptr<sal_uInt32[]> mpColNumberFormat;
std::unique_ptr<sal_uInt32[]> mpRowNumberFormat;
std::vector<bool> maRowCompactFlags;
sal_Int32 mnColFormatCount;
sal_Int32 mnRowFormatCount;
sal_uInt32 mnSingleNumberFormat;
Expand Down Expand Up @@ -99,8 +98,18 @@ private:
void FieldCell(SCCOL nCol, SCROW nRow, SCTAB nTab, const ScDPOutLevelData& rData, bool bInTable);
void MultiFieldCell(SCCOL nCol, SCROW nRow, SCTAB nTab, bool bRowField);

OUString maRowHeaderCaption; // override for "Row Labels" cell, from OOXML
OUString maColHeaderCaption; // override for "Column Labels" cell, from OOXML
public:
void setRowHeaderCaption(const OUString& r) { maRowHeaderCaption = r; }
void setColHeaderCaption(const OUString& r) { maColHeaderCaption = r; }
private:

/// Computes number of columns needed to write row fields.
SCCOL GetColumnsForRowFields() const;
/// Translate a row-header column offset to the matching mpRowFields
/// array index, accounting for compact-shared columns. Returns -1 on miss.
tools::Long GetRowFieldArrayIndexForColOffset(SCCOL nClickColOff) const;
void CalcSizes();

/** Query which sub-area of the table the cell is in. See
Expand All @@ -117,7 +126,48 @@ private:
void outputRowHeader(SCTAB nTab, ScDPOutputImpl& rOutputImpl);
void outputDataResults(SCTAB nTab);

// --- Style application support (filled during Output()) -----------------
// These vectors are sized to the absolute span [maStartPos.Row()..mnTabEndRow]
// and [maStartPos.Col()..mnTabEndCol] respectively, indexed by absolute
// row/col minus the corresponding start. A value < 0 means "role does not
// apply at this row/col" (e.g. for subtotal level on a pure data row).
std::vector<sal_Int8> maRowSubtotalLevel; // 0..2 (mod 3) or -1
std::vector<sal_Int8> maColSubtotalLevel; // 0..2 (mod 3) or -1
std::vector<bool> maRowIsGrandTotal;
std::vector<bool> maColIsGrandTotal;
std::vector<bool> maRowIsBlank;
std::vector<bool> maRowIsPureData; // not subtotal, not blank, not grand
std::vector<bool> maColIsPureData;
void initStyleRoleVectors();

public:
/// Snapshot of cell-role data from the most recent Output(), consumed by
/// pivot table style application (sc/source/core/data/dppivotstyle.cxx).
/// All ranges are absolute sheet coordinates.
struct StyleRoles
{
SCROW nTabStartRow = 0; // top of the whole pivot region
SCCOL nTabStartCol = 0;
SCROW nMemberStartRow = 0;
SCROW nDataStartRow = 0; // first row of data results
SCCOL nDataStartCol = 0;
SCROW nTabEndRow = 0;
SCCOL nTabEndCol = 0;
SCROW nPageFieldFirstRow = -1; // -1 if no page fields
SCROW nPageFieldLastRow = -1;
const std::vector<sal_Int8>* pRowSubtotalLevel = nullptr;
const std::vector<sal_Int8>* pColSubtotalLevel = nullptr;
const std::vector<bool>* pRowIsGrandTotal = nullptr;
const std::vector<bool>* pColIsGrandTotal = nullptr;
const std::vector<bool>* pRowIsBlank = nullptr;
const std::vector<bool>* pRowIsPureData = nullptr;
const std::vector<bool>* pColIsPureData = nullptr;
size_t nNumRowFields = 0;
size_t nNumColFields = 0;
};

StyleRoles getStyleRoles() const;

ScDPOutput(ScDocument* pDocument,
css::uno::Reference<css::sheet::XDimensionsSupplier> xSource,
const ScAddress& rPosition, bool bFilter, bool bExpandCollapse,
Expand Down
33 changes: 33 additions & 0 deletions sc/inc/dppivotstyle.hxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

#pragma once

#include "address.hxx"
#include "dpoutput.hxx"

class ScDocument;

namespace sc
{
struct PivotTableStyleInfo;

/// Applies a named pivot table style (resolved from
/// ScDocument::GetTableStyles()) to the cell range described by rRoles. The
/// style's element patterns (wholeTable, headerRow, subheadings, subtotals,
/// page-field cells, etc.) are merged onto the existing cell patterns in
/// ECMA-376 §18.18.83 application order — most-general first, most-specific
/// last so the latter override the former on overlaps. No-op if rStyleInfo
/// has an empty name or the named style is not registered.
void applyPivotTableStyle(ScDocument& rDoc, SCTAB nTab,
const PivotTableStyleInfo& rStyleInfo,
const ScDPOutput::StyleRoles& rRoles);
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
2 changes: 1 addition & 1 deletion sc/inc/dpsave.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public:
bool GetShowEmpty() const
{ return bool(nShowEmptyMode); }

void SetRepeatItemLabels(bool bSet);
SC_DLLPUBLIC void SetRepeatItemLabels(bool bSet);
bool GetRepeatItemLabels() const
{ return bRepeatItemLabels; }

Expand Down
4 changes: 3 additions & 1 deletion sc/inc/pivot/DPOutLevelData.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,12 @@ struct ScDPOutLevelData
bool mbHasHiddenMember : 1;
bool mbDataLayout : 1;
bool mbPageDim : 1;
bool mbCompact : 1; /// True = compact layout. Stored per-field so it survives sort by mnDimPos.

ScDPOutLevelData(tools::Long nDim, tools::Long nHier, tools::Long nLevel, tools::Long nDimPos,
sal_uInt32 nSrcNumFmt, const uno::Sequence<sheet::MemberResult>& aResult,
OUString aName, OUString aCaption, bool bHasHiddenMember, bool bDataLayout,
bool bPageDim)
bool bPageDim, bool bCompact = false)
: mnDim(nDim)
, mnHier(nHier)
, mnLevel(nLevel)
Expand All @@ -56,6 +57,7 @@ struct ScDPOutLevelData
, mbHasHiddenMember(bHasHiddenMember)
, mbDataLayout(bDataLayout)
, mbPageDim(bPageDim)
, mbCompact(bCompact)
{
}

Expand Down
7 changes: 7 additions & 0 deletions sc/inc/pivot/PivotTableFormatOutput.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ public:
void apply(ScDocument& rDocument);
void prepare(SCTAB nTab, std::vector<ScDPOutLevelData> const& rColumnFields,
std::vector<ScDPOutLevelData> const& rRowFields, bool bColumnFieldIsDataOnly);

/// Apply any FormatType::Button formats whose oField matches nFieldDim to
/// the given cell. Called from outputRowHeader / outputColumnHeaders for
/// each field's button cell. Iterates mpFormats so it's a no-op if no
/// pivotTable formats are present.
void applyButtonFormatToField(ScDocument& rDocument, SCTAB nTab, SCCOL nCol,
SCROW nRow, sal_Int32 nFieldDim);
};

} // end sc
Expand Down
9 changes: 8 additions & 1 deletion sc/inc/pivot/PivotTableFormats.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ enum class FormatType
{
None,
Data,
Label
Label,
/// type='button' — applies to a row/column field's button cell (the
/// in-pivot field caption rendered by FieldCell/MultiFieldCell).
Button
};

/** Information to make a selection in the pivot table. */
Expand All @@ -44,6 +47,10 @@ struct PivotTableFormat
bool bSelected = false;
bool bOutline = false;
std::optional<sal_uInt32> oFieldPosition = std::nullopt;
/// For Button-type formats: the dim id (cache field index) the format
/// targets, copied from <pivotArea field="N">. Matched against
/// mpRowFields[i].mnDim / mpColFields[i].mnDim during apply.
std::optional<sal_Int32> oField = std::nullopt;

std::vector<Selection> aSelections;
std::shared_ptr<ScPatternAttr> pPattern;
Expand Down
45 changes: 33 additions & 12 deletions sc/inc/tablestyle.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#pragma once

#include <memory>
#include <unordered_map>

#include <editeng/boxitem.hxx>
#include <editeng/brushitem.hxx>
Expand All @@ -29,6 +30,11 @@ namespace tools
class JsonWriter;
}

// Mirrors the OOXML ST_TableStyleType enumeration (ECMA-376 §18.18.83). The
// first 11 values are the regular-table-style elements; the rest are needed
// for full pivot-table-style parity. Levels (first/second/third) for
// subheadings and subtotals follow the row-axis or column-axis field index;
// fields beyond level 2 wrap modulo 3 (Excel's documented behaviour).
enum class ScTableStyleElement
{
WholeTable,
Expand All @@ -42,9 +48,28 @@ enum class ScTableStyleElement
TotalRow,
FirstHeaderCell,
LastHeaderCell,
// Table-style-only additions
FirstTotalCell,
LastTotalCell,
// Pivot-style-only additions
PageFieldLabels,
PageFieldValues,
FirstSubtotalRow,
SecondSubtotalRow,
ThirdSubtotalRow,
FirstSubtotalColumn,
SecondSubtotalColumn,
ThirdSubtotalColumn,
FirstColumnSubheading,
SecondColumnSubheading,
ThirdColumnSubheading,
FirstRowSubheading,
SecondRowSubheading,
ThirdRowSubheading,
BlankRow,
};

template <class T> const T* GetItemFromPattern(ScPatternAttr* pPattern, TypedWhichId<T> nWhich)
template <class T> const T* GetItemFromPattern(const ScPatternAttr* pPattern, TypedWhichId<T> nWhich)
{
return pPattern->GetItemSet().GetItemIfSet(nWhich);
}
Expand All @@ -57,17 +82,13 @@ private:
void operator=(ScTableStyle const&) = delete;
void operator=(ScTableStyle&&) = delete;

std::unique_ptr<ScPatternAttr> mpTablePattern;
std::unique_ptr<ScPatternAttr> mpFirstColumnStripePattern;
std::unique_ptr<ScPatternAttr> mpSecondColumnStripePattern;
std::unique_ptr<ScPatternAttr> mpFirstRowStripePattern;
std::unique_ptr<ScPatternAttr> mpSecondRowStripePattern;
std::unique_ptr<ScPatternAttr> mpLastColumnPattern;
std::unique_ptr<ScPatternAttr> mpFirstColumnPattern;
std::unique_ptr<ScPatternAttr> mpHeaderRowPattern;
std::unique_ptr<ScPatternAttr> mpTotalRowPattern;
std::unique_ptr<ScPatternAttr> mpFirstHeaderCellPattern;
std::unique_ptr<ScPatternAttr> mpLastHeaderCellPattern;
// Element -> pattern map. Replaces a fixed set of named unique_ptr members so
// pivot-style elements (subtotals, subheadings, page-field cells, etc.) can be
// stored without ballooning the class with one member per element.
std::unordered_map<ScTableStyleElement, std::unique_ptr<ScPatternAttr>> maPatterns;

/// Returns the pattern for an element, or nullptr if not set.
const ScPatternAttr* lookupPattern(ScTableStyleElement eElement) const;

sal_Int32 mnFirstRowStripeSize;
sal_Int32 mnSecondRowStripeSize;
Expand Down
57 changes: 57 additions & 0 deletions sc/source/core/data/PivotTableFormatOutput.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@

#include <com/sun/star/sheet/MemberResultFlags.hpp>

#include <attrib.hxx>
#include <scitems.hxx>

#include <cstdio>
#include <string>

namespace sc
{
namespace
Expand Down Expand Up @@ -95,6 +101,26 @@ void initLines(std::vector<LineData>& rLines, std::vector<ScDPOutLevelData> cons
rLineData.maFields.resize(rFields.size());
}
}

// Pre-populate per-field dimensions so the dimension equality check in
// checkForMatchingLines doesn't silently abort for fields whose members
// are never iterated by insertFieldMember (e.g. hidden compact row fields
// with empty maResult). Without this, line.maFields[i].mnDimension stays at
// constDataDimension default, the (nDimension == rFormatEntry.nDimension)
// check at evaluateMatches fails, the early break at the bFieldMatch /
// bFieldMaybeMatch test fires, and any dxf-derived format gets dropped --
// wrap, fill, font, borders all lost on every pivot rebuild.
for (LineData& rLineData : rLines)
{
for (size_t i = 0; i < rFields.size() && i < rLineData.maFields.size(); ++i)
{
if (!rFields[i].mbDataLayout
&& rLineData.maFields[i].mnDimension == constDataDimension)
{
rLineData.maFields[i].mnDimension = rFields[i].mnDim;
}
}
}
}

Selection const* findSelection(PivotTableFormat const& rFormat, tools::Long nDimension)
Expand Down Expand Up @@ -336,6 +362,15 @@ void checkForMatchingLines(std::vector<LineData> const& rLines,
{
bFieldMatch = true;
}
else if (!rFormatEntry.bSet && eType == FormatType::Label)
{
// ECMA-376: a <pivotArea> with no <reference> for a given field means
// "any value for this field". For Label formats this is a wildcard match;
// unreferenced row fields shouldn't drop the entry into the maybe-bucket
// (where the !bMaybeExists guard at evaluateMatches() then silently
// ignores it). Match Excel semantics by treating bSet=false as wildcard.
bFieldMatch = true;
}
else
{
bFieldMaybeMatch = true;
Expand Down Expand Up @@ -461,6 +496,28 @@ void FormatOutput::apply(ScDocument& rDocument)
}
}

void FormatOutput::applyButtonFormatToField(ScDocument& rDocument, SCTAB nTab, SCCOL nCol,
SCROW nRow, sal_Int32 nFieldDim)
{
// type='button' formats target a specific row/column field's button cell.
// Walk all imported pivot formats; for each Button-type entry whose oField
// matches nFieldDim, merge its dxf-derived ScPatternAttr onto the cell.
// No-op if no formats are present (mpFormats null).
if (!mpFormats)
return;

for (sc::PivotTableFormat const& rFormat : mpFormats->getVector())
{
if (rFormat.eType != sc::FormatType::Button)
continue;
if (!rFormat.oField || *rFormat.oField != nFieldDim)
continue;
if (!rFormat.pPattern)
continue;
rDocument.ApplyPattern(nCol, nRow, nTab, *rFormat.pPattern);
}
}

} // end sc

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Loading
Loading