简体   繁体   English

从AWS S3存储桶读取Excel文件

[英]Read excel file from AWS S3 Bucket

Currently I have a method to read an excel file that is on my local machine using filename path like this: 目前,我有一种使用文件名路径读取本地计算机上的excel文件的方法,如下所示:

               // Create COM Objects. Create a COM object for everything that is referenced
               Console.WriteLine("Begin reading file...");
               Excel.Application xlApp = new Excel.Application();
               Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\Users\user1\Desktop\file1.xlsx");
               Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1];
               Excel.Range xlRange = xlWorksheet.UsedRange;
               // Some code here

Now I have to read the file from an AWS S3 bucket, and I'm pretty new to the whole AWS environment. 现在,我必须从一个AWS S3存储桶中读取文件,并且对于整个AWS环境而言,我还是一个新手。 From all the sources I read I think the file you get from a S3 bucket only can be returned as "stream" type. 从我阅读的所有资料中,我认为您只能将从S3存储桶中获取的文件作为“流”类型返回。

How do I make it work with my current method? 如何使其与当前方法兼容?

Is there other better way to do this, my goal is just read an excel file from a S3 bucket and do something with the data inside. 还有其他更好的方法可以做到这一点,我的目标是从S3存储桶中读取一个excel文件,并对内部数据进行处理。

There are a couple of things you can do. 您可以做几件事。 Here's a couple 这是一对

  1. You can save the blob as a local file. 您可以将Blob保存为本地文件。 Docs from AWS 来自AWS的文档
  2. You can use third party to mount your bucket as a virtual Drive. 您可以使用第三方将存储桶安装为虚拟驱动器。 Check here . 在这里检查 Keep in mind you're making your operations across the network here. 请记住,您正在此处通过网络进行操作。
  3. You may also just skip the COM objects alltogheter and use ClosedXML . 您也可以只跳过COM对象,并使用ClosedXML This will avoid the speed and memory issues currently available with COM. 这样可以避免COM当前存在的速度和内存问题。 This will also give you the flexibility to move it to lambda or containerized services since you're already working with AWS. 由于您已经在使用AWS,因此这也使您可以灵活地将其移至lambda或容器化服务。

I'm sure you're aware by now, one thing you'll need to watch out for is the file permission while your process is working with the file. 我确定您现在已经知道,您需要注意的一件事是在您的进程使用文件时的文件许可权。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM