2016-09-20 70 views
0

我在使用SQL Server Reporting Services的JAVA項目中使用此SSRS-API。有了這個API,我可以訪問我的SSRS文件夾和報告,但我想知道是否可以使用Excel或PDF上傳或導出報告。SSRS使用Java以SOAP上傳報告

這裏是SSRS java類:SSRS.java

而我管理的bean:

@ViewScoped 
@ManagedBean(name = "biController") 
@SuppressWarnings("restriction") 
public class BiController { 

    private final String ADDRESS = "http://SERVERNAME/reportserver/ReportService2005.asmx?wsdl"; 
    private String[] listReports; 
    private SSRS ssrs; 

    @PostConstruct 
    public void init() { 
     try { 
      URL url = new URL(null, ADDRESS, new sun.net.www.protocol.http.Handler()); 
      NTLMAuthenticator.setDefault(new NTLMAuthenticator("DOMAIN", "USERNAME", "PASSWORD")); 
      ssrs = new SSRS(url, ""); 
     } catch (MalformedURLException e) { 
      throw new FacesException(); 
     } 
    } 

    // This function let me have the Report's names 
    public void constructListOfReports(String path) { 
     listReports = ssrs.listReports(path); 
    } 

    public String[] getListReports() { 
     return listReports; 
    } 

    public void setListReports(String[] listReports) { 
     this.listReports = listReports; 
    } 

} 

有什麼建議?

編輯

我使用的下載功能(downloadReport)SSRS API的我上面(SSRS-API)中提到,這裏是函數的代碼:

public void downloadReport(final String path, final String filename) { 
    final File file = new File(filename); 
    final String physicalName = toPhysicalFileName(path); 

    info("Downloading Report with symbolic name " + path + " to " + file); 

    final byte[] data = _soap.getReportDefinition(physicalName); 

    try (final FileOutputStream out = new FileOutputStream(file)) { 
     out.write(data); 
    } catch (final IOException ioe) { 
     final String message = "Failed to download report with symbolic name " + path + " to " + file; 
     LOG.warning(message); 
     if (file.exists() && !file.delete()) { 
      throw new IllegalStateException(message + " and failed to delete temporary file", ioe); 
     } else { 
      throw new IllegalStateException(message, ioe); 

     } 
    } 
} 

這裏是函數,我用它來調用這個函數:

public void downloadReport() { 
    ssrs.downloadReport('Path/Report name', 'C:\\PATH\\TO\\A\\FOLDER\\REPORT.XML'); 
} 

而在給定的路徑(C:/PATH/TO/A/FOLDER/REPORT.XML)我得到一個XML文件中像這樣:

<?xml version="1.0" encoding="utf-8"?> 
<Report xmlns:rd="http://schemas.microsoft.com/SQLServer/reporting/reportdesigner" xmlns:cl="http://schemas.microsoft.com/sqlserver/reporting/2010/01/componentdefinition" xmlns="http://schemas.microsoft.com/sqlserver/reporting/2010/01/reportdefinition"> 
    <AutoRefresh>0</AutoRefresh> 
    <DataSources> 
    <DataSource Name="PercallAnalysisDW"> 
     <DataSourceReference>Entrepôt de données Percall Analysis</DataSourceReference> 
     <rd:SecurityType>None</rd:SecurityType> 
     <rd:DataSourceID>3a3e3aa4-c6d6-4b44-80f0-f18a9ecd2eac</rd:DataSourceID> 
    </DataSource> 
    </DataSources> 
    <DataSets> 
    <DataSet Name="DeliveryMarginCumuleDS"> 
     <SharedDataSet> 
     <SharedDataSetReference>DeliveryMarginCumuleDS</SharedDataSetReference> 
     </SharedDataSet> 
     <Fields> 
     <Field Name="Date"> 
      <DataField>Date</DataField> 
      <rd:TypeName>System.String</rd:TypeName> 
     </Field> 
     <Field Name="Projet"> 
      <DataField>Projet</DataField> 
      <rd:TypeName>System.String</rd:TypeName> 
     </Field> 
     <Field Name="LABOR_facturé"> 
      <DataField>LABOR_facturé</DataField> 
      <rd:TypeName>System.Int32</rd:TypeName> 
     </Field> 
     <Field Name="TL_facturé"> 
      <DataField>TL_facturé</DataField> 
      <rd:TypeName>System.Int32</rd:TypeName> 
     </Field> 
     <Field Name="Coût_total"> 
      <DataField>Coût_total</DataField> 
      <rd:TypeName>System.Int32</rd:TypeName> 
     </Field> 
     <Field Name="DM"> 
      <DataField>DM</DataField> 
      <rd:TypeName>System.Int32</rd:TypeName> 
     </Field> 
     <Field Name="Revenu"> 
      <Value>=Fields!LABOR_facturé.Value + Fields!TL_facturé.Value</Value> 
     </Field> 
     </Fields> 
    </DataSet> 
    </DataSets> 
    <ReportSections> 
    <ReportSection> 
     <Body> 
     <ReportItems> 
      <Tablix Name="Tablix1"> 
      <TablixBody> 
       ... 
+0

是的,我會說那將是可能的。 –

+0

@BobBrinks你能告訴我怎麼樣?謝謝 –

+0

好吧,或者在SSRS中有一個調用(從來不會使用它不會知道),它會產生PDF或Excel。或者你將不得不建立一些Java代碼或找到一個從SSRS獲取數據並將數據格式化爲PDF或Excel的庫。 –

回答

0

我通過生成URL報告的問題解決了,這裏是功能,可以讓我生成報告:

public void downloadReportExcel(String path) { 
    try { 
     String url = "http://" + SSRS_IP + "/ReportServer?/" + path + "&rs:Format=Excel"; 

     FacesContext.getCurrentInstance().getExternalContext().redirect(url); 

     return; 
    } catch (IOException e) { 
     throw new FacesException(e); 
    } 
} 

功能得到參數的路徑和重定向我到服務器的URL有兩個參數:

  • /路徑:是的完整路徑(從根文件夾)生成
  • RS:格式= Excel中:是代(在這裏我要報告導出到Excel,但它可以在PDF,如:& RS:格式= PDF)的格式