我有一个带有 jtable 的表单,它在其中加载了一个 excel 文件,问题是它没有加载 ñs 或特殊字符
我得到那些问题符号。这是添加按钮代码
private void btn_importarActionPerformed(java.awt.event.ActionEvent evt) {
try {
for (int i = 0; i < jtabla.getRowCount(); i++) {
modelo.removeRow(i);
i -= 1;
}
} catch (Exception e) {
}
JFileChooser fileChooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Archivos Excel (*.xls)", "xls");
fileChooser.setAcceptAllFileFilterUsed(false);
fileChooser.setFileFilter(filter);
fileChooser.setDialogTitle("BUSCAR ARCHIVO");
if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
String ruta = fileChooser.getSelectedFile().getAbsolutePath();
File f = new File(ruta);
try {
Workbook wb = Workbook.getWorkbook(f);
Sheet s = wb.getSheet(0);
int row = s.getRows();
int col = s.getColumns();
String[] datos;
for (int i = 0; i < row; i++) {
datos = new String[col];
for (int j = 0; j < col; j++) {
Cell c = s.getCell(j, i);
datos[j] = c.getContents();
System.out.print(c.getContents());
}
System.out.println("");
if (i == 0) {
modelo.setColumnIdentifiers(datos);
} else {
modelo.addRow(datos);
}
}
jtabla.setModel(modelo);
} catch (Exception e) {
}
}
}
我已经在研究如何转换为 UTF-8,但我不知道我应该什么时候做以及如何做。尝试转换文件FILE
或在时间,getContents
但它没有给我任何结果。
提前致谢
我找到了解决方案
我不得不更改要使用的库,在我使用jxl的问题中,但后来我使用了poi-3.7-20101029.jar
这是代码
书店
按钮
我不得不对整数数字数据使用十进制格式,因为它给了我一个错误