Click here to Skip to main content
15,887,477 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to display cells in excel to JTable in Java JFrame Form. what should I do?
Posted
Comments
markelee-advid 7-May-20 1:35am    
Here is an Excel API for Java that you could use:

ExcelFile workbook = ExcelFile.load("input.xlsx");
ExcelWorksheet worksheet = workbook.getWorksheet(0);

int rowsCount = worksheet.getRows().size();
int columnsCount = worksheet.calculateMaxUsedColumns();

String[][] rowData = new String[rowsCount][columnsCount];
String[] columnNames = new String[columnsCount];

for (int row = 0; row < rowsCount; row++) {
for (int column = 0; column < columnsCount; column++) {

ExcelCell cell = worksheet.getCell(row, column);
String value = cell.getValue().toString();
if (row == 0)
columnNames[column] = value;
else
rowData[row - 1][column] = value;

}
}

JTable table = new JTable(rowData, columnNames);
// Use 'table' object with your JFrame...

Basically, you could create a JTable by reading Excel file from Java.

1 solution

you should use the Apache POI library[^]. That one can "translate" MS Office documents into Java readable stuff.

They have a part POI-HSSF and POI-XSSF in there that is responsable for Excel Documents: http://poi.apache.org/spreadsheet/index.html[^].
Please check out the menu on the left side there, they have several tutorials, Examples and much more to get into it.
 
Share this answer
 
Comments
[no name] 29-Mar-12 23:03pm    
okey, what you know the code or script that is used to JTable in Java JFrame Form?
TorstenH. 30-Mar-12 5:28am    
No. Also the code depends on what you're doing there.
There no such thing as a "genetic super implementation".

But check out the Tutorial they have and you will sure get a good idea on how to do your application.
[no name] 30-Mar-12 10:23am    
okey, I will study from examples

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900