Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java in General
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Java in General
Please help for this Problem in creating excel sheet using java
Ifteqar Ahmed
Ranch Hand
Posts: 85
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I am creating an excel file with my
java
code.
Here is the code
while(stk.hasMoreTokens()) { for(int a=0;a<stk.countTokens();a++) { if(a==stk.countTokens()) break; i[a]=Float.parseFloat(stk.nextToken()); x=i[a]; System.out.println(x); // printing 20 values CORRECTLY WritableCellFormat cf3 = new WritableCellFormat(NumberFormats.FLOAT); Number n = new Number(a,1,x,cf3); //This should create 20 cells in the excel sheet but its creating randomly only 10 cells s.addCell(n); }
This should create 20 cells in the excel sheet but its not working properly
Please help....
Ulf Dittmer
Rancher
Posts: 43081
77
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
What does "it's not working properly mean"? What, exactly, does happen? Seeing an
SSCCE
would help.
Ifteqar Ahmed
Ranch Hand
Posts: 85
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Ulf,
The statement at line 10 is displaying
3.41
5.55
4.79
1.92
1.86
2.68
1.24
1.21
1.54
1.53
1.59
1.5
1.27
1.28
1.34
1.89
3.56
1.33
2.9
but these values are not getting published in excel sheet
In excel sheet i am getting these values at row 1
2.9 3.55 1.26 1.27 1.34 2.68 1.24 1.21 1.52 1.52
Ulf Dittmer
Rancher
Posts: 43081
77
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Without seeing an SSCCE it's hard to tell what's going on. What is "s", for example?
Also, what are the for loop and the if statement supposed to do? The while loop already takes care of iterating over all elements of "stk".
Ifteqar Ahmed
Ranch Hand
Posts: 85
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Here is my complete code
class A { public static void main(String[] args) { try { String filename = "values.xls"; WorkbookSettings ws = new WorkbookSettings(); ws.setLocale(new Locale("en", "EN")); WritableWorkbook workbook = Workbook.createWorkbook(new File(filename), ws); WritableSheet s = workbook.createSheet("Sheet1", 0); writeDataSheet(s); workbook.write(); workbook.close(); } catch (IOException e) { e.printStackTrace(); } catch (WriteException e) { e.printStackTrace(); } } private static void writeDataSheet(WritableSheet s) throws WriteException { /* Format the Font */ WritableFont wf = new WritableFont(WritableFont.ARIAL, 10, WritableFont.BOLD); WritableCellFormat cf = new WritableCellFormat(wf); cf.setWrap(true); try { URL yahoo = new URL("http://SOME-URL.HTML"); URLConnection yc = yahoo.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); String inputLine; String data=new String(); while ((inputLine = in.readLine()) != null) { //System.out.println(inputLine); data+=inputLine; } float[] i=new float[40]; //System.out.println(data); StringTokenizer stk=new StringTokenizer(data,"<br><html> </><body><body>"); ArrayList<Float> al=new ArrayList<Float>(); float x; while(stk.hasMoreTokens()) { //System.out.println(stk.nextToken()); for(int a=0;a<stk.countTokens();a++) { i[a]=Float.parseFloat(stk.nextToken()); //al.add(i[a]); x=i[a]; Number n = new Number(a,1,x); System.out.println(n.getValue()); s.addCell(n); } } in.close(); }catch(Exception e) { e.printStackTrace(); } } }
Here is the complete code..........
Ulf Dittmer
Rancher
Posts: 43081
77
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
So what's the output of the stack traces?
Note that the second while loop is pointless, as it will never loop.
Ifteqar Ahmed
Ranch Hand
Posts: 85
I like...
posted 12 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi Ulf,
Thank You very much. My program is working fine after removing that for loop.
Here is the modified code
int ix=0; while(stk.hasMoreTokens()) { //System.out.println(x); Number n = new Number(ix,1,Double.parseDouble(stk.nextToken())); s.addCell(n); ix++; }
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Writing on excel file using POI
Writing a content in excel in incremental way
JEXCEL to JSP
handling excel sheet with java
importing data from database to excel sheet through JExcel Api
More...