on 12-24-2008 5:04 AM
My requirement is :
I have a WD Table and I need to write it to KM in excel format and as well display it to the user.
I Used JXL to do this.I was able to write it to KM and even display but, sadly it is writing some garbage values in file.
Is there some problem with the file format? I used many formats like ms-excel,text,text/plain,etc.and checked...
Anyone please solve this problem.
Thanks and Regards in advance...
Hi,
I had done this using the following code in SDN. I didnot got any garbage values. Check your context
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();
}
}
}
Regards
Raghu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Vikranth,
Refer to these links.
Hope this helps you.
Regards,
Sumangala
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
83 | |
24 | |
12 | |
9 | |
7 | |
6 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.