2016-05-16 5 views
0

Je génère des fichiers xls en utilisant JExcelApi. Maintenant, ce dont j'ai besoin est de verrouiller les en-têtes car j'ai plus de 300 lignes.Comment geler une ligne complète dans Excel avec JExcelApi?

Chaque fois que je défile, j'ai besoin d'en-têtes à afficher. Quelqu'un peut-il m'aider à résoudre cela. J'ai exploré de nombreux sites mais je n'ai pas eu la solution pour cela.

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

Répondre

0

vous devriez être en mesure de geler des lignes ou des colonnes à l'aide setHorizontalFreeze (ligne int) ou setVerticalFreeze (int col) dans la classe de SheetSettings.

se réfèrent: http://jexcelapi.sourceforge.net/resources/javadocs/2_4_3/docs/jxl/SheetSettings.html

+0

est-il un exemple. J'ai vu le lien ci-dessus, mais je ne suis pas au clirity comme je suis nouveau .. Il suffit d'appeler le setHorizontalFreeze (ligne int)> – Bhanu

+0

son simple comme appelant la méthode setHorizontalFreeze avec le numéro de ligne. Si vous cherchez des exemples, google recherche me donne ceci: http://r4r.co.in/java/apis/jexcel/basic/tutorial/jexcel_basic_tutorials.php?qid=679 – Vijay

+0

Si nous donnons la ligne, le complet rangée est gelée à droite? – Bhanu