asp.net - How to Edit Excel with EPPLUS and send it as attachment -


i have following code, working, opens file stream embedded xlsx saves on memorystream pass value attachment , send no problem.

private sub sendfile2()     dim path string = server.mappath("~/app_data/rqm.xlsx")     using filest filestream = io.file.openread(path)         dim memstream new memorystream()         memstream.setlength(filest.length)         filest.read(memstream.getbuffer(), 0, cint(filest.length))             '' code mailmessage , smtp goes here             mailmsg.attachments.add(new attachment(memstream, "myfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))          end using     end using end sub 

now im trying edition (adding values file, still working in memorystream) having problems i've added

       using pck excelpackage = new excelpackage(memstream)             dim xlswb excelworkbook = pck.workbook             dim xlsws excelworksheet = xlswb.worksheets.first             xlsws.cells(20, 4).value = "hello world"             pck.saveas(memstream)        end using 

which when put breakpoints see pck getting value of memstream lenght of 83084 (the value of original file) 81kb xlsx, when add value cell lenght of memstream 162143 seems modifications, when send again memstream trough

mailmsg.attachments.add(new attachment(memstream, "myfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) 

i receive file of 165b, , i'm not sure doing wrong. apreciated

edit: wasn't able save same memstream instead did this.

memstream2 = new memorystream(pck.getasbytearray()) mailmsg.attachments.add(new attachment(memstream2, "myfile2.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")) 

and worked charm. hope useful anyone.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -