【发布时间】:2016-09-20 13:09:26
【问题描述】:
我在我的 JAVA 项目中使用这个 SSRS-API 和 SQL Server Reporting Services。使用此 API,我可以访问我的 SSRS 文件夹和报告,但我想知道是否可以上传或导出 Excel 或 PDF 格式的报告。
这里是 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;
}
}
有什么建议吗?
编辑
我使用了上面提到的SSRS api(SSRS-API)的下载功能(downloadReport),这里是函数的代码:
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>
...
【问题讨论】:
-
是的,我会说这是可能的。
-
@BobBrinks 你能告诉我怎么做吗?谢谢
-
好吧,要么在 SSRS 中有一个调用(从未使用过它不会知道),它会生成 PDF 或 Excel。或者您必须构建一些 java 代码或找到一个库,该库从 SSRS 获取数据并将该数据格式化为 PDF 或 Excel。
-
这就是我被卡住的地方,我一直在寻找一个这样做的库,或者只是向我展示从 SSRS 获取这些数据的逻辑,如果你知道教程或其他东西的话帮助它会很棒,在此先感谢
标签: java sql-server soap reporting-services