java读取excel中文乱码
时间: 2023-07-03 13:27:51 浏览: 85
如果你在Java中读取Excel文件时遇到了中文乱码的问题,可以尝试以下方法来解决:
1. 使用Unicode编码读取Excel文件,例如:
```
String str = new String(cell.getStringCellValue().getBytes(),"UTF-8");
```
2. 使用Apache POI库读取Excel文件,并设置文件编码为UTF-8,例如:
```
Workbook wb = WorkbookFactory.create(new FileInputStream(file));
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
String str = new String(cell.getStringCellValue().getBytes("UTF-8"),"UTF-8");
```
3. 如果你的Excel文件编码不是UTF-8,可以根据文件编码来设置编码格式,例如:
```
InputStreamReader isr = new InputStreamReader(new FileInputStream(file),"GBK");
Workbook wb = WorkbookFactory.create(isr);
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(0);
Cell cell = row.getCell(0);
String str = cell.getStringCellValue();
```
希望这些方法能够帮助你解决中文乱码问题。