我正在使用JExcelApi生成xls文件。现在,我需要锁定标题,因为我有300多行。
每当我滚动时,都需要显示标题。谁能帮我解决这个问题。我浏览了很多站点,但没有得到解决方案。
OutputStream out = servletResponse.getOutputStream();
servletResponse.setContentType("application/vnd.ms-excel");
WorkbookSettings wbSettings = new WorkbookSettings();
wbSettings.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook = Workbook.createWorkbook(out, wbSettings);
workbook.createSheet("Employee Details", 0);
WritableSheet excelSheet = workbook.getSheet(0);
WritableFont times11pt = new WritableFont(WritableFont.TIMES, 11);
WritableCellFormat times = new WritableCellFormat(times11pt);
// times.setWrap(true);
times.setVerticalAlignment(VerticalAlignment.BOTTOM);
WritableCellFormat timesCenter = new WritableCellFormat(times11pt);
timesCenter.setWrap(true);
timesCenter.setAlignment(Alignment.CENTRE);
timesCenter.setVerticalAlignment(VerticalAlignment.BOTTOM);
WritableFont times11ptBold = new WritableFont(WritableFont.TIMES, 11,
WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE);
WritableCellFormat timesBold = new WritableCellFormat(times11ptBold);
timesBold.setBackground(Colour.YELLOW);
timesBold.setWrap(true);
timesBold.setAlignment(Alignment.CENTRE);
timesBold.setVerticalAlignment(VerticalAlignment.CENTRE);
WritableCellFormat timesBoldLeft = new WritableCellFormat(times11ptBold);
// timesBold.setBackground(Colour.YELLOW);
timesBoldLeft.setWrap(true);
timesBoldLeft.setAlignment(Alignment.LEFT);
timesBoldLeft.setVerticalAlignment(VerticalAlignment.CENTRE);
WritableFont times11ptTitle = new WritableFont(WritableFont.TIMES, 14,
WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE);
WritableCellFormat timesTitle = new WritableCellFormat(times11ptTitle);
// timesBold.setBackground(Colour.YELLOW);
timesTitle.setWrap(true);
timesTitle.setAlignment(Alignment.LEFT);
timesTitle.setVerticalAlignment(VerticalAlignment.CENTRE);
int rows = 6;
int maxcolumn = 0;
int sno = 1;
// TITLE CELL
//excelSheet.mergeCells(0, 0, datesBetween.size() + 4, 1);
/*addCaption(excelSheet, 0, 0, companyName, timesTitle);*/
// get current date time with Date()
DateFormat dateFormat = new SimpleDateFormat(
"EE, MMM dd, yyyy HH:mm:ss a");
Date currDate = new Date();
String currentDate = "" + dateFormat.format(currDate);
// excelSheet.mergeCells(1, 2, 2, 2);
// excelSheet.mergeCells(0, 2, datesBetween.size()+4, 2);
addCaption(excelSheet, 2, 2, "Duration: " + from + " to " + to,
timesBoldLeft);
// excelSheet.mergeCells(1, 3, 2, 3);
// excelSheet.mergeCells(0, 3, datesBetween.size()+4, 3);
addCaption(excelSheet, 2, 3, "Genrated On : " + currentDate,
timesBoldLeft);
timesBold.setBackground(Colour.YELLOW);
timesBold.setWrap(true);
timesBold.setVerticalAlignment(VerticalAlignment.TOP);
addCaption(excelSheet, 0, 5, "S.No.", timesBold);
addCaption(excelSheet, 1, 5, "Employee Name ", timesBold);
addCaption(excelSheet, 2, 5, "Employee Address", timesBold);
addCaption(excelSheet, 3, 5, "Employee City", timesBold);
excelSheet.getSettings().setHorizontalFreeze(5);
workbook.write();
workbook.close();
out.flush();
out.close();
最佳答案
您应该能够在SheetSettings类中使用setHorizontalFreeze(int row)或setVerticalFreeze(int col)冻结行或列。
参考:http://jexcelapi.sourceforge.net/resources/javadocs/2_4_3/docs/jxl/SheetSettings.html