From cc58ac7bf5355debad89b3c8227507aa06221b82 Mon Sep 17 00:00:00 2001 From: Henning Thielemann Date: Sat, 19 Oct 2024 00:35:50 +0200 Subject: [PATCH] cli: Commands.Print.transactionToSpreadsheet: vertically merge common index, date, description and other cells --- hledger/Hledger/Cli/Commands/Print.hs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/hledger/Hledger/Cli/Commands/Print.hs b/hledger/Hledger/Cli/Commands/Print.hs index fc681498d..896b2eadf 100644 --- a/hledger/Hledger/Cli/Commands/Print.hs +++ b/hledger/Hledger/Cli/Commands/Print.hs @@ -240,8 +240,7 @@ transactionToSpreadsheet :: AmountFormat -> Maybe Text -> [Text] -> Transaction -> [[Spr.Cell Spr.NumLines Text]] transactionToSpreadsheet fmt baseUrl query t = - map - (\p -> idx:d:d2:status:code:description:comment:p) + addRowSpanHeader (idx:d:d2:status:code:description:comment:[]) (postingToSpreadsheet fmt baseUrl query =<< tpostings t) where cell = Spr.defaultCell @@ -255,6 +254,20 @@ transactionToSpreadsheet fmt baseUrl query t = code = cell $ tcode t comment = cell $ T.strip $ tcomment t +addRowSpanHeader :: + [Spr.Cell border text] -> + [[Spr.Cell border text]] -> [[Spr.Cell border text]] +addRowSpanHeader common rows = + case rows of + [] -> [] + [row] -> [common++row] + _ -> + let setSpan spn cell = cell{Spr.cellSpan = spn} in + zipWith (++) + (map (setSpan $ Spr.SpanVertical $ length rows) common : + repeat (map (setSpan Spr.Covered) common)) + rows + postingToSpreadsheet :: (Spr.Lines border) => AmountFormat -> Maybe Text -> [Text] ->