2012-03-31 8 views
6

के साथ एक्सेल शीट की प्रतिलिपि बनाने में समस्या कुछ जटिल जटिल एक्सेल फ़ाइलों पर काम कर रही थी और चादरों की प्रतिलिपि बनाने में समस्या आई थी। मैं सोच रहा हूँJExcel API

Exception in thread "main" java.lang.NullPointerException 
    at jxl.write.biff.WritableSheetCopier.shallowCopyCells(WritableSheetCopier.java:499) 
    at jxl.write.biff.WritableSheetCopier.copySheet(WritableSheetCopier.java:239) 
    at jxl.write.biff.WritableSheetImpl.copy(WritableSheetImpl.java:1622) 
    at jxl.write.biff.WritableWorkbookImpl.copySheet(WritableWorkbookImpl.java:987) 
    at excelCalc.main(excelCalc.java:18) 

क्या समस्या यहाँ है: जब भी मैं एक चादर है कि पूरी तरह से खाली मैं निम्न संदेश प्राप्त नहीं है कॉपी करने का प्रयास। एक ".copySheet (" फ़ंक्शन भी होगा यदि इसे चादरों के लिए चादरों के लिए उपयोग नहीं किया जा सकता है। समस्या को पुन: उत्पन्न करने के प्रयास में मैंने एक सरल स्केल पर बनाया है, मैंने नीचे दिया गया कोड बनाया है। आउटपुट मैं अपेक्षा करता हूं देखना सेल (0,0) लेबल होने "परीक्षण" के साथ 2 समान चादरें है। एक पत्रक नामित क्यों यह इस नल पॉइंटर दे रहा है के रूप में "प्रवाह" दूसरे, "कॉपी"। कोई भी विचार?

import java.io.File; 

import jxl.*; 
import jxl.write.*; 

public class excelCalc 
{ 
    public static void main(String[] args) throws Exception 
    { 
     WritableWorkbook outputBook = Workbook.createWorkbook(new File("C:/Users/Kevin Brey/CS243/ExcelTest/files/output", "output.xls")); 

     WritableSheet rSheet = outputBook.createSheet("Flows", 0); 

     rSheet.addCell(new Label(0, 0, "test")); 
     outputBook.copySheet(0, "copy", 0); 
     outputBook.write(); 
     outputBook.close(); 
    } 
} 

संपादित करें: इस कोड को भी एक ही अपवाद देता है:

import java.io.File; 

import jxl.*; 
import jxl.write.*; 

public class excelCalc 
{ 
    public static void main(String[] args) throws Exception 
    { 
     WritableWorkbook outputBook = Workbook.createWorkbook(new File("C:/Users/Kevin Brey/CS243/ExcelTest/files/output", "output.xls")); 

     WritableSheet sheet1 = outputBook.createSheet("Sheet1", 0); 
     WritableSheet sheet2 = outputBook.createSheet("Sheet2", 1); 

     sheet1.addCell(new Label(0, 0, "Label1")); 
     sheet2.addCell(new Label(0, 0, "Label2")); 

     outputBook.copySheet(0, "Copy", 1); 

     outputBook.write(); 
     outputBook.close(); 
    } 
} 

क्या गलत हो सकता है की मेरे विचारों से एक है कि के बाद से एक चादर खुला है और संपादित किया गया है यह नहीं कर सकते कॉपी किया जाना चाहिए। मैं वास्तव में नहीं जानता कि इस के आसपास कैसे जाना है।

उत्तर

9

को कॉपी यह jxl-2.6.12.jar में एक बग है इससे पहले कि कुछ कोशिकाओं चादर कॉपी करने के लिए जोड़ने के लिए, बजाय jxl-2.6.10.jar का उपयोग करें।

विवरण:

टाइपो '&'

लाइन 493 में '& &' - WritableSheetCopier.java

में लाइन 504
if (c != null) 
      { 
      toSheet.addCell(c); 

      // Cell.setCellFeatures short circuits when the cell is copied, 
      // so make sure the copy logic handles the validated cells   
      if (c.getCellFeatures() != null & 
       c.getCellFeatures().hasDataValidation()) 
      { 
       validatedCells.add(c); 
      } 
      } 

लाइन 540 - लाइन WritableSheetCopier.java

में 551
if (c != null) 
      { 
      toSheet.addCell(c); 

      // Cell.setCellFeatures short circuits when the cell is copied, 
      // so make sure the copy logic handles the validated cells   
      if (c.getCellFeatures() != null & 
       c.getCellFeatures().hasDataValidation()) 
      { 
       validatedCells.add(c); 
      } 
      } 

लाइन 9 0 9 - शीटकॉपीर.जावा

if (c != null) 
      { 
      toSheet.addCell(c); 

      // Cell.setCellFeatures short circuits when the cell is copied, 
      // so make sure the copy logic handles the validated cells 
      if (c.getCellFeatures() != null & 
       c.getCellFeatures().hasDataValidation()) 
      { 
       validatedCells.add(c); 
      } 
      } 
+1

वाह धन्यवाद! मुझे लगा कि एपीआई के साथ कुछ गलत था लेकिन मुझे नहीं पता था कि पिछले संस्करणों में मदद मिलेगी या नहीं। –

+0

@Yourchanges, कृपया इसके लिए मुझे जांचें (http://stackoverflow.com/questions/17078543/error-occured-in-copying-excel-sheet-with-jexel-api) – Cataclysm

0

प्रति शीट खाली है,

+0

मैं गलत हो सकता था लेकिन मुझे लगता है कि मैं हूं। मैं rSheet में एक सेल जोड़ता हूं जिसमें इंडेक्स 0 है। फिर जब मैं कॉपीशीट कहता हूं तो यह इंडेक्स 0 पर शीट से कॉपी कर रहा है और न्यूज़शीट को इंडेक्स 0 पर सही कर रहा है? मैंने outputBook.copySheet (0, "प्रतिलिपि", 1) की कोशिश की; प्रतिलिपि 1 पर प्रतिलिपि डालने के लिए, लेकिन यह वही त्रुटि देता है। –