0

I'm working with asp.net core webapi and I want to post an excel file from client (using Angular 2) to my Controller. I've read Import Excel example but what they've done is use an existing file. I want to know how can I read an excel file using IO.Stream. Thanks for your help. I've started read a .txt file like this:

public string Post()
    {
        var files = Request.Form.Files;
        if(files != null)
        {

            var stream = files[0].OpenReadStream();
            StreamReader reader = new StreamReader(stream);

            string result = reader.ReadToEnd();
            int a;
            return result;
        }
        return "";
    }

1 Answer 1

3

As I understand you're trying to use EPPlus library (one of the ports compatible with .NET Core). ExcelPackage class has an overload that accepts Stream with existing Excel content (only OpenXML-based XLSX):

using (ExcelPackage package = new ExcelPackage(stream)) {
   ...
}
Sign up to request clarification or add additional context in comments.

1 Comment

I've just installed it to my project and I've found the overload constructor as you've suggested me. Anyway, Many thanks for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.