0

I am looking for some help on loading an Excel attachment into memory, and then process the excel document. The main issue im having is using EWS to load the attachment into memory and then processing the document. The end result is to load the attachment, read the excel document line by line and store the data into an object to match the excel layout. I already have the code storing the attachment property of the EWS Mail Object. I then need to do the processing here...

    Public Function ParseEmails(ByVal emails As List(Of MailDT)) As List(Of    PriceInjectionDT)
    Dim ParsedEmails As New List(Of PriceInjectionDT)

    For Each email As MailDT In emails
        For Each a As Microsoft.Exchange.WebServices.Data.Attachment In email.Attachment
            a.Load()

        Next
    Next


End Function

This loads the attachment into memory using the .Load but doesnt give me access to the excel properties :( Help!!!

Jakob Christensen
  • 14,826
  • 2
  • 51
  • 81
user1732364
  • 925
  • 4
  • 28
  • 58

1 Answers1

0

Instead of loading the attachment into memory, you can write to disk using FileAttachment.Load. You would then change your code to the following (untested):

For Each email As MailDT In emails
    For Each a As Microsoft.Exchange.WebServices.Data.FileAttachment In email.Attachment
        a.Load("C:\temp\" + a.Name);


    Next
Next

After saving the attachment to disk, you can open and manipulate it using the functionality of the Office Primary Interop Assemblies (PIAs). I found an article on CodeProject on how to use the PIAs.

Jakob Christensen
  • 14,826
  • 2
  • 51
  • 81
  • correct i performed the .load and then passed it into a stream to generate the file and processed it from there. – user1732364 Apr 03 '13 at 19:58