Skip to Content
avatar image
Former Member

Problem in export to excel

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Sep 08, 2008 at 01:48 PM

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 26, 2008 at 10:09 AM

    Hi Rajini,

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

    Regards

    Raghu

    Add comment
    10|10000 characters needed characters exceeded