folone / poi.scala Goto Github PK
View Code? Open in Web Editor NEWExcel meets scalaz
License: Apache License 2.0
Excel meets scalaz
License: Apache License 2.0
Make the creation of Workbook
from path (def apply
on object Workbook
) return IO Workbook
instead of Workbook
.
For the merge sheets sample that has been provided in readme.md file, I get an compilation error as stated in the subject.
Versions:
scalaVersion := "2.12.5"
... "info.folone" %% "poi-scala" % "0.18"
Thanks!
My expectation is to reuse some macro script inside a template to format the data for user purpose.
Current version is not supported to export exel from an template.
By reusing the current library, I got over it by something like this:
import info.folone.scala.poi._
import ss.usermodel.{WorkbookFactory, Cell => POICell, Row => POIRow, Workbook => POIWorkbook}
..
/*
* @param filePath: link to your template
* @param rows: set of Row data to export
*/
def addDataToExelTemplate(filePath:String, rows: Set[Row])
: POIWorkbook = {
val template: InputStream = getClass.getResourceAsStream(filePath)
val wb = WorkbookFactory.create(template)
val data = for {
i ← 0 until wb.getNumberOfSheets
sheet = wb.getSheetAt(i) if (sheet != null)
k ← 0 to sheet.getLastRowNum
row = sheet.getRow(k) if (row != null)
j ← 0 until row.getLastCellNum
cell = row.getCell(j) if (cell != null)
} yield (sheet, row, cell)
val lastRowNum = wb.getSheetAt(0).getLastRowNum +1
// append our data to end of the first sheet.
rows foreach { rw ⇒
val Row((index), (cells)) = rw
val row = wb.getSheetAt(0) createRow index + lastRowNum
cells foreach { cl ⇒
val poiCell = row createCell cl.index
setPoiCell(row, cl, poiCell)
}
}
//return this workbook to use for exporting.
// for example: wb.write(outputStream)
wb
}
/*
* this code is reused from lib.
*/
private def setPoiCell(row: POIRow, cell: Cell, poiCell: POICell): Unit {
{
cell match {
case StringCell(index, data) ⇒
poiCell.setCellValue(data)
val height = data.split("\n").size * row.getHeight
row setHeight height.asInstanceOf[Short]
case BooleanCell(index, data) ⇒ poiCell.setCellValue(data)
case NumericCell(index, data) ⇒ poiCell.setCellValue(data)
case FormulaCell(index, data) ⇒ poiCell.setCellFormula(data)
case styledCell@StyledCell(_, _) ⇒ {
setPoiCell(row, styledCell.nestedCell, poiCell)
}
}
}
}
..
Hope this help someone who met the same expectation, or give author any idea to improve the product.
Can you give me an example?
thx.
I'm using scalaz 7.1.0 and since I've added poi-scala I cannot run my tests. I get this error:
java.lang.IncompatibleClassChangeError: Found class scalaz.Memo, but interface was expected
I've searched online but all the solutions ahve to do with adding specific versions of specs2, which I am not deliberatly using. Is there anyway to solve this?
Master appears to be up to date, but the latest published version is compiled against 7.1. Thanks.
I read your documentation about scala poi, but I can't find out how to actually read the data from the sheet. For instance I want to read all from the document and print it out. May be I just don't understand the dsl. Could you help me?
Hi the package owner:
this package is great ,can suit the condition what my company business.but I want to know if it can use in business company? I have not see the license about this.
wait for you replay
kind regards
Make Cell
typed.
I think I spotted a bug in 'wbInstance.equal' which I tried to fix, but there is more to it since now it breaks monoid laws (as shown by running the test that was skipped since it takes a long time) https://github.com/rintcius/poi.scala/compare/folone:master...rintcius:workbook-equals?expand=1
Not sure why it's breaking the law though. Any idea?
Great project, we've been using it in production for half a year now.
Is it possible to add some functionality to set column width without auto sizing features? Auto sizing columns requires a frame buffer and is really expensive for large sheets.
As of Apache poi 5.2.0, the dependency on log4j-api has been updated to 2.17.1.
It seems that the master branch has already been updated to poi 5.2.0, so could you please release it?
Looking through comments in the POI javadoc, it seems it is recommended to use a File
rather than InputStream
in WorkbookFactory
. I've noticed Workbook.apply
uses InputStream
everywhere even when a filePath is passed as arguments. Is this worthy of a change or is InputStream
indeed the correct choice?
The below artefact is not found.Could you please help me to execute the code
Missing artifact info.folone:poi-scala_2.10.6:jar:0.14
Apache POI lets evaluating a cell's formula:
https://poi.apache.org/spreadsheet/eval.html
However this requires access to the underlying POI cell which is lost on creating the scala version of the cell
Is there an idiomatic way to evaluate a cell using poi.scala?
Do you plan to publish a new version for scala 2.11.1 ?
Thx
Hi,
I would like to discuss how to add the possibility of opening an existing workbook template to edit, instead of creating a new one each time.
I can see that Workbook.scala would have to be changed:
I am not sure what "something" should be :
How would you go about it ?
But how to order sheets by name or by adding order?
I want use Poi Scala library in the my Play framework project, And I added Poi Scala library to libraryDependencies in build.sbt:
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
"info.folone" %% "poi-scala" % "0.11",
"com.typesafe.slick" %% "slick" % "2.0.0-RC1",
"com.typesafe.slick" %% "slick-testkit" % "2.0.0-RC1" % "test",
"com.typesafe.play" %% "play-slick" % "0.5.0.8",
"com.novocode" % "junit-interface" % "0.10" % "test",
"ch.qos.logback" % "logback-classic" % "0.9.28" % "test",
"postgresql" % "postgresql" % "9.1-901.jdbc4",
"postgresql" % "postgresql" % "9.1-901.jdbc4" % "test",
"org.webjars" %% "webjars-play" % "2.2.0",
"org.webjars" % "bootstrap" % "2.3.1"
)
by instruction Poi Scala
but, when I do command "play update" appear following error:
[warn] module not found: info.folone#poi-scala_2.10;0.11
[warn] ==== local: tried
[warn] c:\tools\play-2.2.1\repository\local\info.folone\poi-scala_2.10\0.11\iv
ys\ivy.xml
[warn] ==== Maven2 Local: tried
[warn] file:/C:/Users/boyfox/.m2/repository/info/folone/poi-scala_2.10/0.11/po
i-scala_2.10-0.11.pom
[warn] ==== public: tried
[warn] http://repo1.maven.org/maven2/info/folone/poi-scala_2.10/0.11/poi-scala
_2.10-0.11.pom
[warn] ==== Typesafe Releases Repository: tried
[warn] http://repo.typesafe.com/typesafe/releases/info/folone/poi-scala_2.10/0
.11/poi-scala_2.10-0.11.pom
Dependencies haven't been updated since sbt 0.13.x; some artifacts required for running sbt test
are unavailable.
After updating project/build.properties
...
[info] Loading global plugins from /Users/ITMETHO/.sbt/0.13/plugins
[info] Loading project definition from /Users/ITMETHO/Developer/poi.scala/project
[info] Compiling 1 Scala source to /Users/ITMETHO/Developer/poi.scala/project/target/scala-2.10/sbt-0.13/classes...
[info] Resolving org.scala-sbt#interface;0.13.17 ...
[warn] [FAILED ] org.scala-sbt#compiler-interface;0.13.17!compiler-interface.jar(src): (0ms)
[warn] ==== local: tried
[warn] /Users/ITMETHO/.ivy2/local/org.scala-sbt/compiler-interface/0.13.17/srcs/compiler-interface-sources.jar
[warn] ==== public: tried
[warn] https://repo1.maven.org/maven2/org/scala-sbt/compiler-interface/0.13.17/compiler-interface-0.13.17-sources.jar
[warn] ==== local-preloaded-ivy: tried
[warn] /Users/ITMETHO/.sbt/preloaded/org.scala-sbt/compiler-interface/0.13.17/srcs/compiler-interface-sources.jar
[warn] ==== local-preloaded: tried
[warn] file:////Users/ITMETHO/.sbt/preloaded/org/scala-sbt/compiler-interface/0.13.17/compiler-interface-0.13.17-sources.jar
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: FAILED DOWNLOADS ::
[warn] :: ^ see resolution messages for details ^ ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: org.scala-sbt#compiler-interface;0.13.17!compiler-interface.jar(src)
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
sbt.InvalidComponent: Couldn't retrieve source module: org.scala-sbt:compiler-interface:0.13.17:component
https://mvnrepository.com/artifact/org.scala-sbt/compiler-interface lists no versions 0.13.x
of compiler-interface, but 0.1.0-M3 references the 0.13
license.
Updating SBT to v1.2.4
results in dependency failures for sbt-pgp
, ensime-sbt
, and scalastyle-sbt-plugin
; fixing these causes errors which must be f of deprecation.
[error] object Build extends Build {
[error] ^
[error] /Users/ITMETHO/Developer/poi.scala/project/Build.scala:28:13: type mismatch;
[error] found : Some[sbt.librarymanagement.MavenRepository]
[error] required: sbt.Task[Option[sbt.librarymanagement.Resolver]]
[error] Some("snapshots" at nexus + "content/repositories/snapshots")
[error]
A question was asked in #52 ( But how to order sheets by name or by adding order?) and this code for sorting by name was given:
val sheets: List[Sheet] = ...
Workbook(TreeSet(sheets : _*)(Ordering.fromLessThan[Sheet](_.name < _.name)))
It got me to thinking, when wouldn't sheets need to be in insertion order? I can't think of any reason a user would want there sheet order to be randomized.
Would it be better to use a data type that uses insertion order by default? In any case:
How can I achieve preserving insertion order for Sheets with poi.scala today?
Thanks!
I cannot find 0.15 release on Sonatype OSS or Maven Central. maven-repository says it's at Sonatype OSS's staging repo, but adding it to the resolvers doesn't help.
I have called safeToFile
and called unsafePerformIO
on the result of that call - but no file has been written to the file path I supplied!
Scala version: 2.11.8
Dependencies added
val dependencies = Seq(
"com.typesafe.scala-logging" %% "scala-logging-slf4j" % "2.1.2",
"org.scalaz" %% "scalaz-core" % "7.3.0-M4",
...
"org.apache.poi" % "poi-ooxml" % "3.14",
"info.folone" %% "poi-scala" % "0.14")
Got the following error
scala> sheetOne.safeToFile(path).fold(ex => throw ex, identity).unsafePerformIO
java.lang.ClassCastException: scalaz.Free$Gosub cannot be cast to scala.Tuple2
at scalaz.effect.IO$class.unsafePerformIO(IO.scala:22)
at scalaz.effect.IOFunctions$$anon$6.unsafePerformIO(IO.scala:227)
... 42 elided
while trying to execute the sample code displayed
scala> import info.folone.scala.poi._
import info.folone.scala.poi._
scala> import scalaz._
import scalaz._
scala> import syntax.monoid._
import syntax.monoid._
scala> import syntax.foldable._
import syntax.foldable._
scala> import std.list._
import std.list._
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(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 = "/tmp/workbook.xls"
path: String = /tmp/workbook.xls
scala> sheetOne.safeToFile(path).fold(ex ⇒ throw ex, identity).unsafePerformIO
It would be useful to have a generic extractor which could delegate to specialized extractors. For example:
object Cell {
def unapply(cell: Cell): Option[(Int, Any)] =
cell match {
case StringCell(index, data) => Some((index, data))
case NumericCell(index, data) => Some((index, data))
case BooleanCell(index, data) => Some((index, data))
case FormulaCell(index, data) => Some((index, data))
case _ => None
}
}
It looks like 0.10 and 0.11 are published as snaphot version, see the artifacts here https://oss.sonatype.org/index.html#nexus-search;quick~poi-scala
It also shows 0.12 snaphot but that might be a real snaphot (since i don't see the 0.12 tag in git)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.