Skip to content

Commit

Permalink
Updated the README
Browse files Browse the repository at this point in the history
  • Loading branch information
folone committed Jul 29, 2013
1 parent 6f23d0f commit fdae07e
Showing 1 changed file with 47 additions and 48 deletions.
95 changes: 47 additions & 48 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Apache poi dsl for scala
## Usage

```scala

scala> import info.folone.scala.poi._
import info.folone.scala.poi._

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

// Creating a test workbook
scala> val sheetOne = Workbook {
| Set(Sheet("name") {
| Set(Row(1) {
| Set(NumericCell(1, 13.0/5), 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))
| })
| })
| }
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)))))))
Set(Sheet("name") {
Set(Row(1) {
Set(NumericCell(1, 13.0/5), 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))
})
})
}
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)))))))

scala> val path = "/home/folone/ok.xls"
path: java.lang.String = /home/folone/ok.xls
path: String = /home/folone/ok.xls

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

// Let's create another workbook
scala> val sheetTwo = 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"))
| })
| })
| }
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)))))))
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"))
})
})
}
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")))))))

scala> import syntax.equal._
import syntax.equal._

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

scala> .unsafePerformIO
res6: Boolean = true
scala> res0.unsafePerformIO
res1: Boolean = true

// The impure syntax:
scala> import impure._
import impure._

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

scala> sheetOne
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)))))))
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)))))))

scala> val mergeSheets = sheetOne |+| sheetTwo
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)))))))
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")))))))

scala> val sheetOneReloaded = load(path)
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)))))))
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)))))))

scala> val mergeSheets2 = sheetOneReloaded |+| sheetTwo
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)))))))
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")))))))

scala> mergeSheets == mergeSheets2
res7: Boolean = true
res4: Boolean = true
```


Expand Down

0 comments on commit fdae07e

Please sign in to comment.