后台修改报表
客户有时候希望润乾的程序可以帮客户做一些力气活,比如我们可以导入excel成raq文件这样就可以省去客户很多事。
实际工作遇到的问题
一个客户希望把他的普通报表改成填报表,并且把他单元格的表达式写到填报表的自动计算中。这是客户又不想一个单元格一个单元格的改该怎么办呢。这时我们的API就需要出场了。
首先需要读取客户的raq文件,然后获取单元格的属性,把报表改成填报表,然后把拿到的单元格值赋予到自动计算中。部分代码:
ReportDefine rd = (ReportDefine)ReportUtils.read(application.getRealPath(reportFileHome)+”\\S41.raq”);
Context context = new Context();
Engine enging = new Engine( rd, context);
IReport ireport = enging.calc();
int rowCount = ireport.getRowCount();
int ColCount = ireport.getColCount();
ReportDefine ad=new ReportDefine2(rowCount,ColCount);
ad.setInput(ReportDefine.INPUT_NORMAL);//非填报
ad.setSubmit(ReportDefine.SUBMIT_UPDATABLE_WRITABLE);//数据提交方案设置
ad.setReportType(ReportDefine.RPT_NORMAL);//设置填报类型
for (int i = 1; i <= rowCount; i++) {
for (int j = 1; j <= ColCount; j++) {
INormalCell NCell = ireport.getCell(i, (short) j);
Object value = NCell.getValue();
NCell.getInputProperty();
System.out.println( NCell.getInputProperty());
INormalCell iCell = ad.getCell(i, (short) j);
iCell.setValue(value);//单元格值
iCell.setInputProperty( NCell.getInputProperty());//填报属性
if(iCell.getInputProperty()!=null){
IByteMap map1=new ByteMap();
map1.put(INormalCell.VALUE,value); //设置单元格的数据值表达式
iCell.setExpMap(map1);
iCell.setValue(“”);
InputProperty ip= iCell.getInputProperty();
ip.setAutoCalc((String)value);
}
}
try { ReportUtils.write(application.getRealPath(reportFileHome)+”\\123456.raq”,ad);
} catch (Exception e) {
e.printStackTrace();
}
这样客户不停的发布做好的报表就可以实现报表的转换了。