Skip to content

Commit

Permalink
chore(test): add test for debugging issues on merged cells
Browse files Browse the repository at this point in the history
  • Loading branch information
vst committed Aug 12, 2021
1 parent 06f1b93 commit 9748463
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/DebugMergeCells.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{-# LANGUAGE OverloadedStrings #-}

module DebugMergeCells where

import qualified Codec.Xlsx as X
import qualified Codec.Xlsx.Formatted as XF
import qualified Codec.Xlsx.Tabulate as XT
import Control.Lens ((?~))
import qualified Control.Lens as L
import qualified Data.ByteString.Lazy as BL
import Data.Function ((&))
import qualified Data.Map.Strict as HM
import qualified Data.Text as T
import Data.Time.Clock.POSIX (getPOSIXTime)


debugMergeCells :: XT.SimpleFormatTable -> XT.SimpleFormatTable -> IO BL.ByteString
debugMergeCells sft1 sft2 = do
ct <- getPOSIXTime
let (fcm1, range) = XT.preformatWithTitleXY 1 1 id "Deneme1" sft1
let (fcm2, range) = XT.preformatWithTitleXY 20 1 id "Deneme2" sft2
let xlsx = XF.formatWorkbook [("Sheet 1", fcm1), ("Sheet 2", fcm2)] X.minimalStyleSheet
print xlsx
pure (X.fromXlsx ct xlsx)


-- addHeader
-- :: Int -- ^ The row to put the header at.
-- -> Int -- ^ The column to put the header at.
-- -> Int -- ^ Number of
-- -> (XF.FormattedCell -> XF.FormattedCell)
-- -> T.Text
-- -> HM.Map (Int, Int) XF.FormattedCell
-- -> HM.Map (Int, Int) XF.FormattedCell
-- addHeader row col colspan formatter text cellmap = withColspan n . fmtHead
-- where
-- fillp = X.def & X.fillPatternBgColor ?~ (X.def & X.colorARGB ?~ "FF000080")
-- fmtBold = XF.formattedFormat . XF.formatFont . L.non X.def . X.fontBold ?~ True
-- fmtItal = XF.formattedFormat . XF.formatFont . L.non X.def . X.fontItalic ?~ True
-- fmtBcol = XF.formattedFormat . XF.formatFill . L.non X.def . X.fillPattern ?~ fillp
-- fmtHead = fmtBold . fmtItal . fmtBcol
6 changes: 6 additions & 0 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import Codec.Xlsx.Tabulate (preformat)
import qualified Codec.Xlsx.Tabulate as XT
import qualified Data.ByteString.Lazy as BL
import qualified Data.HashMap.Strict as HM
import DebugMergeCells


main :: IO ()
Expand All @@ -20,6 +21,11 @@ main = do
XT.writeFormatTable path_formatted tableFormatted
putStrLn ("Output is written to " <> path_formatted)

let path_formatted2 = "test/output_formatted_2.xlsx"
output <- debugMergeCells tableFormatted tableFormatted
BL.writeFile path_formatted2 output
putStrLn ("Output is written to " <> path_formatted2)


tableSimple :: XT.SimpleTable
tableSimple = XT.SimpleTable
Expand Down
2 changes: 2 additions & 0 deletions xlsx-tabulate.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ test-suite xlsx-tabulate-doctest
type: exitcode-stdio-1.0
main-is: doctest.hs
other-modules:
DebugMergeCells
Main
Paths_xlsx_tabulate
hs-source-dirs:
Expand All @@ -75,6 +76,7 @@ test-suite xlsx-tabulate-test
type: exitcode-stdio-1.0
main-is: Main.hs
other-modules:
DebugMergeCells
Paths_xlsx_tabulate
hs-source-dirs:
test
Expand Down

0 comments on commit 9748463

Please sign in to comment.