Visualizzazione dei risultati da 1 a 6 su 6

Discussione: org.apache.poi.xwpf

  1. #1
    Utente di HTML.it L'avatar di paul78
    Registrato dal
    Apr 2010
    Messaggi
    515

    org.apache.poi.xwpf

    ciao a tutti!!!!

    riesco in java ad aprire il file docx...questo è il cod.

    codice:
    import java.io.FileInputStream;   
    import java.io.InputStream;
    import javax.swing.*;
    import org.apache.poi.xwpf.extractor.XWPFWordExtractor;   
    import org.apache.poi.xwpf.usermodel.XWPFDocument;
      
    public class Test {   
      
        public static void main(String[] args) { 
        	JTextArea textArea = new JTextArea(20,30);
        	JFrame frame = new JFrame("Prova");
        	JPanel p = new JPanel();
        	p.add(textArea);
        	frame.setSize(700,600);	
    		frame.getContentPane().add(p);
    		frame.setVisible(true);
            try {      
                InputStream in = new FileInputStream("C://text.docx");   
                XWPFDocument docIn = new XWPFDocument(in);   
                XWPFWordExtractor extractor = new XWPFWordExtractor(docIn);   
                //String docText = extractor.getText();
                textArea.append(extractor.getText());
                
            } catch (Exception e) {   
                System.out.println("...");   
            }   
        }   
    }
    in questo modo mi aggiunge il testo a JTextArea....ma nel file text.docx ho alcune lettere in maiuscolo ed alcune in grassetto....ma quando lo apro in JTextArea me lo apre con testo normali....come faccio ad aprirlo uguale????

  2. #2
    Utente di HTML.it
    Registrato dal
    Feb 2007
    Messaggi
    4,157
    Niente che la documentazione non ti dica (ma ormai mi sono pure stancata di ricordartelo).
    JTextArea è un componente che non tiene "gli stili", quindi se usi quello non hai grassetto & company.

    Ti metto in evidenza dei punti (tanto so che non leggi il link che ti ho dato)

    Editor panes, by default, know how to read, write, and edit plain, HTML, and RTF text. Text panes inherit this capability but impose certain limitations. A text pane insists that its document implement the StyledDocument interface. HTMLDocument and RTFDocument are both StyledDocuments so HTML and RTF work as expected within a text pane. If you load a text pane with plain text though, the text pane's document is not a PlainDocument as you might expect, but a DefaultStyledDocument.

    To support a custom text format, implement an editor kit that can read, write, and edit text of that format. Then call the registerEditorKitForContentType method to register your kit with the JEditorPane class. By registering an editor kit in this way, all editor panes and text panes in your program will be able to read, write, and edit the new format. However, if the new editor kit is not a StyledEditorKit, text panes will not support the new format.

    trai le tue conclusioni
    RTFM Read That F*** Manual!!!

  3. #3
    Utente di HTML.it L'avatar di paul78
    Registrato dal
    Apr 2010
    Messaggi
    515
    ciao valia...mi sono documentato e con JEditorPane riesco a copiare i file rtf...ma ho solo un'altro piccolissimo problema...

    praticamente quando copio i caratteri nel JEditorPane non rispetta "a capo"cioè li unisce tutti insieme...io vorrei che copiasse il testo come è il file originale.....ad esempio:

    se nel file prova.rtf ho:

    123
    1234
    12345

    vorrei che me li copisse in questo modo...è possibile???

  4. #4
    Utente di HTML.it L'avatar di Alex'87
    Registrato dal
    Aug 2001
    residenza
    Verona
    Messaggi
    5,802
    extractor.getText()+"\n"
    SpringSource Certified Spring Professional | Pivotal Certified Enterprise Integration Specialist
    Di questo libro e degli altri (blog personale di recensioni libri) | ​NO M.P. TECNICI

  5. #5
    Utente di HTML.it L'avatar di paul78
    Registrato dal
    Apr 2010
    Messaggi
    515
    in questo link:

    http://www.cs.cf.ac.uk/Dave/HCI/HCI_...R/node123.html

    spiega come aprire un file rtf in un JEditorPane...ma nel momento in cui apro il file non rispetta i caratteri che vanno "a capo"....

  6. #6
    Utente di HTML.it L'avatar di paul78
    Registrato dal
    Apr 2010
    Messaggi
    515
    ciao a tutti!!!

    non riesco ancora ad aprire i file .docx....

    ma con questo cod.

    desktop.open(new File("c:\\a.doc"));


    posso aprire il file word....

    è possibile aprire il file word all'interno di un JFrame o un JPanel??????

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.