Apache poi merges cells horizontally and vertically

Merging cells is a common requirement. The principle of apache POI's merging cells is very simple. It means that the cells from the upper left to the lower right will be merged by the upper left. Whether it is horizontal or vertical, this is the principle. The key API method

org.apache.poi.hssf.model.InternalSheet#addMergedRegion
public int addMergedRegion(int rowFrom, int colFrom, int rowTo, int colTo)
  • rowFrom, the starting row
  • colFrom, start column
  • rowTo, terminate the row
  • colTo, the terminating column

(rowFrom, colFrom) constitutes the start node, (rowTo, colTo) constitutes the end node, as long as it is in this area, it will be merged into the upper left cell.

For more complex merged cells, for example, grade----class----student, each merge needs to be counted. For example, how many rows are merged by class depends on how many students there are in the class, and the merged rows of grades are occupied by all classes row count and .
insert image description here

Guess you like

Origin blog.csdn.net/wangjun5159/article/details/127744001