2012-06-30 19 views
11

का उपयोग करके परिशिष्ट एक्सेलशीट बनाने के लिए कैसे मैं एक संलग्न सक्षम एक्सेल शीट बनाना चाहता हूं। की तरह मैं चार स्तंभों stream1 stream2 stream3 stream4 हैजावा

पहली बार मैं डेटा डालने कर रहा हूँ केवल प्रथम स्तंभ (stream1) उसके बाद मैं पूरा भरने के अन्य स्तंभों एक के बाद एक करना चाहते हैं।

इस

कोड जो मैं उपयोग कर रहा हूँ है:

public void createFile(Jqueue stream1, Jqueue stream2, Jqueue stream3, Jqueue stream4) { 
    try { 

     String filename = "path"; 
     boolean alreadyExists = (new File(filename)).exists(); 

     HSSFRow rowhead = sheet1.createRow((short) 0); 
     rowhead.createCell((short) 0).setCellValue("Stream 1"); 
     rowhead.createCell((short) 1).setCellValue("Stream 2"); 
     rowhead.createCell((short) 2).setCellValue("Stream 3"); 
     rowhead.createCell((short) 3).setCellValue("Stream 4"); 


     int i = 1; 
     while (!stream1.isEmpty()) { 
      String urlstream1 = ""; 
      String urlstream2 = ""; 
      String urlstream3 = ""; 
      String urlstream4 = ""; 
      HSSFRow row = sheet1.createRow((short) i); 
      try { 
       if (stream1.size() > 0) { 
        urlstream1 = stream1.dequeue().toString(); 
       } 
      } catch (Exception ex) { 
      } 
      try { 
       if (stream2.size() > 0) { 
        urlstream2 = stream2.dequeue().toString(); 
       } 
      } catch (Exception ex) { 
      } 
      try { 
       if (stream3.size() > 0) { 
        urlstream3 = stream3.dequeue().toString(); 
       } 
      } catch (Exception ex) { 
      } 
      try { 
       if (stream4.size() > 0) { 
        urlstream4 = stream4.dequeue().toString(); 
       } 
      } catch (Exception ex) { 
      } 
      row.createCell((short) 0).setCellValue(urlstream1); 
      row.createCell((short) 1).setCellValue(urlstream2); 
      row.createCell((short) 2).setCellValue(urlstream3); 
      row.createCell((short) 3).setCellValue(urlstream4); 
      i++; 
     } 

     FileOutputStream fileOut = new FileOutputStream(filename); 
     hwb.write(fileOut); 
     fileOut.close(); 

लेकिन इस संलग्न करने योग्य कोड नहीं है। पंक्ति से इसकी डालने वाली डेटा पंक्ति।

उन्नत में thx।

उत्तर

1

मुझे लगता है अपने कोड में एक मामूली बदलाव यह करना चाहिए।

जगह

पूर्णांक प्रयास करें मैं = 1;

निम्नलिखित के साथ

:

पूर्णांक i = sheet1.getLastRowNum() + 1;

आपको फ़ाइलों को पढ़ने और लिखने के लिए भी अपना कार्यान्वयन बदलने की आवश्यकता होगी।

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^