2010-03-01 103 views

回答

1

是有可能做到這一點,至少在DWR 3

0

它會返回一個excel從客戶端下載一個例子:

// Java方面:

public FileTransfer getExcel(Parametros param){ 
    byte[] result = <here get data>; 
    InputStream myInputStream = new ByteArrayInputStream(result); 
    String excelFormat = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; 
    FileTransfer dwrExcelFile = new FileTransfer("excel.xlsx", excelFormat, myInputStream); 
    return dwrExcelFile; 
} 

// JavaScript端:

function downloadExcelFile() { 
    dwr.engine.setTimeout(59000); 
    var params = <params_to_send>; 
    <Java_class>.getExcel(params, {callback:function(dataFromServer) { 
    downloadExcelCallback(dataFromServer); 
    }}); 
} 

function downloadExcelCallback(data) { 
    dwr.engine.openInDownload(data); 
}