@@ -260,6 +260,7 @@ module Hledger.Cli.Commands.Balance (
260260 ,multiBalanceReportTableAsText
261261 ,multiBalanceReportAsSpreadsheet
262262 ,addTotalBorders
263+ ,addRowSpanHeader
263264 ,simpleDateSpanCell
264265 ,RowClass (.. )
265266 -- ** Tests
@@ -454,12 +455,11 @@ budgetAverageClass rc =
454455 case rc of Value -> " budget rowaverage" ; Total -> " budget colaverage"
455456
456457-- What to show as heading for the totals row in balance reports ?
457- -- Currently nothing in terminal, Total: in html and xSV output.
458- totalRowHeadingText = " "
459- totalRowHeadingBudgetText = " "
460- totalRowHeadingHtml = " Total:"
461- totalRowHeadingCsv = " Total:"
462- totalRowHeadingBudgetCsv = " Total:"
458+ -- Currently nothing in terminal, Total: in HTML, FODS and xSV output.
459+ totalRowHeadingText = " "
460+ totalRowHeadingSpreadsheet = " Total:"
461+ totalRowHeadingBudgetText = " "
462+ totalRowHeadingBudgetCsv = " Total:"
463463
464464-- Single-column balance reports
465465
@@ -659,6 +659,19 @@ addTotalBorders =
659659rawTableContent :: [[Ods. Cell border text ]] -> [[text ]]
660660rawTableContent = map (map Ods. cellContent)
661661
662+ addRowSpanHeader ::
663+ Ods. Cell border text ->
664+ [[Ods. Cell border text ]] -> [[Ods. Cell border text ]]
665+ addRowSpanHeader header rows =
666+ case rows of
667+ [] -> []
668+ [row] -> [header: row]
669+ _ ->
670+ zipWith (:)
671+ (header{Ods. cellSpan = Ods. SpanVertical (length rows)} :
672+ repeat header{Ods. cellSpan = Ods. Covered })
673+ rows
674+
662675setAccountAnchor ::
663676 Maybe Text -> [Text ] -> Text -> Ods. Cell border text -> Ods. Cell border text
664677setAccountAnchor base query acct cell =
@@ -673,7 +686,7 @@ balanceReportAsSpreadsheet opts (items, total) =
673686 headers :
674687 concatMap (\ (a, _, _, b) -> rows Value a b) items ++
675688 if no_total_ opts then []
676- else addTotalBorders $ rows Total totalRowHeadingCsv total
689+ else addTotalBorders $ rows Total totalRowHeadingSpreadsheet total
677690 where
678691 cell = Ods. defaultCell
679692 headers =
@@ -690,14 +703,12 @@ balanceReportAsSpreadsheet opts (items, total) =
690703 (guard (rc== Value ) >> balance_base_url_ opts)
691704 (querystring_ opts) name $
692705 cell $ accountNameDrop (drop_ opts) name in
706+ addRowSpanHeader accountCell $
693707 case layout_ opts of
694708 LayoutBare ->
695- map (\ a ->
696- [accountCell,
697- cell $ acommodity a,
698- renderAmount rc $ mixedAmount a])
709+ map (\ a -> [cell $ acommodity a, renderAmount rc $ mixedAmount a])
699710 . amounts $ mixedAmountStripCosts ma
700- _ -> [[accountCell, renderAmount rc ma]]
711+ _ -> [[renderAmount rc ma]]
701712
702713 renderAmount rc mixedAmt =
703714 wbToText <$> cellFromMixedAmount bopts (amountClass rc, mixedAmt)
@@ -783,18 +794,17 @@ multiBalanceReportAsSpreadsheetHelper ishtml opts@ReportOpts{..} (PeriodicReport
783794 [hCell " rowtotal" " total" | row_total_] ++
784795 [hCell " rowaverage" " average" | average_]
785796 fullRowAsTexts row =
786- map ( anchorCell: ) $
797+ addRowSpanHeader anchorCell $
787798 rowAsText Value (dateSpanCell balance_base_url_ querystring_ acctName) row
788799 where acctName = prrFullName row
789800 anchorCell =
790801 setAccountAnchor balance_base_url_ querystring_ acctName $
791802 accountCell $ accountNameDrop drop_ acctName
792- totalrows
793- | no_total_ = []
794- | ishtml = zipWith (:) (accountCell totalRowHeadingHtml : repeat Ods. emptyCell) $
795- rowAsText Total simpleDateSpanCell tr
796- | otherwise = map (accountCell totalRowHeadingCsv : ) $
797- rowAsText Total simpleDateSpanCell tr
803+ totalrows =
804+ if no_total_
805+ then []
806+ else addRowSpanHeader (accountCell totalRowHeadingSpreadsheet) $
807+ rowAsText Total simpleDateSpanCell tr
798808 rowAsText rc dsCell =
799809 let fmt = if ishtml then oneLineNoCostFmt else machineFmt
800810 in map (map (fmap wbToText)) .
0 commit comments