ExcelWorkbook wk = new ExcelWorkbookParser().parseFromVirtualPath(path);
或者
wk = new ExcelWorkbookParser().parseFromResource(new FileResource(file));
根据imp.xml导入配置来实现自动解析Excel文件为领域模型对象。
FileResource resource = new FileResource(new File("c:/test.orm.xlsx"));
OrmModel ormModel = (OrmModel) new XlsxObjectLoader("/nop/orm/imp/orm.imp.xml").parseFromResource(resource);
new ExcelTemplate(workbook).generateToFile(file, DisabledEvalScope.INSTANCE);
ITemplateOutput output = reportEngine.getRendererForExcel(workbook, XptConstants.RENDER_TYPE_HTML);
output.generateToFile(file, DisabledEvalScope.INSTANCE);
或者
ITextTemplateOutput output = reportEngine.getHtmlRenderer(workbook);
String html = output.generateText(DisabledEvalScope.INSTANCE);
参考GenOrmHelper.saveOrmToExcel函数
IEvalScope scope = XLang.newEvalScope();
scope.setLocalValue(null, XptConstants.VAR_ENTITY, ormModel);
ExcelWorkbook workbook = reportEngine.buildXptModelFromImpModel("/nop/orm/imp/orm.imp.xml");
ITemplateOutput output = reportEngine.getRendererForXptModel(workbook, "xlsx");
output.generateToFile(outputFile, scope);
ExcelSheet configSheet = workbook.getSheet("Config");
XLangCompileTool compileTool = XLang.newCompileTool().allowUnregisteredScopeVar(true);
ImportModel importModel = ImportModelHelper.getImportModel(RuleConstants.IMP_PATH_RULE);
ImportSheetModel sheetModel = importModel.getSheet(RuleConstants.SHEET_NAME_CONFIG);
RuleModel rule = ImportModelHelper.parseSheet(sheetModel, configSheet, compileTool, RuleModel.class);