从数据库打开 Xlsx

open Xlsx from database

我正在尝试打开一个 xlsx 文件 实际上是作为 Blob 存储在数据库中的。所以这个过程分为三个步骤:

1st : 从数据库中获取文件。

第二:保存在服务器上。

第 3 次:打开它。

我试过像这样使用 outputstream :

 InputStream in = blob.getBinaryStream();
 OutputStream out = new FileOutputStream("c:/mytemp/testanar.xlsx");
 byte[] buff = blob.getBytes(1,(int)blob.length());
 out.write(buff);
 out.close();

但我找不到将此方法用于 URL 的任何问题。

我的问题是如何在服务器上保存文件?

我找到了解决问题的方法。我的问题是找到一种在 Web 应用程序中使用浏览器打开 excel 文件的方法。 这是 2 个步骤的解决方案:

第一步:

安装一个扩展程序来帮助您阅读我使用的 excel 的文件 https://chrome.google.com/webstore/detail/office-editing-for-docs-s/gbkeegbaiigmenfmjfclcdgdpimamgkj

第二步:

创建一个 servlet 来帮助您阅读您的文件这是我的一部分:

public String downloadDocument(@PathVariable int docId, HttpServletResponse response) throws IOException {
    Rapport document = rapportService.findRapportById(docId);

    response.setContentType(document.getType());
    response.setContentLength(document.getContent().length);
    // if you want to download the file instead of reading the same file 
    // remove "//" below
    //response.setHeader("Content-Disposition", "attachment; filename=\"" + document.getName() + "\"");
    FileCopyUtils.copy(document.getContent(), response.getOutputStream());

    return "redirect:listofreports";
}

[编辑] : 其中 Rapport 是代表 excel 文件的模型。

祝你好运。