Cómo utilizar POI 3.0 para generar documentos WORD
importar java.io.*;
importar java.util.*
importar org.apache.poi.poifs.filesystem.*; p>
importar java.util.*; p>
importar org.
public static boolean writeWordFile(ruta de cadena, contenido de cadena) {
boolean w = false
prueba {
p>
// byte b[] = content.getBytes( "ISO-8859-1 "); b[] = content.getBytes();
ByteArrayInputStream bais = nuevo ByteArrayInputStream(b);
POIFSFileSystem fs = nuevo directorio POIFSFileSystem(); = fs.getRoot();
DocumentEntry de = directorio.createDocument( "WordDocument", aquí
FileOutputStream ostream = new FileOutputStream(ruta); >fs.writeFilesystem(ostream)writeFilesystem(ostream);
bais.close();
ostream.close()
} captura (IOException e); ) {
e.printStackTrace();
p>
}
return w;
public static void main(String[] args){
boolean b = writeWordFile( "E://test.doc ", "hola "
}<); /p>
}
}
/*
public String extractText(InputStream in) lanza IOException {
ArrayList text = new ArrayList();
POIFSFileSystem fsys = new POIFSFileSystem(in);
DocumentEntry headerProps = (DocumentEntry) fsys.
DocumentInputStream din = fsys.
DocumentInputStream = fsys.createDocumentInputStream( "WordDocument ");
byte[] encabezado = nuevo byte[headerProps.getSize()];
in.read(header);
din.close();
// Obtenga información del encabezado del documento
int info = LittleEndian.getShort (encabezado, 0xa);
useTable1 booleano = (información & 0x200) ! getInt(encabezado);
String nombreTabla = null;
if (useTable1) {
nombreTabla = " 1Tabla "; else {
nombreTabla = "0Tabla ";
}
tabla EntradaDocumento = (EntradaDocumento) fsys.getRoot().getEntry(NombreTabla); >
byte[] tableStream = nuevo byte[table.getSize()];
din = fsys.createDocumentInputStream(tableName);
din.read( tableStream); /p>
din.close();
din = nulo;
fsys = nulo
tabla = nulo; p>headerProps = null;
int multiple = findText(tableStream, complexOffset, text
);