Skip to content

Commit fdae07e

Browse files
committed
Updated the README
1 parent 6f23d0f commit fdae07e

File tree

1 file changed

+47
-48
lines changed

1 file changed

+47
-48
lines changed

README.md

+47-48
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Apache poi dsl for scala
55
## Usage
66

77
```scala
8-
98
scala> import info.folone.scala.poi._
109
import info.folone.scala.poi._
1110

@@ -24,83 +23,83 @@ import std.list._
2423

2524
// Creating a test workbook
2625
scala> val sheetOne = Workbook {
27-
| Set(Sheet("name") {
28-
| Set(Row(1) {
29-
| Set(NumericCell(1, 13.0/5), FormulaCell(2, "ABS(A1)"))
30-
| },
31-
| Row(2) {
32-
| Set(StringCell(1, "data"), StringCell(2, "data2"))
33-
| })
34-
| },
35-
| Sheet("name2") {
36-
| Set(Row(2) {
37-
| Set(BooleanCell(1, true), NumericCell(2, 2.4))
38-
| })
39-
| })
40-
| }
41-
sheetOne: info.folone.scala.poi.Workbook = Workbook(Set(Sheet ("name")(Set(Row (1)(Set(NumericCell(1,2.6), FormulaCell(2,ABS(A0)))), Row (2)(Set(StringCell(1,data), StringCell(2,data2))))), Sheet ("name2")(Set(Row (2)(Set(BooleanCell(1,true), NumericCell(2,2.4)))))))
26+
Set(Sheet("name") {
27+
Set(Row(1) {
28+
Set(NumericCell(1, 13.0/5), FormulaCell(2, "ABS(A1)"))
29+
},
30+
Row(2) {
31+
Set(StringCell(1, "data"), StringCell(2, "data2"))
32+
})
33+
},
34+
Sheet("name2") {
35+
Set(Row(2) {
36+
Set(BooleanCell(1, true), NumericCell(2, 2.4))
37+
})
38+
})
39+
}
40+
sheetOne: info.folone.scala.poi.Workbook = Workbook(Set(Sheet ("name")(Set(Row (1)(Set(NumericCell(1, 2.6), FormulaCell(2, "=ABS(A1)"))), Row (2)(Set(StringCell(1, "data"), StringCell(2, "data2"))))), Sheet ("name2")(Set(Row (2)(Set(BooleanCell(1, true), NumericCell(2, 2.4)))))))
4241

4342
scala> val path = "/home/folone/ok.xls"
44-
path: java.lang.String = /home/folone/ok.xls
43+
path: String = /home/folone/ok.xls
4544

4645
// Saving the result (yes, it does control side-effects via scalaz.IO)
4746
scala> sheetOne.safeToFile(path).unsafePerformIO
47+
res0: scalaz.\/[Throwable,Unit] = \/-(())
4848

4949
// Let's create another workbook
5050
scala> val sheetTwo = Workbook {
51-
| Set(Sheet("name") {
52-
| Set(Row(1) {
53-
| Set(StringCell(1, "newdata"), StringCell(2, "data2"), StringCell(3, "data3"))
54-
| },
55-
| Row(2) {
56-
| Set(StringCell(1, "data"), StringCell(2, "data2"))
57-
| },
58-
| Row(3) {
59-
| Set(StringCell(1, "data"), StringCell(2, "data2"))
60-
| })
61-
| },
62-
| Sheet("name") {
63-
| Set(Row(2) {
64-
| Set(StringCell(1, "data"), StringCell(2, "data2"))
65-
| })
66-
| })
67-
| }
68-
sheetTwo: info.folone.scala.poi.Workbook = Workbook(Set(Sheet ("name")(Set(Row (1)(Set(StringCell(1,newdata), StringCell(2,data2), StringCell(3,data3))), Row (2)(Set(StringCell(1,data), StringCell(2,data2))), Row (3)(Set(StringCell(1,data), StringCell(2,data2))))), Sheet ("name")(Set(Row (2)(Set(StringCell(1,data), StringCell(2,data2)))))))
51+
Set(Sheet("name") {
52+
Set(Row(1) {
53+
Set(StringCell(1, "newdata"), StringCell(2, "data2"), StringCell(3, "data3"))
54+
},
55+
Row(2) {
56+
Set(StringCell(1, "data"), StringCell(2, "data2"))
57+
},
58+
Row(3) {
59+
Set(StringCell(1, "data"), StringCell(2, "data2"))
60+
})
61+
},
62+
Sheet("name") {
63+
Set(Row(2) {
64+
Set(StringCell(1, "data"), StringCell(2, "data2"))
65+
})
66+
})
67+
}
68+
sheetTwo: info.folone.scala.poi.Workbook = Workbook(Set(Sheet ("name")(Set(Row (1)(Set(StringCell(1, "newdata"), StringCell(2, "data2"), StringCell(3, "data3"))), Row (2)(Set(StringCell(1, "data"), StringCell(2, "data2"))), Row (3)(Set(StringCell(1, "data"), StringCell(2, "data2"))))), Sheet ("name")(Set(Row (2)(Set(StringCell(1, "data"), StringCell(2, "data2")))))))
6969

7070
scala> import syntax.equal._
7171
import syntax.equal._
7272

7373
// And let's merge the saved workbook from before with the new one using the Monoid instance
74-
scala> Workbook(path).map {
75-
| case \/-(workbook) => (workbook |+| sheetTwo) === (sheetOne |+| sheetTwo)
76-
| case -\/(_) => false
77-
| }
78-
res5: scalaz.effect.IO[Boolean] = scalaz.effect.IOFunctions$$anon$5@2e48f14
74+
scala> val res0 = { Workbook(path).map {
75+
case \/-(workbook) => (workbook |+| sheetTwo) === (sheetOne |+| sheetTwo)
76+
case -\/(_) => false
77+
} }
78+
res0: scalaz.effect.IO[Boolean] = scalaz.effect.IOFunctions$$anon$5@5fc1a208
7979

80-
scala> .unsafePerformIO
81-
res6: Boolean = true
80+
scala> res0.unsafePerformIO
81+
res1: Boolean = true
8282

8383
// The impure syntax:
8484
scala> import impure._
8585
import impure._
8686

8787
scala> sheetOne.overwrite(path)
88-
res4: scalaz.\/[Throwable,Unit] = \/-(())
8988

9089
scala> sheetOne
91-
res5: info.folone.scala.poi.Workbook = Workbook(Set(Sheet ("name")(Set(Row (1)(Set(NumericCell(1,2.6), FormulaCell(2,ABS(A1)))), Row (2)(Set(StringCell(1,data), StringCell(2,data2))))), Sheet ("name2")(Set(Row (2)(Set(BooleanCell(1,true), NumericCell(2,2.4)))))))
90+
res3: info.folone.scala.poi.Workbook = Workbook(Set(Sheet ("name")(Set(Row (1)(Set(NumericCell(1, 2.6), FormulaCell(2, "=ABS(A1)"))), Row (2)(Set(StringCell(1, "data"), StringCell(2, "data2"))))), Sheet ("name2")(Set(Row (2)(Set(BooleanCell(1, true), NumericCell(2, 2.4)))))))
9291

9392
scala> val mergeSheets = sheetOne |+| sheetTwo
94-
mergeSheets: info.folone.scala.poi.Workbook = Workbook(Set(Sheet ("name2")(Set(Row (2)(Set(BooleanCell(1,true), NumericCell(2,2.4))))), Sheet ("name")(Set(Row (1)(Set(NumericCell(1,2.6), FormulaCell(2,ABS(A1)))), Row (2)(Set(StringCell(1,data), StringCell(2,data2)))))))
93+
mergeSheets: info.folone.scala.poi.Workbook = Workbook(Set(Sheet ("name2")(Set(Row (2)(Set(BooleanCell(1, true), NumericCell(2, 2.4))))), Sheet ("name")(Set(Row (1)(Set(NumericCell(1, 2.6), FormulaCell(2, "=ABS(A1)"))), Row (2)(Set(StringCell(1, "data"), StringCell(2, "data2")))))))
9594

9695
scala> val sheetOneReloaded = load(path)
97-
sheetOneReloaded: info.folone.scala.poi.Workbook = Workbook(Set(Sheet ("name")(Set(Row (2)(Set(StringCell(1,data), StringCell(2,data2))), Row (1)(Set(NumericCell(1,2.6), FormulaCell(2,ABS(A1)))))), Sheet ("name2")(Set(Row (2)(Set(BooleanCell(1,true), NumericCell(2,2.4)))))))
96+
sheetOneReloaded: info.folone.scala.poi.Workbook = Workbook(Set(Sheet ("name")(Set(Row (1)(Set(NumericCell(1, 2.6), FormulaCell(2, "=ABS(A1)"))), Row (2)(Set(StringCell(1, "data"), StringCell(2, "data2"))))), Sheet ("name2")(Set(Row (2)(Set(BooleanCell(1, true), NumericCell(2, 2.4)))))))
9897

9998
scala> val mergeSheets2 = sheetOneReloaded |+| sheetTwo
100-
mergeSheets2: info.folone.scala.poi.Workbook = Workbook(Set(Sheet ("name2")(Set(Row (2)(Set(BooleanCell(1,true), NumericCell(2,2.4))))), Sheet ("name")(Set(Row (1)(Set(NumericCell(1,2.6), FormulaCell(2,ABS(A1)))), Row (2)(Set(StringCell(1,data), StringCell(2,data2)))))))
99+
mergeSheets2: info.folone.scala.poi.Workbook = Workbook(Set(Sheet ("name2")(Set(Row (2)(Set(BooleanCell(1, true), NumericCell(2, 2.4))))), Sheet ("name")(Set(Row (1)(Set(NumericCell(1, 2.6), FormulaCell(2, "=ABS(A1)"))), Row (2)(Set(StringCell(1, "data"), StringCell(2, "data2")))))))
101100

102101
scala> mergeSheets == mergeSheets2
103-
res7: Boolean = true
102+
res4: Boolean = true
104103
```
105104

106105

0 commit comments

Comments
 (0)