简体   繁体   English

如何使用Apache POI在Java中读取Excel ListBox值

[英]How to read Excel ListBox value in Java using Apache POI

How to read Excel ListBox value in Java using Apache POI ? 如何使用Apache POI读取Java中的Excel ListBox值? On web this is the only thread that discussed abou this problem. 在网络上,这是讨论此问题的唯一线程。 http://apache-poi.1045710.n5.nabble.com/sample-code-to-read-excel-listbox-values-td2308018.html http://apache-poi.1045710.n5.nabble.com/sample-code-to-read-excel-listbox-values-td2308018.html

But this code does not work. 但是此代码不起作用。 It uses this code 它使用此代码

    HSSFWorkbook workbook = null;
    HSSFSheet sheet = null;
    HSSFRow row = null;
    HSSFCell cell = null;
    HSSFDataValidation dataValidation = null;

    try { 
        inputStream = new java.io.FileInputStream(new java.io.File("C:/temp/data validation.xls"));
        workbook = new HSSFWorkbook(inputStream);
        sheet = workbook.getSheetAt(0);
        validationRecords = sheet.getDVRecords(); 

But in HSSF version which I am using "getDVRecords" method is not available in HSSFSheet. 但是在我正在使用“ getDVRecords”方法的HSSF版本中,HSSFSheet中不提供该方法。

Is there any better and working code ? 有更好的工作代码吗?

EDIT: I already have code to read values of normal cell or dropdown. 编辑:我已经有代码来读取普通单元格或下拉列表的值。 I am specifically looking for code to read listbox. 我专门在寻找要阅读列表框的代码。 List box is where you can select more than one values. 列表框是您可以选择多个值的地方。 ListBox are not tied to any specific cell. ListBox没有绑定到任何特定的单元格。 They appear as components overlaid on the sheet 它们显示为覆盖在图纸上的组件

Please refer this link to see how to add listbox. 请参考此链接以了解如何添加列表框。 This will help better understand my question. 这将有助于更好地理解我的问题。 http://office.microsoft.com/en-in/excel-help/add-a-list-box-or-combo-box-to-a-worksheet-HP010236681.aspx http://office.microsoft.com/zh-CN/excel-help/add-a-list-box-or-combo-box-to-a-worksheet-HP010236681.aspx

ever tried to use the jExcel API? 曾经尝试使用jExcel API吗? It uses Apache POI and is really easy to handle: 它使用Apache POI,非常易于处理:

net.sourceforge.jexcelapi:jxl:2.6.12 net.sourceforge.jexcelapi:jxl:2.6.12

you can try it somehow like this: 您可以这样尝试:

WorkSheet sheet;

Cell comboBox = sheet.getCell(x,y);
String value= comboBox.getContents();

greetings 问候

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM