Append text to word file doesn't work

Hi,

this my code:

private void append(byte[] datos, OutputStream os)
{

    try
    {
        Document doc = new Document(new ByteArrayInputStream(datos));
        DocumentBuilder builder = new DocumentBuilder(doc);
        Font fuente = builder.getFont();
        fuente.setSize(11);
        fuente.setColor(java.awt.Color.BLACK);
        fuente.setBold(false);
        fuente.setName("Arial");
        fuente.setUnderline(Underline.NONE);
        builder.moveToDocumentStart();
        builder.writeln("ok;");
        doc.save(os, SaveFormat.DOC);
    }
    catch (Exception e)
    {
        e.getMessage();
    }
}

File content doesn’t change… I’m doing something wrong?

thx for reply it’s urgent!

Hi

Thanks for your request. Your code is correct and it works fine on my side. It adds text at the beginning of the document. Do not you see the text inserted at the beginning of the document? If you need to add text at the end of the document, you should use builder.moveToDocumentEnd(); instead of builder.moveToDocumentStart();

private static void append(byte[] datos, OutputStream os)
{
    try
    {
        Document doc = new Document(new ByteArrayInputStream(datos));
        DocumentBuilder builder = new DocumentBuilder(doc);
        Font fuente = builder.getFont();
        fuente.setSize(11);
        fuente.setColor(java.awt.Color.BLACK);
        fuente.setBold(false);
        fuente.setName("Arial");
        fuente.setUnderline(Underline.NONE);
        builder.moveToDocumentEnd();
        builder.writeln("ok;");
        doc.save(os, SaveFormat.DOC);
    }
    catch (Exception e)
    {
        e.getMessage();
    }
}

Also, please attach your input document here for testing.
Best regards.

Ok thank you!!!