gpt4 book ai didi

java - 如何使用 JExcelApi 卡住 Excel 中的整行?

转载 作者:太空宇宙 更新时间:2023-11-04 12:36:45 26 4
gpt4 key购买 nike

我正在使用 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 类中使用 setHorizo​​ntalFreeze(int row) 或 setVerticalFreeze(int col) 卡住行或列。

引用:http://jexcelapi.sourceforge.net/resources/javadocs/2_4_3/docs/jxl/SheetSettings.html

关于java - 如何使用 JExcelApi 卡住 Excel 中的整行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37250022/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com