cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in export to excel

Former Member
0 Kudos

Hi,

I have implemented the export to excel functionality in web dynpro java.It is working fine when the output in the table is more than one.

But if there only one output in the table then in the export to excel function,there is no header in the excel sheet for the single row of data.

Could anyone please suggest how to get the header in the downloaded excel sheet even if there is single row data in the table.

Thanks,

Rajani

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Rajini,

It would be nice if you could share the procedure to export data to excel sheet step by step.

Regards

Raghu

Former Member
0 Kudos

Hi,

May i know whats the code you used to generate excel sheet.

See this sample code to generate a form, like this you can generate headers and all


import java.io.File;
import java.io.IOException;

import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.Border;
import jxl.format.BorderLineStyle;
import jxl.format.Colour;
import jxl.format.VerticalAlignment;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

public class WriteExcel {

	public static void main(String[] args) {
		
			try {
				WritableWorkbook workbook = Workbook.createWorkbook(new File("Vacc.xls"));
				WritableSheet sheet = workbook.createSheet("AccSheet", 0);
				
				//Title
				WritableFont titlefont = new WritableFont(WritableFont.TIMES, 20,WritableFont.BOLD); 
				WritableCellFormat titleformat=new WritableCellFormat(titlefont);
				titleformat.setAlignment(Alignment.CENTRE);
				titleformat.setBorder(Border.ALL,BorderLineStyle.THICK,Colour.GREEN);
				titleformat.setVerticalAlignment(VerticalAlignment.CENTRE);
				Label title=new Label(1,0,"Vendor Account Form",titleformat);
				sheet.setColumnView(1,19);
				sheet.setColumnView(2,19);
				sheet.mergeCells(1,0,2,2);
				sheet.addCell(title);
				
				//fields
				WritableFont fieldsfont = new WritableFont(WritableFont.ARIAL, 10,WritableFont.BOLD); 
				WritableFont valuesfont = new WritableFont(WritableFont.ARIAL, 10); 
				WritableCellFormat fieldsformat=new WritableCellFormat(fieldsfont);
				WritableCellFormat valuessformat=new WritableCellFormat(fieldsfont);
				valuessformat.setBorder(Border.ALL,BorderLineStyle.THIN);
				String fields[]={"Vendor Id","Vendor Name","Vendor Address","Material Id","Quantity","Amount"};
				int j=4;
				for(int i=0;i<fields.length;i++){
					Label field=new Label(1,j,fields<i>,fieldsformat);
					sheet.addCell(field);
					 
					if(i<=3){
						Label value=new Label(2,j,"",valuessformat);
						sheet.addCell(value);
					} else{
					   Number value=new Number(2,j,0,valuessformat);
					   sheet.addCell(value);
					}
					j++;
					j++;
				}
			
				
				
				workbook.write(); 
				workbook.close(); 
			} catch (RowsExceededException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (WriteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		
		
	}
}

Former Member
0 Kudos

Hi naga,

Where it creates the excel sheet?

In server or on local machine.

On which path?

Regards,

Bala

Former Member
0 Kudos

Hi ,

Its a sample one.

Its normal standalone java application creates excel sheet in client side using Jxl API.

Regards,

Naga

Former Member
0 Kudos

Hi,

I am using the the tutorial from the Web dynpro sample applications to do the export to excel.The excel is created on local system.When the user clicks on ""exporttoexcel"" button the excel sheet is created.But when there is only single record in the excel then there is not header in the excel sheet.Please suggest

Thanks,

Rajani

Former Member
0 Kudos

Solved