图一:图二:同一个sheet中,上图表格为模版1至21行,下图表格是上图表格复制过来的,从22行至43行。整个表格都可以复制。就是里面的形状(黑圆圈和白圆圈,在excel通过插入形状插入的)不能复制,用的是poi读取excel。下面是我写的复制表格的方法,求懂的人帮我看一下。如何改,或写一个读取excel形状的调用方法、能复制上面表格的形状到下一个表格的对应位置,(黑圈、白圈,和大圆)。谢谢。技术交流!
       /**
 * 复制行
 * @param wb 
 * @param st
 * @param startRow 
 * @param endRow   
 * @param pPosition 
 * @param jempRow 递增变量 =23
 * @throws Exception
 */
public static void copyRows(HSSFWorkbook wb, HSSFSheet st, int startRow,
int endRow, int pPosition, int jempRow) throws Exception {
int pStartRow = startRow - 1;
int pEndRow = endRow - 1;
int targetRowFrom;
int targetRowTo;
int columnCount;
CellRangeAddress region = null;
int i;
int j;
if (pStartRow == -1 || pEndRow == -1)
return;
for (i = 0; i < st.getNumMergedRegions(); i++) {
region = (CellRangeAddress) st.getMergedRegion(i);
if ((region.getFirstRow() >= pStartRow)
&& (region.getLastRow() <= pEndRow)) {
targetRowFrom = region.getFirstRow() - pStartRow + pPosition;
targetRowTo = region.getLastRow() - pStartRow + pPosition;
CellRangeAddress newRegion = (CellRangeAddress) region.copy();
newRegion.setFirstRow(targetRowFrom);
newRegion.setFirstColumn(region.getFirstColumn());
newRegion.setLastRow(targetRowTo);
newRegion.setLastColumn(region.getLastColumn());
st.addMergedRegion(newRegion);
}
}
// set the column height and value
for (i = pStartRow; i <= pEndRow; i++) {
HSSFRow sourceRow = st.getRow(i);
columnCount = sourceRow.getLastCellNum();
if (sourceRow != null) {
HSSFRow newRow = st.createRow(pPosition + i);
newRow.setHeight(sourceRow.getHeight());
for (j = 0; j < columnCount; j++) {
HSSFCell templateCell = sourceRow.getCell(j);
if (templateCell != null) {
HSSFCell newCell = newRow.createCell(j);
copyCell(templateCell, newCell);

}
}
}
}
}qq交流:553432206。项目比较紧、谢谢大家。poiExcel