forked from demo/example
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
3.0 KiB
79 lines
3.0 KiB
6 years ago
|
//遍历单元格
|
||
|
package com.fr.demo;
|
||
|
|
||
|
import com.fr.io.TemplateWorkBookIO;
|
||
|
import com.fr.main.TemplateWorkBook;
|
||
|
import com.fr.report.cell.TemplateCellElement;
|
||
|
import com.fr.report.elementcase.TemplateElementCase;
|
||
|
import com.fr.report.worksheet.WorkSheet;
|
||
|
import com.fr.web.core.Reportlet;
|
||
|
import com.fr.web.request.ReportletRequest;
|
||
|
import com.fr.workspace.simple.SimpleWork;
|
||
|
|
||
|
import java.util.Map;
|
||
|
|
||
|
|
||
|
public class ChangeRowAndCol extends Reportlet {
|
||
|
public TemplateWorkBook createReport(ReportletRequest reportletrequest) {
|
||
|
// 定义最终需要返回的WorkBook对象
|
||
|
TemplateWorkBook workbook = null;
|
||
|
String envPath = "D:\\FineReport_8.0\\WebReport\\WEB-INF";
|
||
|
SimpleWork.checkIn(envPath);
|
||
|
WorkSheet newworksheet = new WorkSheet();
|
||
|
String change = "0";
|
||
|
try {
|
||
|
// 读取模板保存为WorkBook对象
|
||
|
workbook = TemplateWorkBookIO.readTemplateWorkBook(
|
||
|
"\\doc\\Primary\\GroupReport\\Group.cpt");
|
||
|
// 读取请求中的参数判断是否需要切换行列显示,0表示不切换,1表示切换
|
||
|
if (reportletrequest.getParameter("change") != null) {
|
||
|
change = reportletrequest.getParameter("change").toString();
|
||
|
}
|
||
|
if (change.equals("1")) {
|
||
|
// 获得单元格需要首先获得单元格所在的报表
|
||
|
TemplateElementCase report = (TemplateElementCase) workbook
|
||
|
.getTemplateReport(0);
|
||
|
// 遍历单元格
|
||
|
int col = 0, row = 0;
|
||
|
byte direction = 0;
|
||
|
java.util.Iterator it = report.cellIterator();
|
||
|
while (it.hasNext()) {
|
||
|
TemplateCellElement cell = (TemplateCellElement) it.next();
|
||
|
// 获取单元格的行号与列号并互换
|
||
|
col = cell.getColumn();
|
||
|
row = cell.getRow();
|
||
|
cell.setColumn(row);
|
||
|
cell.setRow(col);
|
||
|
// 获取原单元格的扩展方向,0表示纵向扩展,1表示横向扩展
|
||
|
direction = cell.getCellExpandAttr().getDirection();
|
||
|
if (direction == 0) {
|
||
|
cell.getCellExpandAttr().setDirection((byte) 1);
|
||
|
} else if (direction == 1) {
|
||
|
cell.getCellExpandAttr().setDirection((byte) 0);
|
||
|
}
|
||
|
// 将改变后的单元格添加进新的WorkSheet中
|
||
|
newworksheet.addCellElement(cell);
|
||
|
}
|
||
|
// 替换原sheet
|
||
|
workbook.setReport(0, newworksheet);
|
||
|
}
|
||
|
} catch (Exception e) {
|
||
|
e.printStackTrace();
|
||
|
} finally {
|
||
|
SimpleWork.checkOut();
|
||
|
}
|
||
|
return workbook;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void setParameterMap(Map arg0) {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void setTplPath(String arg0) {
|
||
|
// TODO Auto-generated method stub
|
||
|
|
||
|
}
|
||
|
}
|