Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>If you call close() without calling write() first, a completely empty file will be generated.</h2> <p>Once you have finished adding sheets and cells to the workbook, you call write() on the workbook, and then close the file. This final step generates the output file (output.xls in this case) which may be read by Excel. <a href="http://www.andykhan.com/jexcelapi/tutorial.html" rel="nofollow">credits this excellent tutorial</a> it's required to add:</p> <pre><code> copy.write(); copy.close(); </code></pre> <h2>The cellFeatures needs to be re-instantiate inside the loop</h2> <p>according to my tests this code works fine:</p> <pre><code> WritableCellFeatures cellFeatures = null; Label checkLabel = null; for (int x = 0; x &lt; xlData.size(); x++) { for (int i = 0; i &lt;= 14; i++) { System.out.println("X:" + x + "I:" + i); if (i &gt; 9) { checkLabel = new Label(i, x + xlHeader.size(), (String) arrList.get(0)); cellFeatures = new WritableCellFeatures(); cellFeatures.setDataValidationList(arrList); checkLabel.setCellFeatures(cellFeatures); writableSheet.addCell(checkLabel); } } } // All cells modified/added. Now write out the workbook workbook.write(); workbook.close(); </code></pre> <h2>Even the Blank version works but in this case the cell hasn't an initial value</h2> <p>according to my tests also this code works fine:</p> <pre><code> WritableCellFeatures cellFeatures = null; Blank b = null; for (int x = 0; x &lt; xlData.size(); x++) { for (int i = 0; i &lt;= 14; i++) { System.out.println("X:" + x + "I:" + i); if (i &gt; 9) { b = new Blank(i, x + xlHeader.size()); cellFeatures = new WritableCellFeatures(); cellFeatures.setDataValidationList(arrList); b.setCellFeatures(cellFeatures); writableSheet.addCell(b); } } } // All cells modified/added. Now write out the workbook workbook.write(); workbook.close(); </code></pre> <h2>If you open the generated file <code>.xls</code> with Excel 2010 or Excel 2013 you may need to save as <code>.xlsx</code> to see the combo.</h2> <p>I experienced that opening .xls by Excel2010/2013, even if the cells actually contains a data validation list and the validation constraints works the data validation arrow are missing; that you need to save as in the new format if you want see the arrow and the combobox.</p> <p>Moreover this drawback seems rather caused by the last Excel versions and not by JXL, demonstrated by the fact that opening the .xls in OpenOffice.org Cal 3.4.1 there is not any problem and the combo works correctly; this could be related to the fact that the current version <a href="http://jexcelapi.sourceforge.net/" rel="nofollow">jxl 2.6.12 2009-10-26</a> I use for the test <strong>Generates spreadsheets in Excel 2000 format</strong></p> <hr> <p><a href="https://gist.github.com/rondinif/6628904" rel="nofollow">The Java code developed for this answer is available</a> to anyone who wants to improve or fork and play with it. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload