3

I need to generate/export a excel file from a table that is generated from a list of objects. I can see that there is a module for Play 1.x but not for Play 2.x and. I found a possible solution but it is written in scala (I think) here: http://aishwaryasinghal.wordpress.com/2012/05/17/generating-excel-in-play-2/

I've tried to implement this but I think my imports doesn't work.

import java.io.FileOutputStream;
import org.apache.poi.xssf.usermodel.*;
import org.apache.poi.xssf.*;

import org.apache.poi.xssf.eventusermodel.XSSFReader;
import org.apache.poi.xssf.model.SharedStringsTable;
import org.apache.poi.openxml4j.opc.OPCPackage;

public static void generateExcel(List<Infoobject> list) {
        File file = new File("mydata.xlsx");
        FileOutputStream fileOut = new FileOutputStream(file);
        XSSFWorkbook wb = new XSSFWorkbook();
            //Workbook wb = new XSSFWorkbook(); Doesn't work either
        Sheet sheet = wb.createSheet("Sheet1");
        int rNum = 0;
        Row row = sheet.createRow(rNum);
        int cNum = 0;
        Cell cell = row.createCell(cNum);
        cell.setCellValue("My Cell Value");
        wb.write(fileOut);
        fileOut.close();
    }

It can't find either XSSFWorkbook, Sheet, Row and Cell. Do you guys know what the problem could be?

Can I use an another solution and just write it in clean Java? Or Javascript maybe?

And I do know that I have to iterate my List later to get some stuff in my excel file. This is just a try to see if it works.


Try this:

select 
    boat_data.*,
    b.pricingDescription,
    t.min_price
from boat_data
inner join (
    select pricingref, min(price) as min_price
    from boat_prices
    group by pricingref
) t on t.pricingref = boat_data.pricingref
inner join boat_prices b on (b.price = t.min_price and b.pricingRef = t.pricingRef)

Edit: I added another solution based on the information in the comments. This version should return the lowest price for each combination of pricingRef and seasonDescription (multiple rows if the same price occurs in several seasons):

select 
    boat_data.*,
    t.seasonDescription,
    pricingDescription,
    t.min_price
from boat_data
 join (
    select pricingref, seasonDescription, min(price) as min_price
    from boat_prices
    group by pricingref, seasonDescription
) t on t.pricingref = boat_data.pricingref
 join boat_prices b on b.price = t.min_price and b.pricingRef = t.pricingRef and t.seasonDescription = b.seasonDescription
order by pricingRef
4

2 回答 2

3

您只需将依赖项添加到build.sbt

libraryDependencies ++= Seq(
    javaJdbc,
    cache,
    javaEbean,
    "org.apache.poi" % "poi" % "3.8",
    "org.apache.poi" % "poi-ooxml" % "3.9"
)

然后,您需要重新生成您的项目(例如。play idea),并正常运行。第一次运行时,它将从 Maven 加载所有新的依赖项,您应该一切顺利。

于 2014-03-17T19:17:10.143 回答
0

尝试使用 Jasper Report,这是将数据从模型导出到 EXCEL 文件/报告的好方法。如果你想要一些样品,我可以寄给你;)

于 2017-01-14T12:23:19.523 回答