//Obtaining the reference of the PageSetup of the worksheet PageSetup pageSetup = sheet.getPageSetup(); //Defining column numbers A & B as title columns pageSetup.setPrintTitleColumns("$A:$B"); //Defining row numbers 1 & 2 as title rows pageSetup.setPrintTitleRows("$1:$2");