Boa tarde pessoal,
to com um problema aqui…
Fiz um aplicativozinho em java, muito simples, e com muita preça, para converter um arquivo xls(excel) em documento de texto(txt), e ta acontecendo o seguinte erro, funciona tudo beleza, mais as palavras com acento, cedilha e talz, ficam com um ponto de interrogação, vou copiar meu codigo abaixo.
Se puderem ajudar.
Agradeço.
ps1: utilizo linux, UBUNTU.
ps2: não reparem no codigo, que fiz com muita pressa.
public class conversaopropria {
public static int coluna, linha, linhareferencia, conta, posicaovetor = 0;
public static String strings = null;
public static void main(String[] args) throws BiffException, IOException {
String[] leitura = lerxls("/home/cpd/areadetrabalho/conversaodados/conversaofilipe.xls");
int tamanhodovetor = leitura.length;
for (int j = 0 ; j < tamanhodovetor ; j ++){
gravar(leitura[j] + ",");
}
}
public static String[] lerxls(String caminho) throws BiffException,
IOException {
coluna = 1;
linha = 0;
linhareferencia = 0;
Workbook workbook = Workbook.getWorkbook(new File(caminho));
Sheet sheet = workbook.getSheet(0);
int totaldelinhas = sheet.getRows();
totaldelinhas -= 4;
conta = (totaldelinhas - 3);
conta = conta / 6;
String[] linhassql = new String[conta + 1];
totaldelinhas -= 1;
// System.out.println(totaldelinhas);
// coluna / linha
while (linhareferencia <= totaldelinhas) {
// System.out.println(coluna + "," + linha);
Cell a1 = sheet.getCell(coluna, linha);
linha += 1;
// System.out.println(coluna + "," + linha);
Cell a2 = sheet.getCell(coluna, linha);
linha += 1;
// System.out.println(coluna + "," + linha);
Cell a3 = sheet.getCell(coluna, linha);
linha += 1;
// System.out.println(coluna + "," + linha);
Cell a4 = sheet.getCell(coluna, linha);
linha += 1;
// System.out.println(coluna + "," + linha);
Cell a5 = sheet.getCell(coluna, linha);
coluna += 2;
linha -= 3;
// System.out.println(coluna + "," + linha);
Cell a6 = sheet.getCell(coluna, linha);
coluna += 2;
linha -= 1;
// System.out.println(coluna + "," + linha);
Cell a7 = sheet.getCell(coluna, linha);
linha += 1;
// System.out.println(coluna + "," + linha);
Cell a8 = sheet.getCell(coluna, linha);
linha += 1;
// System.out.println(coluna + "," + linha);
Cell a9 = sheet.getCell(coluna, linha);
linha += 2;
// System.out.println(coluna + "," + linha);
Cell a10 = sheet.getCell(coluna, linha);
String string1 = a1.getContents();
String string2 = a2.getContents();
String string3 = a3.getContents();
String string4 = a4.getContents();
String string5 = a5.getContents();
String string6 = a6.getContents();
String string7 = a7.getContents();
String string8 = a8.getContents();
String string9 = a9.getContents();
String string10 = a10.getContents();
if (string1.equals("")) {
} else {
strings = string1 + ",";
}
strings += string2 + "," + string3 + "," + string4 + "," + string5
+ "," + string6 + "," + string7 + "," + string8 + ","
+ string9;
if (string10.equals("")) {
} else {
strings += "," + string10;
}
linhassql[posicaovetor] = strings;
linhareferencia = a5.getRow() + 6;
// System.out.println("linha referencia" + linhareferencia);
posicaovetor += 1;
// System.out.println(posicaovetor);
linha += 2;
coluna = 1;
}
return linhassql;
}
public static void gravar(String texto) {
String conteudo = texto;
try {
// o true significa q o arquivo será constante
FileWriter x = new FileWriter(
"/home/cpd/areadetrabalho/conversaodados/teste.txt", true);
conteudo += "\n\r"; // criando nova linha e recuo no arquivo
x.write(conteudo); // armazena o texto no objeto x, que aponta para
// o arquivo
x.close(); // cria o arquivo
//JOptionPane.showMessageDialog(null, "Arquivo gravado com sucesso",
// "Concluído", JOptionPane.INFORMATION_MESSAGE);
}
// em caso de erro apreenta mensagem abaixo
catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage(), "Atenção",
JOptionPane.WARNING_MESSAGE);
}
}
}