forked from demo/example
Browse Source
* commit '394c0dd1b9a35bc57eb2eec332506d1a8cddfc5c': DEC-10642 后台CAS登录后,token应放入request 无JIRA任务 图表接口更新 http://www.finedevelop.com:2016/browse/DEMO-2670 新增10.0从数据读取frm决策报表,编码格式改为utf-8 http://www.finedevelop.com:2016/browse/DEMO-2670 新增10.0从数据库读取frm决策报表 1.代码改为utf-8编码 2.去掉多余注释部分 1.代码改为utf-8编码 2.去掉代码多余的注释部分 frm表单导出api新增代码persist/10.0
Lanlan
5 years ago
5 changed files with 157 additions and 7 deletions
@ -0,0 +1,58 @@
|
||||
package com.fr.demo; |
||||
|
||||
import com.fr.io.utils.ResourceIOUtils; |
||||
import com.fr.web.weblet.Formlet; |
||||
import com.fr.form.main.Form; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import java.io.InputStream; |
||||
import java.sql.Blob; |
||||
import java.sql.Connection; |
||||
import java.sql.DriverManager; |
||||
import java.sql.ResultSet; |
||||
import java.sql.Statement; |
||||
import java.util.Map; |
||||
|
||||
|
||||
|
||||
public class ReadfrmFromDatabase extends Formlet { |
||||
|
||||
|
||||
public Form createForm(HttpServletRequest reportletRequest) { |
||||
|
||||
Form form= new Form(); |
||||
String name = reportletRequest.getParameter("reportname").toString(); |
||||
try { |
||||
// 定义数据连接(根据你实际数据库信息进行修改)
|
||||
String driver = "com.mysql.jdbc.Driver"; |
||||
String url = "jdbc:mysql://localhost:3306/test"; |
||||
String user = "root"; |
||||
String pass = "123456"; |
||||
Class.forName(driver); |
||||
Connection conn = DriverManager.getConnection(url, user, pass); |
||||
// 从数据库中读模板
|
||||
String sql = "select B from report where A = '" + name |
||||
+ "'"; |
||||
Statement smt = conn.createStatement(); |
||||
ResultSet rs = smt.executeQuery(sql); |
||||
while (rs.next()) { |
||||
Blob blob = rs.getBlob(1); |
||||
FineLoggerFactory.getLogger().info(blob.toString()); |
||||
InputStream ins = blob.getBinaryStream(); |
||||
form.readStream(ins); |
||||
} |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
System.out.println(ResourceIOUtils.getRealPath("assets")); |
||||
return form; |
||||
} |
||||
|
||||
@Override |
||||
public void setParameterMap(Map<String, Object> arg0) { |
||||
// TODO Auto-generated method stub
|
||||
|
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,76 @@
|
||||
package com.fr.io; |
||||
|
||||
import com.fr.base.operator.common.CommonOperator; |
||||
import com.fr.chart.activator.ChartBaseActivator; |
||||
import com.fr.cluster.engine.activator.standalone.StandaloneModeActivator; |
||||
import com.fr.config.activator.BaseDBActivator; |
||||
import com.fr.config.activator.ConfigurationActivator; |
||||
import com.fr.env.operator.CommonOperatorImpl; |
||||
import com.fr.form.export.FormToWBExecutor; |
||||
import com.fr.general.I18nResource; |
||||
import com.fr.io.TemplateWorkBookIO; |
||||
import com.fr.io.exporter.ImageExporter; |
||||
import com.fr.io.exporter.PDFExporter; |
||||
import com.fr.io.exporter.excel.stream.StreamExcel2007Exporter; |
||||
import com.fr.main.impl.WorkBook; |
||||
import com.fr.main.workbook.ResultWorkBook; |
||||
import com.fr.module.Module; |
||||
import com.fr.module.tool.ActivatorToolBox; |
||||
import com.fr.report.ReportActivator; |
||||
import com.fr.report.RestrictionActivator; |
||||
import com.fr.report.module.ReportBaseActivator; |
||||
import com.fr.report.write.WriteActivator; |
||||
import com.fr.scheduler.SchedulerActivator; |
||||
import com.fr.stable.WriteActor; |
||||
import com.fr.store.StateServerActivator; |
||||
import com.fr.workspace.simple.SimpleWork; |
||||
|
||||
import java.io.File; |
||||
import java.io.FileOutputStream; |
||||
|
||||
public class ExportApi_frm { |
||||
public static void main(String[] args) { |
||||
// 定义报表运行环境,用于执行报表
|
||||
Module module = ActivatorToolBox.simpleLink(new BaseDBActivator(), |
||||
new ConfigurationActivator(), |
||||
new StandaloneModeActivator(), |
||||
new StateServerActivator(), |
||||
new SchedulerActivator(), |
||||
new ReportBaseActivator(), |
||||
new RestrictionActivator(), |
||||
new ReportActivator(), |
||||
new WriteActivator(), |
||||
new ChartBaseActivator()); |
||||
SimpleWork.supply(CommonOperator.class, new CommonOperatorImpl()); |
||||
String envpath = "C:\\Users\\hipsh\\Desktop\\apache-tomcat-8.5.38-10.0\\webapps\\webroot\\WEB-INF\\";//工程路径
|
||||
SimpleWork.checkIn(envpath); |
||||
I18nResource.getInstance(); |
||||
module.start(); |
||||
try { |
||||
|
||||
java.util.Map parameterMap = new java.util.HashMap(); |
||||
parameterMap.put("aa", "1"); |
||||
ResultWorkBook re = FormToWBExecutor.executeForm("test.frm",parameterMap); |
||||
// 定义输出流
|
||||
FileOutputStream outputStream; |
||||
// 将结果工作薄导出为Excel文件
|
||||
outputStream = new FileOutputStream(new File("C:\\FTPServer\\1528.xlsx")); |
||||
StreamExcel2007Exporter ExcelExport1 = new StreamExcel2007Exporter(); |
||||
ExcelExport1.export(outputStream,re); |
||||
// 将结果工作薄导出为PDF文件
|
||||
outputStream = new FileOutputStream(new File("C:\\FTPServer\\PdfExport.pdf")); |
||||
PDFExporter PdfExport = new PDFExporter(); |
||||
PdfExport.export(outputStream, re); |
||||
//将结果工作薄导出为Image文件
|
||||
outputStream = new FileOutputStream(new File("C:\\FTPServer\\PngExport.png")); |
||||
ImageExporter ImageExport = new ImageExporter(); |
||||
ImageExport.export(outputStream, re); |
||||
outputStream.close(); |
||||
module.stop(); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} finally { |
||||
SimpleWork.checkOut(); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue