用于Play Framework v2.x的Excel编写器模块 [英] Excel writer Module for Play Framework v2.x
本文介绍了用于Play Framework v2.x的Excel编写器模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
最后我选择使用 Spoiwo。 Apache POI的Scala Wrapper 。它有一个整洁的开始指南。但是,没有PlayFramework的例子。
这是我的快速而肮脏的黑客,可以从案例类生成简单的报告。
def generateReportXLSX(waybillId:Long)= Action {implicit request =>
val headerStyle =
CellStyle(fillPattern = CellFill.Solid,fillForegroundColor = Color.DarkGrey,fillBackgroundColor = Color.AquaMarine,font = Font(bold = true))
val listItems:List [Item] = Items.findByWaybillId(waybillId)
val listRows = listItems.map {item =>
Row()。withCellValues(item.id.getOrElse(1),item.itemCode,item.senderName.getOrElse())
}
val gettingStartedSheet = Sheet (name =Накладная)
.withRows(listRows)
.withColumns(
Column(index = 0,style = CellStyle(font = Font(bold = true)),autoSized = true )
)
gettingStartedSheet.saveAsXlsx(/ home / user / dumps /+ waybillId +。xlsx)
Ok.sendFile(new File /home/user/dumps/\"+waybillId+\".xlsx)))
}
How it would be possible to generate Excell reports from Play Framework v2.x(Scala). I found there's a Play-Excel module but it supports PlayFramework v1.0. Is there anything suitable for v2.x?
解决方案
In the end I choose to use Spoiwo. Scala Wrapper for Apache POI. It has a neat starting guide. However, doesn't have an example with PlayFramework.
Here's my quick and dirty hack to generate simple report from case class.
def generateReportXLSX(waybillId: Long) = Action{ implicit request =>
val headerStyle =
CellStyle(fillPattern = CellFill.Solid, fillForegroundColor = Color.DarkGrey, fillBackgroundColor = Color.AquaMarine, font = Font(bold = true))
val listItems: List[Item] = Items.findByWaybillId(waybillId)
val listRows = listItems.map{ item =>
Row().withCellValues(item.id.getOrElse(1), item.itemCode, item.senderName.getOrElse(""))
}
val gettingStartedSheet = Sheet(name = "Накладная ")
.withRows(listRows)
.withColumns(
Column(index = 0, style = CellStyle(font = Font(bold = true)), autoSized = true)
)
gettingStartedSheet.saveAsXlsx("/home/user/dumps/"+waybillId+".xlsx")
Ok.sendFile(new File(("/home/user/dumps/"+waybillId+".xlsx")))
}
这篇关于用于Play Framework v2.x的Excel编写器模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文