0
我使用JExcelApi生成xls文件。现在我需要的是锁定标题,因为我有超过300行。如何使用JExcelApi冻结Excel中的完整行?
每当我滚动我需要有标题显示。任何人都可以帮助我解决这个问题。我已经探索了很多网站,但我没有得到解决方案。
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();
有没有任何例子。我已经看过上面的链接,但是我不是很清楚,因为我是新的。只需调用setHorizontalFreeze(int row)就足够了> – Bhanu
它简单,就像使用行号调用setHorizontalFreeze方法一样。如果你正在寻找的例子,谷歌搜索给了我这个:http://r4r.co.in/java/apis/jexcel/basic/tutorial/jexcel_basic_tutorials.php?qid=679 – Vijay
如果我们给一行,完整行是冻结的权利? – Bhanu