2016-09-20 73 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)的格式