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 に答える