Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用Java和OpenOffice UNO API操作odt文件中的嵌入式文件_Java_Openoffice.org - Fatal编程技术网

如何使用Java和OpenOffice UNO API操作odt文件中的嵌入式文件

如何使用Java和OpenOffice UNO API操作odt文件中的嵌入式文件,java,openoffice.org,Java,Openoffice.org,我找到了一种在ODF文件中存储自定义文件的方法,将它们存储在一个新的资源目录中,并将其包含在一个新的mimetype下的清单中 我想知道的是如何在Java OpenOffice附加组件中实现以下功能: 读取“我的资源”中的文件:是否可以获取其内容的InputStreamReader 创建一个新文件:我能以某种方式创建并写入一个新文件吗 关于如何做到这一点的任何想法。我不熟悉UNOAPI,有点困惑 /* this java code need one jar file named with odf

我找到了一种在ODF文件中存储自定义文件的方法,将它们存储在一个新的资源目录中,并将其包含在一个新的mimetype下的清单中

我想知道的是如何在Java OpenOffice附加组件中实现以下功能:

  • 读取“我的资源”中的文件:是否可以获取其内容的InputStreamReader
  • 创建一个新文件:我能以某种方式创建并写入一个新文件吗
  • 关于如何做到这一点的任何想法。我不熟悉UNOAPI,有点困惑

    /* this java code need one jar file named with odfdom-java 0.8.6 , and it will able to read any odt file and can store in string and can also change the content of the original file on new or existing file what ever your requirement . if you want to create new file then give new file name and path at the method "document.save("D:/newFile.odt")".
    */
    
    1)--> FileReaderTemp .java
    
    package com.ik.candidate.util;
    
    import java.io.File;
    
    import org.apache.log4j.Logger;
    import org.odftoolkit.odfdom.doc.OdfTextDocument;
    import org.odftoolkit.odfdom.incubator.search.TextNavigation;
    import org.odftoolkit.odfdom.incubator.search.TextSelection;
    
    public class FileReaderTemp {
    
        public static void main(String[] args) throws Exception {
            parseAll("d:/odt_resume/vrunda_ashar_Rajkot_00.odt");
        }
    
        public static void parseAll(String fileName) throws Exception {
            Logger logger = Logger.getLogger(FileReaderTemp.class);
            try {
                File file = new File(fileName);
                if (!file.exists()) {
                    logger.debug("Sorry File does not Exists!");
                } else if (file.getName().endsWith(".odt")) {
                    OpenOfficeParser odt = new OpenOfficeParser();
    
                    //getting contents of odt file in string
                    String string = odt.getText(fileName);
                    TextNavigation search;
                    OdfTextDocument document = (OdfTextDocument) OdfTextDocument.loadDocument(fileName);
    
                    // for replacing Email id
                    String emailID="jariya.nilesh99@gmail.com";
                //  String emailID = new FindEmailID().findEmail(string);
                    System.out.println("Email is :: " + emailID);
                    search = new TextNavigation(emailID, document);
                    while (search.hasNext()) {
                    System.out.println("Search is : " + search);
                TextSelection item = (TextSelection) search.getCurrentItem();
                    item.replaceWith("");
                System.out.println("Email id Removed succesfully :: ");
                        }
    
    
                    // for replacing contact no
                      String no="9856565698";   
                                //String no = new FindContactNo().findContact(string);
                    System.out.println("Contact no is :: " + no);
    
                        no = no.replace("+", "");
                        // System.out.println("After removed + : " + no);
    
                        search = new TextNavigation(no, document);
                        // iterate through the search results
                    while (search.hasNext()) {
                    // System.out.println("Search is No : " + search);
                TextSelection item = (TextSelection) search.getCurrentItem();
                    item.replaceWith("");
                            System.out.println("Contact no Removed succesfully :: ");
                        }
    
    
                    // save the modified document back to a original file other wise it will create new odt file
                    document.save(fileName);
                }
            }
    
            catch (Exception e) {
                //logger.error("Exception : " + e);
                System.out.println("Not found ::");
            }
        }
    }