如何在运行时语言(Java)的Birt中插入图像

时间:2018-11-23 05:09:41

标签: java birt

我能够在Rcp应用程序中创建Birt报告,但问题是我无法将图像添加到我的表格数据(单元格数据)中

图像的路径或位置在“我的工作区”中。我的问题是如何为将在报告表中显示的图像设置路径或位置。我们为图像处理程序提供了SetURL方法,但它给出了如下错误

TextItemHandle cellData = null;
CellHandle contenCell = null;
contentCell = (CellHandle) tabledetail.getCells().get(0);
cellData = designFactory.newTextItem(value);
cellData.setContent(value.replace(" ", ""));
cellData.setProperty("canShrink", "false");

cellData.getPropertyHandle(StyleHandle.FONT_SIZE_PROP).setIntValue(10);

image = designFactory.newImage("");
image.setURL("platform:/plugin/com.****.reportgeneration/images/Information-icon.gif");
contentCell.getContent().add(cellData);   
contentCell.getContent().add(image);

全栈异常

  

org.eclipse.birt.report.engine.api.EngineException:运行报告时发生错误。       在org.eclipse.birt.report.engine.api.impl.EngineTask.handleFatalExceptions(EngineTask.java:2375)       在org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:191)       在org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.run(RunAndRenderTask.java:77)       在com。****。reportgeneration.popup.actions.ModuleReportGeneration.createReportFolder(ModuleReportGeneration.java:465)       在com。****。reportgeneration.popup.actions.ModuleReportGeneration.access $ 0(ModuleReportGeneration.java:402)       在com。****。reportgeneration.popup.actions.ModuleReportGeneration $ 1.run(ModuleReportGeneration.java:325)       在org.eclipse.jface.operation.ModalContext $ ModalContextThread.run(ModalContext.java:119)   原因:org.mozilla.javascript.EvaluatorException:正则表达式(#1)后的无效标志       在org.mozilla.javascript.DefaultErrorReporter.runtimeError(DefaultErrorReporter.java:77)       在org.mozilla.javascript.DefaultErrorReporter.error(DefaultErrorReporter.java:64)       在org.mozilla.javascript.Parser.addError(Parser.java:188)       在org.mozilla.javascript.Parser.addError(Parser.java:166)       在org.mozilla.javascript.Parser.reportError(Parser.java:223)       在org.mozilla.javascript.Parser.reportError(Parser.java:210)       在org.mozilla.javascript.Parser.reportError(Parser.java:203)       在org.mozilla.javascript.TokenStream.readRegExp(TokenStream.java:921)       在org.mozilla.javascript.Parser.primaryExpr(Parser.java:2798)       在org.mozilla.javascript.Parser.memberExpr(Parser.java:2406)       在org.mozilla.javascript.Parser.unaryExpr(Parser.java:2304)       在org.mozilla.javascript.Parser.mulExpr(Parser.java:2229)       在org.mozilla.javascript.Parser.addExpr(Parser.java:2213)       在org.mozilla.javascript.Parser.shiftExpr(Parser.java:2194)       在org.mozilla.javascript.Parser.relExpr(Parser.java:2169)       在org.mozilla.javascript.Parser.eqExpr(Parser.java:2141)       在org.mozilla.javascript.Parser.bitAndExpr(Parser.java:2130)       在org.mozilla.javascript.Parser.bitXorExpr(Parser.java:2119)       在org.mozilla.javascript.Parser.bitOrExpr(Parser.java:2108)       在org.mozilla.javascript.Parser.andExpr(Parser.java:2097)       在org.mozilla.javascript.Parser.orExpr(Parser.java:2086)       在org.mozilla.javascript.Parser.condExpr(Parser.java:2062)       在org.mozilla.javascript.Parser.assignExpr(Parser.java:2033)       在org.mozilla.javascript.Parser.expr(Parser.java:2012)       在org.mozilla.javascript.Parser.statementHelper(Parser.java:1039)       在org.mozilla.javascript.Parser.nameOrLabel(Parser.java:1793)       在org.mozilla.javascript.Parser.statementHelper(Parser.java:1032)       在org.mozilla.javascript.Parser.statement(Parser.java:901)       在org.mozilla.javascript.Parser.parse(Parser.java:540)       在org.mozilla.javascript.Parser.parse(Parser.java:478)       在org.mozilla.javascript.Context.compileImpl(Context.java:2348)       在org.mozilla.javascript.Context.compileString(Context.java:1335)       在org.mozilla.javascript.Context.compileString(Context.java:1324)       在org.eclipse.birt.report.engine.javascript.JavascriptEngine $ 3.run(JavascriptEngine.java:240)       在org.eclipse.birt.report.engine.javascript.JavascriptEngine $ 3.run(JavascriptEngine.java:1)       在java.security.AccessController.doPrivileged(本机方法)       在org.eclipse.birt.report.engine.javascript.JavascriptEngine.compile(JavascriptEngine.java:236)       在org.eclipse.birt.report.engine.javascript.JavascriptEngine.compile(JavascriptEngine.java:1)       在org.eclipse.birt.core.script.ScriptContext.compile(ScriptContext.java:153)       在org.eclipse.birt.report.engine.executor.ExecutionContext.compile(ExecutionContext.java:779)       在org.eclipse.birt.report.engine.executor.ExecutionContext.evaluate(ExecutionContext.java:713)       在org.eclipse.birt.report.engine.executor.ReportItemExecutor.evaluateString(ReportItemExecutor.java:297)       在org.eclipse.birt.report.engine.executor.ImageItemExecutor.handleURIImage(ImageItemExecutor.java:261)       在org.eclipse.birt.report.engine.executor.ImageItemExecutor.handleImage(ImageItemExecutor.java:214)       在org.eclipse.birt.report.engine.executor.ImageItemExecutor.execute(ImageItemExecutor.java:111)       在org.eclipse.birt.report.engine.internal.executor.dup.SuppressDuplicateItemExecutor.execute(SuppressDuplicateItemExecutor.java:43)       在org.eclipse.birt.report.engine.internal.executor.wrap.WrappedReportItemExecutor.execute(WrappedReportItemExecutor.java:46)       在org.eclipse.birt.report.engine.internal.executor.l18n.LocalizedReportItemExecutor.execute(LocalizedReportItemExecutor.java:34)       在org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:65)       在org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26)       在org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140)       在org.eclipse.birt.report.engine.layout.html.HTMLInlineStackingLM.resumeLayout(HTMLInlineStackingLM.java:111)       在org.eclipse.birt.report.engine.layout.html.HTMLInlineStackingLM.layoutNodes(HTMLInlineStackingLM.java:160)       在org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26)       在org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140)       在org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:70)       在org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26)       在org.eclipse.birt.report.engine.layout.html.HTMLTableBandLM.layoutChildren(HTMLTableBandLM.java:67)       在org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140)       在org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:70)       在org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26)       在org.eclipse.birt.report.engine.layout.html.HTMLRepeatHeaderLM.layoutChildren(HTMLRepeatHeaderLM.java:46)       在org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140)       在org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:70)       在org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26)       在org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140)       在org.eclipse.birt.report.engine.layout.html.HTMLInlineStackingLM.resumeLayout(HTMLInlineStackingLM.java:111)       在org.eclipse.birt.report.engine.layout.html.HTMLInlineStackingLM.layoutNodes(HTMLInlineStackingLM.java:160)       在org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26)       在org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140)       在org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:70)       在org.eclipse.birt.report.engine.layout.html.HTMLStackingLM.layoutChildren(HTMLStackingLM.java:26)       在org.eclipse.birt.report.engine.layout.html.HTMLRepeatHeaderLM.layoutChildren(HTMLRepeatHeaderLM.java:46)       在org.eclipse.birt.report.engine.layout.html.HTMLAbstractLM.layout(HTMLAbstractLM.java:140)       在org.eclipse.birt.report.engine.layout.html.HTMLBlockStackingLM.layoutNodes(HTMLBlockStackingLM.java:70)       在org.eclipse.birt.report.engine.layout.html.HTMLPageLM.layout(HTMLPageLM.java:92)       在org.eclipse.birt.report.engine.layout.html.HTMLReportLayoutEngine.layout(HTMLReportLayoutEngine.java:100)       在org.eclipse.birt.report.engine.api.impl.RunAndRenderTask.doRun(RunAndRenderTask.java:181)

1 个答案:

答案 0 :(得分:1)

TextItemHandle nText = designFactory.newTextItem(null);
nText.setContentType(DesignChoiceConstants.TEXT_CONTENT_TYPE_HTML);
nText.setContent("<img src="+ "D:\\***Ws_16-11-18\\com.** (*.***.projectcreation\\icons\\sample.gif" + " />");
contentCell.getContent().add(nText);

此代码对我来说可以插入图片