sc/inc/dbdata.hxx | 5 ++--- sc/inc/document.hxx | 2 +- sc/inc/globstr.hrc | 1 + sc/inc/table.hxx | 2 +- sc/inc/tokenarray.hxx | 1 + sc/source/core/data/documen3.cxx | 16 +++++++++++----- sc/source/core/data/table3.cxx | 23 ++++++++++------------- sc/source/core/tool/dbdata.cxx | 1 - sc/source/core/tool/token.cxx | 5 +++++ sc/source/filter/oox/tablecolumnsbuffer.cxx | 12 ++++++++++++ sc/source/ui/docshell/dbdocfun.cxx | 20 +++----------------- sc/source/ui/view/dbfunc3.cxx | 2 +- 12 files changed, 48 insertions(+), 42 deletions(-)
New commits: commit ef16ad5be600c3ba5ca1237e8066b254a51b43c6 Author: Balazs Varga <[email protected]> AuthorDate: Mon Oct 27 12:20:48 2025 +0100 Commit: Balazs Varga <[email protected]> CommitDate: Thu Jan 29 09:28:42 2026 +0100 Do not extend DbDataRange automatically for TableStyles when we have Total Rows. Also do not set bActive for groups in SubtotalParam otherwise the original Subtotal will run. Use TableRefs[ColumnName] for Total functions. Change-Id: Id95aa3ab58a7de7c7640a8e7d724df089fb66065 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193204 Tested-by: Balazs Varga <[email protected]> Reviewed-by: Balazs Varga <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193680 Reviewed-by: Andras Timar <[email protected]> Tested-by: Andras Timar <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196748 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197974 Tested-by: Jenkins diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index bab60929c084..539431ead370 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1199,7 +1199,7 @@ public: bool DoSubTotals( SCTAB nTab, ScSubTotalParam& rParam ); void RemoveSubTotals( SCTAB nTab, ScSubTotalParam& rParam ); // Table SubTotals - bool DoTableSubTotals( SCTAB nTab, ScSubTotalParam& rParam ); + bool DoTableSubTotals( SCTAB nTab, ScSubTotalParam& rParam, sal_uInt16 nIndex ); void RemoveTableSubTotals( SCTAB nTab, ScSubTotalParam& rParam, const ScSubTotalParam& rOldParam ); bool TestRemoveSubTotals( SCTAB nTab, const ScSubTotalParam& rParam ); diff --git a/sc/inc/globstr.hrc b/sc/inc/globstr.hrc index dc8dd49c8a28..ccf112e1e144 100644 --- a/sc/inc/globstr.hrc +++ b/sc/inc/globstr.hrc @@ -208,6 +208,7 @@ #define STR_TABLE_GRAND_STDDEV NC_("STR_TABLE_GRAND_STDDEV", "Grand StdDev") #define STR_TABLE_GRAND_SUM NC_("STR_TABLE_GRAND_SUM", "Grand Sum") #define STR_TABLE_GRAND_VAR NC_("STR_TABLE_GRAND_VAR", "Grand Var") +#define STR_TABLE_TOTAL NC_("STR_TABLE_TOTAL", "Summary") #define STR_NOCHARTATCURSOR NC_("STR_NOCHARTATCURSOR", "No chart found at this position.") #define STR_PIVOT_NOTFOUND NC_("STR_PIVOT_NOTFOUND", "No pivot table found at this position.") #define STR_EMPTYDATA NC_("STR_EMPTYDATA", "(empty)") diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index b1a98be70c91..20790134159a 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -328,7 +328,7 @@ public: void RemoveSubTotals( ScSubTotalParam& rParam ); void RemoveSimpleSubTotals( ScSubTotalParam& rParam, const ScSubTotalParam& rOldParam ); bool DoSubTotals( ScSubTotalParam& rParam ); - bool DoSimpleSubTotals( ScSubTotalParam& rParam ); + bool DoSimpleSubTotals( ScSubTotalParam& rParam, sal_uInt16 nIndex ); const ScSheetEvents* GetSheetEvents() const { return pSheetEvents.get(); } void SetSheetEvents( std::unique_ptr<ScSheetEvents> pNew ); diff --git a/sc/inc/tokenarray.hxx b/sc/inc/tokenarray.hxx index 90495d9446ba..08938553ea4f 100644 --- a/sc/inc/tokenarray.hxx +++ b/sc/inc/tokenarray.hxx @@ -114,6 +114,7 @@ public: SC_DLLPUBLIC formula::FormulaToken* AddDoubleReference( const ScComplexRefData& rRef ); SC_DLLPUBLIC void AddRangeName( sal_uInt16 n, sal_Int16 nSheet ); formula::FormulaToken* AddDBRange( sal_uInt16 n ); + SC_DLLPUBLIC formula::FormulaToken* AddTableRef( sal_uInt16 n ); SC_DLLPUBLIC formula::FormulaToken* AddExternalName( sal_uInt16 nFileId, const svl::SharedString& rName ); SC_DLLPUBLIC void AddExternalSingleReference( sal_uInt16 nFileId, const svl::SharedString& rTabName, const ScSingleRefData& rRef ); SC_DLLPUBLIC formula::FormulaToken* AddExternalDoubleReference( sal_uInt16 nFileId, const svl::SharedString& rTabName, const ScComplexRefData& rRef ); diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx index 20db6a930d50..015f29499656 100644 --- a/sc/source/core/data/documen3.cxx +++ b/sc/source/core/data/documen3.cxx @@ -794,10 +794,10 @@ void ScDocument::RemoveTableSubTotals( SCTAB nTab, ScSubTotalParam& rParam, cons pTable->RemoveSimpleSubTotals( rParam, rOldParam ); } -bool ScDocument::DoTableSubTotals( SCTAB nTab, ScSubTotalParam& rParam ) +bool ScDocument::DoTableSubTotals( SCTAB nTab, ScSubTotalParam& rParam, sal_uInt16 nIndex ) { ScTable* pTable = FetchTable(nTab); - return pTable && pTable->DoSimpleSubTotals(rParam); + return pTable && pTable->DoSimpleSubTotals(rParam, nIndex); } bool ScDocument::HasSubTotalCells( const ScRange& rRange ) @@ -1581,9 +1581,12 @@ void ScDocument::GetFilterEntries( ScDBData* pDBData = pDBCollection->GetDBAtCursor(nCol, nRow, nTab, ScDBDataPortion::AREA); //!?? if (!pDBData) return; - - pDBData->ExtendBackColorArea(*this); - pDBData->ExtendDataArea(*this); + // Do not extand DBArea automatically in case of Table Styles with Total row + if (!pDBData->HasTotals() || !pDBData->GetTableStyleInfo()) + { + pDBData->ExtendBackColorArea(*this); + pDBData->ExtendDataArea(*this); + } SCTAB nAreaTab; SCCOL nStartCol; SCROW nStartRow; @@ -1593,6 +1596,9 @@ void ScDocument::GetFilterEntries( if (pDBData->HasHeader()) ++nStartRow; + // For Table Styles area, exclude total row + if (pDBData->HasTotals() && pDBData->GetTableStyleInfo()) + --nEndRow; ScQueryParam aParam; pDBData->GetQueryParam( aParam ); diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index d0657e41b601..6db9cb19a7bb 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -2366,7 +2366,7 @@ bool ScTable::DoSubTotals( ScSubTotalParam& rParam ) return bSpaceLeft; } -bool ScTable::DoSimpleSubTotals( ScSubTotalParam& rParam ) +bool ScTable::DoSimpleSubTotals( ScSubTotalParam& rParam, sal_uInt16 nIndex ) { RowEntry aRowEntry; aRowEntry.nGroupNo = 0; @@ -2394,30 +2394,27 @@ bool ScTable::DoSimpleSubTotals( ScSubTotalParam& rParam ) } else { - SetString(group.nField, aRowEntry.nDestRow, nTab, u"Summary"_ustr); + SetString(group.nField, aRowEntry.nDestRow, nTab, ScResId(STR_TABLE_TOTAL)); } // insert the formulas if (group.nSubTotals > 0) { - ScComplexRefData aRef; - aRef.InitFlags(); - aRef.Ref1.SetAbsTab(nTab); - aRef.Ref2.SetAbsTab(nTab); - for (SCCOL nResult = 0; nResult < group.nSubTotals; ++nResult) { - aRef.Ref1.SetAbsCol(group.col(nResult)); - aRef.Ref1.SetAbsRow(aRowEntry.nFuncStart); - aRef.Ref2.SetAbsCol(group.col(nResult)); - aRef.Ref2.SetAbsRow(aRowEntry.nFuncEnd); - // TODO: handle it with tablerefs: Table1[Column1] ScTokenArray aArr(rDocument); aArr.AddOpCode(ocSubTotal); aArr.AddOpCode(ocOpen); aArr.AddDouble(static_cast<double>(group.func(nResult))); aArr.AddOpCode(ocSep); - aArr.AddDoubleReference(aRef); + // Table refs structure + aArr.AddTableRef(nIndex); + aArr.AddOpCode(ocTableRefOpen); + ScSingleRefData aSingleRef; + aSingleRef.InitAddress(group.col(nResult), aRowEntry.nFuncStart - 1, nTab); + aArr.AddSingleReference(aSingleRef); + aArr.AddOpCode(ocTableRefClose); + // Table refs structure end aArr.AddOpCode(ocClose); aArr.AddOpCode(ocStop); ScFormulaCell* pCell = new ScFormulaCell( diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx index a135b364ff6a..eb4be588ac61 100644 --- a/sc/source/core/tool/dbdata.cxx +++ b/sc/source/core/tool/dbdata.cxx @@ -701,7 +701,6 @@ void ScDBData::CreateSubTotalParam(ScSubTotalParam& rSubTotalParam) const { rSubTotalParam.bDoSort = false; rSubTotalParam.bGroupedBy = false; - rSubTotalParam.aGroups[0].bActive = true; rSubTotalParam.aGroups[0].nField = rSubTotalParam.nCol1; // which column we add 'Summary' const size_t nEntryCount = rSubTotalParam.nCol2 - rSubTotalParam.nCol1 + 1; // col count diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx index 082a591cc032..0e2e2ab5d884 100644 --- a/sc/source/core/tool/token.cxx +++ b/sc/source/core/tool/token.cxx @@ -2354,6 +2354,11 @@ FormulaToken* ScTokenArray::AddDBRange( sal_uInt16 n ) return Add( new FormulaIndexToken( ocDBArea, n)); } +FormulaToken* ScTokenArray::AddTableRef( sal_uInt16 n ) +{ + return Add( new ScTableRefToken(n, ScTableRefToken::TABLE)); +} + FormulaToken* ScTokenArray::AddExternalName( sal_uInt16 nFileId, const svl::SharedString& rName ) { return Add( new ScExternalNameToken(nFileId, rName) ); diff --git a/sc/source/ui/docshell/dbdocfun.cxx b/sc/source/ui/docshell/dbdocfun.cxx index 66e48da16986..de0daf0634b9 100644 --- a/sc/source/ui/docshell/dbdocfun.cxx +++ b/sc/source/ui/docshell/dbdocfun.cxx @@ -834,7 +834,8 @@ bool ScDBDocFunc::Query( SCTAB nTab, const ScQueryParam& rQueryParam, ScSubTotalParam aSubTotalParam; pDBData->GetSubTotalParam( aSubTotalParam ); // partial results exist? - if (aSubTotalParam.aGroups[0].bActive && !aSubTotalParam.bRemoveOnly) + if ((aSubTotalParam.aGroups[0].bActive && !aSubTotalParam.bRemoveOnly) + || (pDBData->HasTotals() && pDBData->GetTableStyleInfo())) bKeepSub = true; } @@ -1309,22 +1310,7 @@ void ScDBDocFunc::DoTableSubTotals( SCTAB nTab, const ScDBData& rNewData, const bool bSuccess = true; if (bDo) { - // sort - if (rParam.bDoSort) - { - pDBData->SetArea(nTab, aNewParam.nCol1, aNewParam.nRow1, aNewParam.nCol2, - aNewParam.nRow2); - - // set partial result field to before the sorting - // (Duplicates are omitted, so can be called again) - - ScSortParam aOldSort; - pDBData->GetSortParam(aOldSort); - ScSortParam aSortParam(aNewParam, aOldSort); - Sort(nTab, aSortParam, false, false, bApi); - } - - bSuccess = rDoc.DoTableSubTotals(nTab, aNewParam); + bSuccess = rDoc.DoTableSubTotals(nTab, aNewParam, rNewData.GetIndex()); rDoc.SetDrawPageSize(nTab); } ScRange aDirtyRange(aNewParam.nCol1, aNewParam.nRow1, nTab, aNewParam.nCol2, aNewParam.nRow2, diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx index 1c9a7e45fb69..94469fa6d6ba 100644 --- a/sc/source/ui/view/dbfunc3.cxx +++ b/sc/source/ui/view/dbfunc3.cxx @@ -670,7 +670,7 @@ void ScDBFunc::DoTableSubTotals( const ScDBData& rNewData, const ScSubTotalParam bool bSuccess = true; if (bDo) { - bSuccess = rDoc.DoTableSubTotals(nTab, aNewParam); + bSuccess = rDoc.DoTableSubTotals(nTab, aNewParam, rNewData.GetIndex()); } ScRange aDirtyRange(aNewParam.nCol1, aNewParam.nRow1, nTab, aNewParam.nCol2, aNewParam.nRow2, nTab); commit 03f5b806cd9c735f81c03551685fe8de0ae6fc9d Author: Balazs Varga <[email protected]> AuthorDate: Mon Oct 27 11:14:28 2025 +0100 Commit: Balazs Varga <[email protected]> CommitDate: Thu Jan 29 09:28:31 2026 +0100 Import and store Total rows information in ScSubtotal obj at ooxml import. Change-Id: I2c0d58a1c21800c987b9998e9cb59b39a872ee58 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193203 Tested-by: Balazs Varga <[email protected]> Reviewed-by: Balazs Varga <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193679 Reviewed-by: Andras Timar <[email protected]> Tested-by: Andras Timar <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/196747 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197973 diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx index 23f2dff0662c..7c7ae6d81bda 100644 --- a/sc/inc/dbdata.hxx +++ b/sc/inc/dbdata.hxx @@ -278,9 +278,8 @@ public: SC_DLLPUBLIC void SetAdvancedQuerySource(const ScRange* pSource); SC_DLLPUBLIC void GetSubTotalParam(ScSubTotalParam& rSubTotalParam) const; - void SetSubTotalParam(const ScSubTotalParam& rSubTotalParam); - - void CreateSubTotalParam(ScSubTotalParam& rSubTotalParam) const; + SC_DLLPUBLIC void SetSubTotalParam(const ScSubTotalParam& rSubTotalParam); + SC_DLLPUBLIC void CreateSubTotalParam(ScSubTotalParam& rSubTotalParam) const; void GetImportParam(ScImportParam& rImportParam) const; void SetImportParam(const ScImportParam& rImportParam); diff --git a/sc/source/filter/oox/tablecolumnsbuffer.cxx b/sc/source/filter/oox/tablecolumnsbuffer.cxx index 47548066ce74..e815bfa5156f 100644 --- a/sc/source/filter/oox/tablecolumnsbuffer.cxx +++ b/sc/source/filter/oox/tablecolumnsbuffer.cxx @@ -22,6 +22,7 @@ #include <sal/log.hxx> #include <oox/helper/attributelist.hxx> #include <oox/token/tokens.hxx> +#include <subtotalparam.hxx> XmlColumnPrModel::XmlColumnPrModel() : mnMapId( 1 ), @@ -137,6 +138,17 @@ bool TableColumns::finalizeImport( ScDBData* pDBData ) } pDBData->SetTableColumnNames( std::move(aNames) ); pDBData->SetTableColumnAttributes( std::move(aAttributesVector) ); + // set subtotal parameters for columns + if (pDBData->HasTotals()) + { + ScSubTotalParam aSubTotalParam; + pDBData->GetSubTotalParam(aSubTotalParam); + aSubTotalParam.bHasHeader = pDBData->HasHeader(); + aSubTotalParam.bRemoveOnly = false; + aSubTotalParam.bReplace = false; + pDBData->CreateSubTotalParam(aSubTotalParam); + pDBData->SetSubTotalParam(aSubTotalParam); + } return true; } return false;
