我的excel中有多行,除了顶行,其他行的内容都很小。只是为了在顶行插入一个大标题,我不希望后续行的宽度受到影响。有没有一种方法可以在不影响后续行宽度的情况下将顶行中的内容跨越多列。
发布于 2013-06-20 22:31:42
是的,通过使用WritableSheet.mergeCells方法。
例如:
WritableWorkbook w = Workbook.createWorkbook(outputStream);
WritableSheet s = w.createSheet("MySheet", 0);
int row = 0;
WritableCell titleCell = new Label(0, row, "Hello World");
s.addCell(titleCell);
s.mergeCells(0, row, 13, row);这具有使第一行具有13个单元的宽度的效果,并且不会影响后续行的单元宽度。请注意,这将允许您合并行,但这将不起作用。更改行高的正确方法是:
/* Row heights are in 20ths of a point */
int fontPointSize = 16;
int rowHeight = (int) ((1.5d * fontPointSize) * 20);
s.setRowView(row, rowHeight, false);发布于 2016-08-30 22:23:12
这是可能的,玩玩这个吧。希望能对你有所帮助。
int col1 = 0;
int col2 = 2;
int row1 = 0;
int row2 = 0;
WritableWorkbook workbook = Workbook.createWorkbook(outputStream);
WritableSheet sheet = workbook.createSheet("MySheet", 0);
sheet.mergeCells(col1,row1,col2,row2);
//This makes the cell at row1 and col1 span the next two cells
//Write content at the marge cell
sheet.addCell(new Label(col1,row1,"Content here"));参考文献:first reference和socond reference
https://stackoverflow.com/questions/15515263
复制相似问题