Foros del Web » Programación para mayores de 30 ;) » Java »

Error POI getParagraphText al leer Doc

Estas en el tema de Error POI getParagraphText al leer Doc en el foro de Java en Foros del Web. Tengo la versión 3.8 de POI y éste es mi código: Código: fs = new POIFSFileSystem(new FileInputStream("c:\\Data.docx")); HWPFDocument doc = new HWPFDocument(fs); readParagraphs(doc); Dónde el ...
  #1 (permalink)  
Antiguo 08/05/2012, 02:23
 
Fecha de Ingreso: abril-2010
Mensajes: 12
Antigüedad: 14 años, 1 mes
Puntos: 0
Error POI getParagraphText al leer Doc

Tengo la versión 3.8 de POI y éste es mi código:

Código:
fs = new POIFSFileSystem(new FileInputStream("c:\\Data.docx"));
            HWPFDocument doc = new HWPFDocument(fs);

            readParagraphs(doc);
Dónde el método readParagraphs:

Código:
public static void readParagraphs(HWPFDocument doc) throws Exception{
        WordExtractor we = new WordExtractor(doc);

        /**Get the total number of paragraphs**/
        String[] paragraphs = we.getParagraphText();
        System.out.println("Total Paragraphs: "+paragraphs.length);

        for (int i = 0;i < paragraphs.length; i++) 
        {

            System.out.println("Length of paragraph "+(i +1)+": "+ paragraphs[i].length());
            System.out.println(paragraphs[i].toString());
        }

    }
Al ejecutarlo me salta ésta excepción:

Código:
org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)
	at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:131)
	at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:104)
	at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:138)
	at anagram.Anagram.main(Anagram.java:55)
Alguien sabe cómo arreglarlo??

He conseguido leer el documento usando el método getText del XWPFWordExtractor, pero necesito extraer los datos línea a línea para procesarlos, hay algún otro método?

Saludos y gracias!

Etiquetas: doc, poi, string
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:42.