1. Requirements:
The exported Excel has multiple sheets, and the format of the tables in each sheet is different
2. Implementation idea
1. Write all sheet templates on the first index page;
2. Using jX :if notation of Jxls, determine which region of the script to load by judging a variable in each sheet object;
Practice 3.
The command at A1 is as follows:
jx:area(lastCell="R45") jx:each(items="sheetList", var="sheet", lastCell="R45" multisheet="sheetNames") jx:if(condition="sheet.sheetNum==1" lastCell="R17" areas=["A1:R17"]) jx:if(condition="sheet.sheetNum==2" lastCell="R29" areas=["A18:R29"]) jx:if(condition="sheet.sheetNum==3" lastCell="R41" areas=["A30:R41"]) jx:if(condition="sheet.sheetNum==4" lastCell="R45" areas=["A42:R45"])Copy the code
Command explanation:
1. Jx :area The maximum range of the JXLS command is A1:R45.
2. Jx :each iterates over a single sheet object in the sheet collection, which stores all the elements in a sheet;
Sheet. SheetNum is a variable whose value actually means the number of sheets in Excel in which commands will be loaded
The traversal commands for A4, A9, and A21 are as follows:
jx:each(items="sheet.context.disburseDetailsByHospitalLevel" var="record" lastCell="Z4")
jx:each(items="sheet.context.mechanismDisburseRankByHospitalLevel" var="record" lastCell="G9")
jx:each(items="sheet.context.mechanismDisburseGrowthRankByHospitalLevel" var="record" lastCell="G14")
Copy the code
Simply use jx:each to iterate over the object you want to display;
4. Conclusion:
Only jx:if command should be used to judge the sheet object in the annotation of cell A1 and delimit the boundary of loading each region.
5. Precautions:
1. Please pay attention to the lastCell and areas in JX: IF. Improper setting may cause blank lines in the second or later sheet after rendering.
Such as:
(jx:if(condition=" sheet.sheetnum ==1" lastCell="R17")) (jx:if(condition=" sheet.sheetnum ==1") (areas=["A1:R17"]) LastCell ="R16" areas=["A1:R16"]) Then the first row of the second sheet will be empty and the rendering of the table will start from the second row. If you write jx:if(condition="sheet.sheetNum==1" lastCell="R15" areas=["A1:R15"]) then there will be two empty linesCopy the code