2016-05-16 7 views
0

Ich erzeuge xls-Dateien mit Hilfe von JExcelApi. Jetzt muss ich die Header sperren, weil ich mehr als 300 Zeilen habe.Wie man eine komplette Zeile in Excel mit JExcelApi einfriert?

Immer wenn ich blättern muss, müssen Header angezeigt werden. Kann mir jemand helfen, das zu lösen? Ich habe viele Seiten erkundet, aber ich habe keine Lösung dafür gefunden. mit setHorizontalFreeze (int row) oder setVerticalFreeze (int col) in SheetSettings Klasse

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(); 

Antwort

0

Sie sollten in der Lage sein, Zeilen oder Spalten einzufrieren.

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

+0

gibt es ein Beispiel. Ich habe den oben genannten Link gesehen, aber ich bin nicht in der Klugheit, wie ich neu bin. Einfach aufrufen der setHorizontalFreeze (int Zeile) ist genug> – Bhanu

+0

es ist einfach als Aufruf der setHorizontalFreeze Methode mit der Zeilennummer. Wenn Sie nach Beispielen suchen, Google Search gibt mir das: http://r4r.co.in/java/apis/jexcel/basic/tutorial/jexcel_basic_tutorials.php?qid=679 – Vijay

+0

Wenn wir die eine Zeile geben, die komplette Reihe ist Freezed richtig? – Bhanu

Verwandte Themen