Ler conteudo de um Ficheiro Excel sem bibliotecas adicionais

Alo pessoal,

Gostaria de saber se alguém tem uma solução para ler ficheiros do MS Excel sem o usando do Apache POI ou Jexcel.
Estou tentando através do código abaixo, mas não tenho sucesso, pois o output aparece desfeito na consola.
Existe algum tratamento diferente para tal, que seja diferente do que aplicamos aos ficheiros de texto?

[code]
String nomeFicheiro = “my_bills.xlsx”;

			BufferedReader br = new BufferedReader(new FileReader(nomeFicheiro));
							
			String linha = br.readLine(); 
			while(linha!= null){ 
				System.out.println(linha); 
				linha = br.readLine(); 
				byte [] store = linha.getBytes();[/code]

Agradeço deste já, pela atenção.

Por que você gostaria de ler um arquivo do excel sem usar uma API?

[quote=El]Alo pessoal,

Gostaria de saber se alguém tem uma solução para ler ficheiros do MS Excel sem o usando do Apache POI ou Jexcel.
Estou tentando através do código abaixo, mas não tenho sucesso, pois o output aparece desfeito na consola.
Existe algum tratamento diferente para tal, que seja diferente do que aplicamos aos ficheiros de texto?

[code]
String nomeFicheiro = “my_bills.xlsx”;

			BufferedReader br = new BufferedReader(new FileReader(nomeFicheiro));
							
			String linha = br.readLine(); 
			while(linha!= null){ 
				System.out.println(linha); 
				linha = br.readLine(); 
				byte [] store = linha.getBytes();[/code]

Agradeço deste já, pela atenção.[/quote]

A menos que vc tenha uma muito boa desculpa para querer fazer isso, é completa insanidade.
Só que se vc quer realmente fazer isso vc tem que saber o que está fazendo. Tem que saber o protocolo do arquivo.
O arquivo é um zip de xml. Portanto a primeira coisa a fazer é descompactar o arquivo.

O tempo que vc leva a entender o protocolo e a implementá-lo simplesmente não compensa. É mais simples usar as ferramentas da apache.

Realmente… você vai ter um bom trabalho pra extrair alguma informação sem usar alguma API.
São arquivos XML, o que vai te levar fatalmente a alguma API, como o SAX.

Ok. Obrigado a todos. Percebi que não é viável.
Já agora, como sugerem que eu faca com o POI?

[quote=El]Ok. Obrigado a todos. Percebi que não é viável.
Já agora, como sugerem que eu faca com o POI?[/quote]
to sacando que vc quer um control C control V, né danado? toma aí:


package br.com.relatorio;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
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.hssf.util.HSSFColor;
import org.apache.poi.hssf.util.Region;


public class AcoesRealizadasMB {

	private EntityRepositoryLocal entityRepository;
	
	public void gerarRealatorio(ActionEvent actionEvent) {
		try{
		HSSFWorkbook workbook = montarRelatorio();
		enviarRelatorio(workbook);
		JsfUtilArkanis.addSuccessMessage("MSGU0043");
		}catch(ReportException e){
			JsfUtilArkanis.addErrorMessage("message.nenhuma.informacao.encontrada");
		}
		catch(Exception e){
			e.printStackTrace();
			JsfUtilArkanis.addErrorMessage("MSG007E");
		}
	}

	private void enviarRelatorio(HSSFWorkbook wb) throws IOException {
		FacesContext context = FacesContext.getCurrentInstance();
		HttpServletResponse response = (HttpServletResponse) context.getExternalContext().getResponse();
		response.setDateHeader("Expires", 0);
		response.setHeader("Content-Disposition", "attachment; filename=acoesRealizadas.xls");
		response.setContentType("application/octet-stream");
		ServletOutputStream servletOutputStream = response.getOutputStream();
		wb.write(servletOutputStream);
		servletOutputStream.flush();
		servletOutputStream.close();
		context.responseComplete();
	}
	
	private HSSFWorkbook montarRelatorio() throws IOException, RuntimeException, ReportException {
		HSSFWorkbook wb = montarCabecalhoWorkbook();
		wb = montarCorpoWorkbook(wb);
		return wb;
	}

	private HSSFWorkbook montarCorpoWorkbook(HSSFWorkbook wb) throws ReportException {
		try{
			
			Rede rede = JsfUtilArkanis.getRedeAberta();
			rede = entityRepository.fetchLazy(rede.getClass(), rede.getId());
			List<IEntidadeMapa> listaNos = entityRepository.recuperarEntidade(filtraMacro(rede.getMacros(), TipoEntidadeEnum.EL, TipoMacroEnum.IN));
			List<IEntidadeMapa> listaSegmentos = entityRepository.recuperarEntidade(filtraMacro(rede.getMacros(), TipoEntidadeEnum.SE, TipoMacroEnum.IN));
			List<IEntidadeMapa> listaSegmentosRecondutorados = entityRepository.recuperarEntidade(filtraMacro(rede.getMacros(), TipoEntidadeEnum.SE, TipoMacroEnum.RE));
			validarSeExistemAlteracoes(listaNos, listaSegmentos, listaSegmentosRecondutorados);
			HSSFSheet sheet = wb.getSheetAt(0);
			int indexLinha = 4;
			indexLinha = inserirTitulo(wb, sheet, indexLinha, "Nós", "Código", "Tipo", "Tensão");
			indexLinha= inserirNos(wb, sheet,listaNos, indexLinha) + 1;
			indexLinha = inserirTitulo(wb, sheet, indexLinha, "Segmentos Criados", "Código", "Seção", "Comprimento");
			indexLinha= inserirSegmentos(wb, sheet,listaSegmentos, indexLinha) + 1;
			indexLinha = inserirTitulo(wb, sheet, indexLinha, "Segmentos Recondutorados", "Código", "Seção", "Comprimento");
			inserirSegmentos(wb, sheet,listaSegmentosRecondutorados, indexLinha);
			return wb;
		}catch(ReportException e){
			throw new ReportException();
		}
		catch(Exception e){
			throw new RuntimeException(e);
		}
	}

	private void validarSeExistemAlteracoes(List<?>... listasDeAlteracoes) throws ReportException {
		int listasVazias = 0;
		for(List<?> listaEntity : listasDeAlteracoes){
			if(listaEntity.size() == 0)
				listasVazias++;
		}
		if(listasVazias == listasDeAlteracoes.length)
			throw new ReportException();
	}

	private HSSFWorkbook montarCabecalhoWorkbook() {
		HSSFWorkbook wb = new HSSFWorkbook();
		
		HSSFSheet sheet = wb.createSheet("Ações Realizadas");
		HSSFRow row =sheet.createRow(0);
		HSSFCellStyle style = createCellStyle(wb);
		HSSFCell cell = row.createCell((short) 0);
		cell.setCellValue(
			new HSSFRichTextString("Rede Básica: " + JsfUtilArkanis.getTrabalhoAberto().getRedeBase().getDesDescricao())
		);
		cell.setCellStyle(style);
		cell = row.createCell((short) 1);
		cell.setCellValue(
			new HSSFRichTextString("Trabalho: " + JsfUtilArkanis.getTrabalhoAberto().getRede().getDesDescricao())
		);
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
		String data = dateFormat.format(Calendar.getInstance().getTime());
		cell.setCellStyle(style);
		cell = sheet.createRow(1).createCell((short) 0);
		cell.setCellValue(new HSSFRichTextString("Data/Hora: " + data));
		cell.setCellStyle(style);
		sheet.autoSizeColumn((short)(0));
		sheet.autoSizeColumn((short)(1));
		return wb;
	}

	private HSSFCellStyle createCellStyle(HSSFWorkbook wb) {
		HSSFFont font = wb.createFont();
		font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
		HSSFCellStyle style = wb.createCellStyle();
		style.setFont(font);
		return style;
	}
	
	private int inserirTitulo(HSSFWorkbook wb, HSSFSheet sheet, int indexLinha, String titulo, String subtitulo1, String subtitulo2, String subtitulo3) {
		HSSFCellStyle style = createCellStyle(wb);
		style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style.setFillForegroundColor(HSSFColor.AQUA.index);
		style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
		HSSFCell cell = sheet.createRow(indexLinha).createCell((short) 0);
		cell.setCellValue(new HSSFRichTextString(titulo));
		cell.setCellStyle(style);
		Region region = new Region(indexLinha, (short)0, indexLinha, (short)2);
		sheet.addMergedRegion(region);
		indexLinha++;
		style = createCellStyle(wb);
		style.setBorderBottom(HSSFCellStyle.BORDER_MEDIUM);
		style.setBorderTop(HSSFCellStyle.BORDER_MEDIUM);
		style.setBorderRight(HSSFCellStyle.BORDER_MEDIUM);
		style.setBorderLeft(HSSFCellStyle.BORDER_MEDIUM);
		style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
		style.setFillForegroundColor(HSSFColor.AQUA.index);
		cell = sheet.createRow(indexLinha).createCell((short) 0);
		cell.setCellValue(new HSSFRichTextString(subtitulo1));
		cell.setCellStyle(style);
		cell = sheet.createRow(indexLinha).createCell((short) 1);
		cell.setCellValue(new HSSFRichTextString(subtitulo2));
		cell.setCellStyle(style);
		cell = sheet.createRow(indexLinha).createCell((short) 2);
		cell.setCellValue(new HSSFRichTextString(subtitulo3));
		cell.setCellStyle(style);
		indexLinha++;
		return indexLinha;
	}

	private List<Macro> filtraMacro(List<Macro> macros, TipoEntidadeEnum tipoEntidade, TipoMacroEnum tipoMacro){
		List<Macro> listaMacros = new ArrayList<Macro>();
		for(Macro macro : macros){
			if(macro.getTipoEntidade() == tipoEntidade && macro.getTipoMacro() == tipoMacro ){
				listaMacros.add(macro);
			}
		}
		return listaMacros;
	}
	
	private int inserirSegmentos(HSSFWorkbook wb, HSSFSheet sheet, List<IEntidadeMapa> listaSegmentos, int indexLinha){
		HSSFCellStyle style = createCellStyle(wb);
		int primeiraCelula = indexLinha;
		int ultimaCelula = primeiraCelula;
		for(IEntidadeMapa entity : listaSegmentos){
			ultimaCelula = indexLinha;
			sheet.createRow(indexLinha).createCell((short) 0).setCellValue(new HSSFRichTextString( ((Segmento) entity).getDesCodigo()) );
			sheet.createRow(indexLinha).createCell((short) 1).setCellValue(((Segmento) entity).getTtipoSegmento().getNumSecao());
			sheet.createRow(indexLinha).createCell((short) 2).setCellValue(((Segmento) entity).getValComprimento() );
			indexLinha++;
		}
		return inserirFuncaoSoma(sheet, indexLinha, style, primeiraCelula, ultimaCelula, "Comprimento Total");
	}
	
	private int inserirNos(HSSFWorkbook wb, HSSFSheet sheet, List<IEntidadeMapa> listaNos, int indexLinha){
		HSSFCellStyle style = createCellStyle(wb);
		int primeiraCelula = indexLinha;
		int ultimaCelula = primeiraCelula;
		for(IEntidadeMapa entity : listaNos){
			TipoElementoSimbolo tipoElemento = ((Elemento) entity).getTtipoElemento().getSimbolo(); 
			if(TipoElementoSimbolo.getRestricaoAcoesRealizadas().contains(tipoElemento)){
			ultimaCelula = indexLinha;
			sheet.createRow(indexLinha).createCell((short) 0).setCellValue(new HSSFRichTextString( ((Elemento) entity).getDesCodigo()) );
			sheet.createRow(indexLinha).createCell((short) 1).setCellValue(new HSSFRichTextString(((Elemento) entity).getTtipoElemento().getSimbolo().toString()));
			sheet.createRow(indexLinha).createCell((short) 2).setCellValue(((Elemento) entity).getValTensao() != null ? ((Elemento) entity).getValTensao() : 0);
			indexLinha++;
			}
		}
		return inserirFuncaoCountA(sheet, indexLinha, style, primeiraCelula, ultimaCelula, "Total Chaves");
	}
	
	private int inserirFuncaoCountA(HSSFSheet sheet, int indexLinha, HSSFCellStyle style, int primeiraCelula, int ultimaCelula, String titulo) {
		indexLinha++;
		HSSFCell cell;
		cell = sheet.createRow(indexLinha).createCell((short) 1);
		cell.setCellValue(new HSSFRichTextString(titulo) );
		cell.setCellStyle(style);
		sheet.autoSizeColumn((short)(2));
		cell = sheet.createRow(indexLinha).createCell((short) 2);
		cell.setCellFormula("countA(C"+(primeiraCelula+1)+":C"+(ultimaCelula+1)+")");
		cell.setCellStyle(style);
		indexLinha++;
		return indexLinha;
	}	
	private int inserirFuncaoSoma(HSSFSheet sheet, int indexLinha, HSSFCellStyle style, int primeiraCelula, int ultimaCelula, String titulo) {
		indexLinha++;
		HSSFCell cell;
		cell = sheet.createRow(indexLinha).createCell((short) 1);
		cell.setCellValue(new HSSFRichTextString(titulo) );
		cell.setCellStyle(style);
		sheet.autoSizeColumn((short)(2));
		cell = sheet.createRow(indexLinha).createCell((short) 2);
		cell.setCellFormula("sum(C"+(primeiraCelula+1)+":C"+(ultimaCelula+1)+")");
		cell.setCellStyle(style);
		indexLinha++;
		return indexLinha;
	}
	
	public EntityRepositoryLocal getEntityRepository() {
		return entityRepository;
	}

	public void setEntityRepository(EntityRepositoryLocal entityRepository) {
		this.entityRepository = entityRepository;
	}

}

para maiores detalhes leia: http://poi.apache.org/