怎样使导出的txt内容对齐
客户要求导出的txt文件内容对齐,切没有边框。
需求实现
利用api导出txt文件,在导出之前设置ReportDefine的边框为无边框再利用ReportUtils.exportToText(os, ireport);方法导出即可。
示例代码如下:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import com.runqian.report4.model.ReportDefine;
import com.runqian.report4.model.engine.ExtCellSet;
import com.runqian.report4.usermodel.Context;
import com.runqian.report4.usermodel.Engine;
import com.runqian.report4.usermodel.IReport;
import com.runqian.report4.util.ReportUtils;
import com.runqian.report4.view.text.TextFile;
public class TestTextReport {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
ReportDefine rd = (ReportDefine)ReportUtils.read(“d:\\Program Files (x86)\\reportHome4543\\webapps\\demo\\reportFiles\\test_txt.raq”);
//TextFile textFile = new TextFile(ireport,” “,”\n”);
//String text = textFile.toString();
//System.out.println(text);
int r = rd.getRowCount();
int c = rd.getColCount();
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
//rd.setTBWidth(i, (short)j, (float)1);
rd.setBBStyle(i, (short)j, (byte)80);
rd.setTBStyle(i, (short)j, (byte)80);
rd.setLBStyle(i, (short)j, (byte)80);
rd.setRBStyle(i, (short)j, (byte)80);
}
}
Context ctx = new Context();
Engine engine = new Engine(rd,ctx);
IReport ireport = engine.calc();
ExtCellSet.setLicenseFileName(“d:\\Program Files (x86)\\reportHome4543\\webapps\\demo\\WEB-INF\\classes\\runqianWindowServer.lic”);//设置授权
OutputStream os = new FileOutputStream(“D:\\TEXT.txt”);//创建导出的输出流
ReportUtils.exportToText(os, ireport);
OutputStreamWriter osw = new OutputStreamWriter(os);
//osw.write(text,0,text.length());//内容写到流中
osw.close();
os.close();
}
}