1

我正在研究java项目。在此,我完成了将 ods 文件转换为 html 的代码,然后在浏览器中打开该转换后的文件。
以下是我的代码:-

private String ConvertOdtAndOdsToHTML(String sDocPath, String finalDestinationPath, String downloadImagePath, String returnPath) {
        try {
            String root = finalDestinationPath;
            int lastIndex = sDocPath.lastIndexOf(File.separator);
            String sFileName = sDocPath.substring(lastIndex + 1, sDocPath.length());
            String fileNameWithOutExt = FilenameUtils.removeExtension(sFileName);
            String fileOutName = root + File.separator + fileNameWithOutExt + ".html";
            InputStream in = new FileInputStream(new File(sDocPath));
            String ext = FilenameUtils.getExtension(sDocPath);
            OdfTextDocument document = null;
            OdfSpreadsheetDocument odfSpreadsheetDocument = null;
            if (ext.equalsIgnoreCase("odt")) {
                 document = OdfTextDocument.loadDocument(in);
            }
            else  if (ext.equalsIgnoreCase("ods")) {
                 odfSpreadsheetDocument = OdfSpreadsheetDocument.loadDocument(in);
            }
            org.odftoolkit.odfdom.converter.xhtml.XHTMLOptions options = org.odftoolkit.odfdom.converter.xhtml.XHTMLOptions.create();
            // Extract image
            String sLocalSystemImagePath = finalDestinationPath + File.separator+"images"+File.separator;
            File imageFolder = new File(sLocalSystemImagePath);


            options.setExtractor( new org.openskye.resource.FileImageExtractor( imageFolder ) );
            // URI resolver
            String localHostImagePath = downloadImagePath + File.separator+"images"+File.separator;
            FileResolverOdt fileURIResolver = new FileResolverOdt(new File(localHostImagePath));
            options.URIResolver(fileURIResolver);
            // URI resolver

            OutputStream out = new FileOutputStream(new File(fileOutName));
            if (ext.equalsIgnoreCase("odt")) {
                org.odftoolkit.odfdom.converter.xhtml.XHTMLConverter.getInstance().convert(document, out, options);
            }
            else if (ext.equalsIgnoreCase("ods")) {
                org.odftoolkit.odfdom.converter.xhtml.XHTMLConverter.getInstance().convert(odfSpreadsheetDocument, out, options);
            }
            return returnPath + File.separator + fileNameWithOutExt + ".html";
        } catch (Exception e) {
            return "Failed to open the document: " + sDocPath + " due to error:" + e.getMessage();
        }
    }

我能够将 ods 文件转换为 html 并且文件也在浏览器中打开,但它显示了一些问号???? 以及浏览器中的日期和时间。我只想在文件在开放式办公室打开时显示文件,而不显示日期时间和任何特殊字符。我也想区分床单。

附图显示了???  以及显示在浏览器中并且我要删除的日期和时间

这是我要转换的 ods 文件链接 下面附上转换为 html 的 ods 文件的屏幕截图

在此处输入图像描述

如果有人能帮助我找到解决方案,我将不胜感激。

4

0 回答 0