Ao executar uma planilha, as palavras com acentuação aparecem no console com caracteres “distorcidos”.
Segue código:
`package main.java;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.read.biff.BiffException;
public class web {
public String excelReader(String pathFile) {
int colunas;
String mensagem = null;
if (pathFile.endsWith(".xls")) {
// Abrir arquivo
Workbook planilha = null;
// Abas do arquivo
Sheet abas;
try {
//Configura para aceitar acentuação
WorkbookSettings conf = new WorkbookSettings();
conf.setEncoding("UTF-8");
// Abrindo arquivo
try {
File arquivo = new File(pathFile);
planilha = Workbook.getWorkbook(arquivo, conf);
} catch (BiffException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Pegamos a primeira aba
abas = planilha.getSheet(0);
// Pegar as linhas
int linhas = abas.getRows();
// Pegar as colunas
colunas = abas.getColumns();
// Logica
for (int i = 0; i < linhas; i++) {
System.err.println("Lendo linha: " + i);
for(int j = 0; j < colunas; j++){
System.out.println("Valor linha: " + i + "\nValor coluna: " + j +" " + abas.getCell(j, i).getContents());
}
}
return "Planilha lida com sucesso.";
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
// Extens�o nap suportada
mensagem = "A leitura só suporta a extensão .xls";
System.out.println(mensagem);
}
return mensagem;
}
}
Como consertar isso?