|
|

楼主 |
发表于 2012/3/12 18:09:06
|
显示全部楼层
private String replaceLocalGraphicsInOutput(CognosServerConnectAL connect,
AsynchDetailReportOutput reportOutput, String savePath,
String partOfFileoutPutName, String compages) throws IOException {
BaseClass[] bcGraphic;
SearchPathMultipleObject graphicSearchPath = new SearchPathMultipleObject();
graphicSearchPath.setValue(reportOutput.getOutputObjects()[0]
.getSearchPath().getValue());
bcGraphic = connect.getCMService().query(graphicSearchPath,
new PropEnum[] { PropEnum.searchPath }, new Sort[] {},
new QueryOptions());
Output out = null;
if ((bcGraphic.length > 0) && (bcGraphic[0] instanceof Output)) {
SearchPathMultipleObject outSearchPath = new SearchPathMultipleObject();
out = (Output) bcGraphic[0];
outSearchPath.setValue(out.getSearchPath().getValue() + "/graphic");
BaseClass[] g = connect.getCMService().query(
outSearchPath,
new PropEnum[] { PropEnum.searchPath, PropEnum.data,
PropEnum.dataType }, new Sort[] {},
new QueryOptions());
StringBuffer finalHtml = new StringBuffer();
String[] pages = reportOutput.getOutputPages();
String html = pages[0].toString();
String start = null;
String end = null;
String graphicFile = null;
// 替换html文件中img标签的属性
for (int i = 0; i < g.length; i++) {
String pictrueName = partOfFileoutPutName + "_" + compages + i
+ ".png";
graphicFile = savePath + "/" + pictrueName;
// 图表保存本地
File gFile = new File(graphicFile);
FileOutputStream fos = new FileOutputStream(gFile);
fos.write(((Graphic) g).getData().getValue());
fos.flush();
fos.close();
int index = 0;
index = html.indexOf("<img", 0);
start = html.substring(0, index);
end = html.substring(html.indexOf(">", index) + 1);
finalHtml.append(start + "<img src='" + pictrueName + "'>");
html = end;
}
finalHtml.append(html);
return finalHtml.toString();
}
return null;
}
把返回的String写到文件即可.这样能把图片保存到本地,至于与word文档整合,这个没做过 |
|