Home > Net >  MVC server returns the bitstream of EXCEL, the front desk how to receive and translate into EXCEL fo
MVC server returns the bitstream of EXCEL, the front desk how to receive and translate into EXCEL fo

Time:09-30

1. Can not be through the server generates a A.X LS file, and then the browser to access this path then to download this file, this method cannot be used,
2. I don't think the effect of the server to generate A.X LS file, directly in the form of a flow to the client and then download, how to achieve this?
3. The flow can be a byte, can also be a MemoryStream flow,

CodePudding user response:

How do you plan flow, the data is pass it on,

CodePudding user response:

System. IO. MemoryStream ms=new System. IO. MemoryStream ();
The book. Write (ms);//in written to the MemoryStream
Ms. Seek (0, SeekOrigin. Begin);
Byte [] bytelength=Ms. ToArray ();
Ms. Write (bytelength, 0, bytelength. Length);
Var filePath=Server. MapPath (tablename "~/excel/" + +". XLS ");
MainModels. WriteBuffToFile (bytelength filePath);//generates EXCEL file
Return the File (filePath, "application/VND. - ms excel," tablename + ". XLS ");

This is my current code is to survive EXCEL file first and then to the service side download EXCEL file, I don't like this way, I want to pass the flow directly output to the browser, and then download the EXCEL,

CodePudding user response:

If it is, can use the WebSocket,

CodePudding user response:

Dizzy,
you then!Byte [] bytelength=Ms. ToArray ();
Return the File (bytelength, "application/VND. - ms excel," tablename + ". XLS ");
  •  Tags:  
  • C#
  • Related