/**
     * Generate the asset list to excel file according to the specified folder.
     * @param path the output file name
     */
    private void genAssetListExcel(String path)
    {
        Asset assets[] = epgdata.getAsset();
        if(!this.isContainAsset(assets))
        {
            System.out.println("No assets should be generated to excel file");
            return;
        }        String tmp = "";
        try
        {
            HSSFWorkbook wb = new HSSFWorkbook();
            HSSFSheet sheet = wb.createSheet("asset");            for( int i=0;i<assets.length;i++)
            {
                // Create a row and put some cells in it. Rows are 0 based.
                HSSFRow row = sheet.createRow((short)i);
                row.createCell((short)0).setCellValue(assets[i].getChannel() + java.io.File.separator + assets[i].getName());
                row.createCell((short)1).setCellValue(mfutil.DateUtil.convertSecondsToTime(assets[i].getDuration()));
                row.createCell((short)2).setCellValue(assets[i].getLogDate());
            }
            File f = new File(path);
            if(f.exists() && f.isFile())
            {
                System.out.println("Deleting the excel file");
                f.delete();
            }
             //Write excel
            System.out.println("Writing the excel file " + path);
            java.io.FileOutputStream fileOut = new java.io.FileOutputStream(path);
            wb.write(fileOut);
            fileOut.close();        }catch(java.io.FileNotFoundException e)
        {
            System.out.println("Can not write a asset list excel file:" + path);
        }
        catch(java.io.IOException e)
        {
            System.out.println("Write a asset list failed excel file:" + path);
        }
    }

解决方案 »

  1.   

    Go to www.apache.org to find POI to implement the uppper exampleThe following package must be imported.package EPG;import paytv.DBConnection;
    import paytv.paytvutil;
    import java.sql.*;
    import java.io.RandomAccessFile;
    import java.io.File;
    import java.io.IOException;
    import java.io.FileNotFoundException;
    import org.apache.poi.poifs.filesystem.POIFSFileSystem;
    import org.apache.poi.hssf.usermodel.HSSFWorkbook;
    import org.apache.poi.hssf.usermodel.HSSFSheet;
    import org.apache.poi.hssf.usermodel.HSSFRow;
    import org.apache.poi.hssf.usermodel.HSSFCell;
    import  java.io.FileOutputStream;
    import EPG.Schedule.*;
    import java.util.ArrayList;
    import EPG.Kasenna.*;