forked from demo/example
zack
5 years ago
42 changed files with 222 additions and 66 deletions
@ -0,0 +1,51 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<WorkBook xmlVersion="20170720" releaseVersion="10.0.0"> |
||||||
|
<Report class="com.fr.report.worksheet.WorkSheet" name="sheet1"> |
||||||
|
<ReportPageAttr> |
||||||
|
<HR/> |
||||||
|
<FR/> |
||||||
|
<HC/> |
||||||
|
<FC/> |
||||||
|
</ReportPageAttr> |
||||||
|
<ColumnPrivilegeControl/> |
||||||
|
<RowPrivilegeControl/> |
||||||
|
<RowHeight defaultValue="723900"> |
||||||
|
<![CDATA[723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900,723900]]></RowHeight> |
||||||
|
<ColumnWidth defaultValue="2743200"> |
||||||
|
<![CDATA[2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200,2743200]]></ColumnWidth> |
||||||
|
<CellElementList> |
||||||
|
<C c="0" r="0"> |
||||||
|
<O t="XMLable" class="com.fr.base.Formula"> |
||||||
|
<Attributes> |
||||||
|
<![CDATA[=SUM(B1,B1)]]></Attributes> |
||||||
|
</O> |
||||||
|
<PrivilegeControl/> |
||||||
|
<Expand/> |
||||||
|
</C> |
||||||
|
<C c="1" r="0"> |
||||||
|
<O t="I"> |
||||||
|
<![CDATA[3]]></O> |
||||||
|
<PrivilegeControl/> |
||||||
|
<Expand/> |
||||||
|
</C> |
||||||
|
</CellElementList> |
||||||
|
<ReportAttrSet> |
||||||
|
<ReportSettings headerHeight="0" footerHeight="0"> |
||||||
|
<PaperSetting/> |
||||||
|
<Background name="ColorBackground" color="-1"/> |
||||||
|
</ReportSettings> |
||||||
|
</ReportAttrSet> |
||||||
|
<PrivilegeControl/> |
||||||
|
</Report> |
||||||
|
<ReportParameterAttr> |
||||||
|
<Attributes showWindow="true" delayPlaying="true" windowPosition="1" align="0" useParamsTemplate="true"/> |
||||||
|
<PWTitle> |
||||||
|
<![CDATA[参数]]></PWTitle> |
||||||
|
</ReportParameterAttr> |
||||||
|
<StyleList/> |
||||||
|
<DesignerVersion DesignerVersion="KAA"/> |
||||||
|
<PreviewType PreviewType="0"/> |
||||||
|
<TemplateIdAttMark class="com.fr.base.iofile.attr.TemplateIdAttrMark"> |
||||||
|
<TemplateIdAttMark TemplateId="56859b48-9102-476b-a84f-09ff9b64e606"/> |
||||||
|
</TemplateIdAttMark> |
||||||
|
</WorkBook> |
@ -0,0 +1,85 @@ |
|||||||
|
package com.fr.demo; |
||||||
|
|
||||||
|
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.general.I18nResource; |
||||||
|
import com.fr.io.TemplateWorkBookIO; |
||||||
|
import com.fr.io.exporter.excel.stream.StreamExcel2007Exporter; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import com.fr.main.TemplateWorkBook; |
||||||
|
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.worksheet.WorkSheet; |
||||||
|
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 com.fr.write.web.excel.ExcelImportPlusProcessor; |
||||||
|
import junit.framework.TestCase; |
||||||
|
import org.junit.Assert; |
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream; |
||||||
|
import java.io.ByteArrayOutputStream; |
||||||
|
import java.io.InputStream; |
||||||
|
import java.util.HashMap; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author zack |
||||||
|
* @version 10.0 |
||||||
|
* @date 2019/8/27 |
||||||
|
*/ |
||||||
|
public class ExportApiTest extends TestCase { |
||||||
|
public void testExport() { |
||||||
|
Module module = ActivatorToolBox.simpleLink(new BaseDBActivator(), |
||||||
|
new ConfigurationActivator(), |
||||||
|
new StandaloneModeActivator(), |
||||||
|
new StateServerActivator(), |
||||||
|
new ChartBaseActivator(), |
||||||
|
new SchedulerActivator(), |
||||||
|
new ReportBaseActivator(), |
||||||
|
new RestrictionActivator(), |
||||||
|
new ReportActivator(), |
||||||
|
new WriteActivator()); |
||||||
|
SimpleWork.supply(CommonOperator.class, new CommonOperatorImpl()); |
||||||
|
SimpleWork.checkIn(ExportApiTest.class.getResource("../../../WEB-INF").getPath()); |
||||||
|
I18nResource.getInstance(); |
||||||
|
module.start(); |
||||||
|
|
||||||
|
|
||||||
|
ResultWorkBook rworkbook = null; |
||||||
|
try { |
||||||
|
// 未执行模板工作薄
|
||||||
|
WorkBook workbook = (WorkBook) TemplateWorkBookIO |
||||||
|
.readTemplateWorkBook("//sumtest.cpt"); |
||||||
|
// 获取报表参数并设置值,导出内置数据集时数据集会根据参数值查询出结果从而转为内置数据集
|
||||||
|
// 定义parametermap用于执行报表,将执行后的结果工作薄保存为rworkBook
|
||||||
|
java.util.Map parameterMap = new java.util.HashMap(); |
||||||
|
// 定义输出流
|
||||||
|
ByteArrayOutputStream outputStream; |
||||||
|
// 将结果工作薄导出为Excel文件
|
||||||
|
outputStream = new ByteArrayOutputStream(); |
||||||
|
StreamExcel2007Exporter ExcelExport1 = new StreamExcel2007Exporter(); |
||||||
|
ExcelExport1.export(outputStream, workbook.execute(parameterMap, new WriteActor())); |
||||||
|
outputStream.close(); |
||||||
|
InputStream in = new ByteArrayInputStream(outputStream.toByteArray()); |
||||||
|
TemplateWorkBook workBook = new ExcelImportPlusProcessor().generateWorkBookByStream(in, "111.xlsx", new HashMap()); |
||||||
|
Assert.assertEquals(6, ((WorkSheet) workBook.getReport(0)).getCellElement(0, 0).getValue()); |
||||||
|
Assert.assertEquals(3, ((WorkSheet) workBook.getReport(0)).getCellElement(1, 0).getValue()); |
||||||
|
module.stop(); |
||||||
|
} catch (Exception e) { |
||||||
|
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||||
|
} finally { |
||||||
|
SimpleWork.checkOut(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue