表格内容对齐

显示效果:

示例代码所生成的OFD文件:下载

 示例代码

package test.create.c04;


import iofd.layout.OfdDocument;
import iofd.layout.block.Paragraph;
import iofd.layout.block.Table;

import java.util.ArrayList;
import java.util.List;

import test.create.TestDocUtil;

public class C0408NumberAutoAlignRight {

	public static void main(String[] args) throws Throwable {
		C0408NumberAutoAlignRight o = new C0408NumberAutoAlignRight();
		o.done();
	}

	private void done() throws Throwable {
		String clzName = this.getClass().getSimpleName();
		System.out.println(clzName + " begin");
		
		OfdDocument doc = new OfdDocument();
		
		String s = "这是一个表格的示例:涉及数字的,如果没有配置对齐方式,默认水平靠右对齐;其他类型字符串默认靠右排列。";
		Paragraph p = new Paragraph();
		p.add(s);
		doc.add(p);
		
		List head = new ArrayList<>();
		head.add("标题一");
		head.add("标题二");
		head.add("标题三");
		head.add("标题四");
		head.add("标题五");
		
		List> data = new ArrayList<>();
		
		for(int i = 0; i < 10; i++) {
			List row = new ArrayList<>();
			for(int j = 0; j < 5; j++) {
				if(j == 0){
					StringBuilder sb = new StringBuilder();
					sb.append("[").append(100 + i).append(",").append(j).append("]");
					row.add(sb.toString());
				} else {
					row.add(12345 * (i + j));
				}
			}
			data.add(row);
		}
		
		Table table = new Table(head, data);
		doc.add(table);
		
		String fileName = TestDocUtil.getOfdFilePath(this.getClass());
		doc.save(fileName);
		System.out.println(clzName + " end");
	}
}