将Excel工作表与Java swing集成 [英] Integrating excel sheet with java swing
问题描述
如何使用Java swing从Excel工作表中获取单元格值?我一直进行到使用Desktop.getDesktop().open()打开excel应用程序为止.我的目标是从Excel工作表中获取一个值,并在我的Java swing中显示该值.是否可以使用任何库.请帮忙.预先感谢
How can i get a cells value from an excel sheet using java swing ? I progressed till opening the excel app using Desktop.getDesktop().open(). My aim is to get a value from an excel sheet and display the value in my java swing. Is it possible using any libraries. Please help. Thanks in advance
推荐答案
使用Apache POI.它可以打开Excel文件并访问单个单元格: http://poi.apache.org/
Use Apache POI. It can open Excel files and access individual cells: http://poi.apache.org/
以下是使用方法的示例:
Here's an example on how to use it:
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
//..
FileInputStream file = new FileInputStream(new File("C:\\test.xls"));
//Get the workbook instance for XLS file
HSSFWorkbook workbook = new HSSFWorkbook(file);
//Get first sheet from the workbook
HSSFSheet sheet = workbook.getSheetAt(0);
//Get iterator to all the rows in current sheet
Iterator<Row> rowIterator = sheet.iterator();
//Get iterator to all cells of current row
Iterator<Cell> cellIterator = row.cellIterator();
它来自此站点: http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/
这篇关于将Excel工作表与Java swing集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!