RTF to HTML for Libre Spreadsheet - Java [closed]

asked 2014-02-20 04:32:15 +0100

tauruzian gravatar image

I'm trying to convert RTF to HTML using Libre. Its working fine for Libre Document but giving null value for Spreadsheet. Below is my java code how I do the parse.

ArrayList<String> styleValue = new ArrayList<String>();
String result;
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable contents = clipboard.getContents(null);
DataFlavor dfRTF = new DataFlavor("text/rtf", "Rich Formatted Text");
DataFlavor dfTxt = DataFlavor.stringFlavor;
result = rtfToHtml(new StringReader(streamToString((InputStream) contents.getTransferData(dfRTF))));

rtfToHtml ()

public static String rtfToHtml(Reader rtf) throws IOException { 
        JEditorPane p = new JEditorPane();
        p.setContentType("text/rtf");
        EditorKit kitRtf = p.getEditorKitForContentType("text/rtf");
        try {
            kitRtf.read(rtf, p.getDocument(), 0);
            kitRtf = null;
            EditorKit kitHtml = p.getEditorKitForContentType("text/html");
            Writer writer = new StringWriter();
            kitHtml.write(writer, p.getDocument(), 0, p.getDocument().getLength());
            return writer.toString();

        } catch (BadLocationException e) {
            e.printStackTrace();
        }
        return null;
    }

Appreciated if anyone could help me to fix this for Libre spreadsheet. Please advice. Thanks

edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by Alex Kemp
close date 2016-02-19 11:10:16.951275

Comments

I don't understand. You have spreadsheets (they're not "Libre spreadsheets", at best Open Document Spreadsheets) as RTF files? Are you using the LibreOffice JDK here?

bencomp gravatar imagebencomp ( 2014-07-12 17:01:16 +0100 )edit