gpt4 book ai didi

使用 Apache POI 和 eclipse 作为编辑器读取 excel 文件的 java 程序

转载 作者:行者123 更新时间:2023-12-04 21:28:51 25 4
gpt4 key购买 nike

我创建了这段代码来使用 APACHE POI 读取包含 boolean 值、字符串和数值的 excel 文件。

import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;



public class ExcelRead {

public static void main(String[] args) throws Exception {
File excel = new File ("C:\\Users\\...\\Documents\\test.xls");
FileInputStream fis = new FileInputStream(excel);

HSSFWorkbook wb = new HSSFWorkbook(fis);
HSSFSheet ws = wb.getSheet("Input");

int rowNum = ws.getLastRowNum()+1;
int colNum = ws.getRow(0).getLastCellNum();
String[][] data = new String[rowNum][colNum];


for (int i=0; i<rowNum; i++){
HSSFRow row = ws.getRow(i);
for (int j=0; j<colNum; j++){
HSSFCell cell = row.getCell(j);
String value = cellToString(cell);
data[i][j] = value;
System.out.println("The value is" + value);

}
}
}

public static String cellToString (HSSFCell cell){

int type;
Object result;
type = cell.getCellType();

switch(type) {


case 0://numeric value in excel
result = cell.getNumericCellValue();
break;
case 1: //string value in excel
result = cell.getStringCellValue();
break;
case 2: //boolean value in excel
result = cell.getBooleanCellValue ();
break;
default:
throw new RunTimeException("There are no support for this type of
cell");
}

return result.toString();


}

当我使用 eclipse 运行它时,我收到此警告:

Usage: AddDimensionedImage imageFile outputFile

谁能帮帮我?

最佳答案

您正在尝试运行名为“AddDimensionedImage”的不同项目/类。

在 Eclipse 上右键单击您的 ExcelRead 文件并选择 Run As -> Java Application

关于使用 Apache POI 和 eclipse 作为编辑器读取 excel 文件的 java 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15700512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com