public async Task <HttpResponseMessage> ExecuteAsync(CancellationToken cancellationToken) { var response = new HttpResponseMessage(); if (_Source != null) { ExcelGenerator.ExportToFile(_Source, _Title, "D:\\text.xls"); MemoryStream ms = ExcelGenerator.Generate(this._Source, this._Title, this._MapInfos); response.Content = new ByteArrayContent(ms.ToArray()); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.ms-excel"); response.Content.Headers.ContentDisposition.FileName = string.Format("{0}.xls", _Title); response.Content.Headers.LastModified = new DateTimeOffset(DateTime.Now); //response.Content.Headers.ContentLength = ms.Length; response.StatusCode = HttpStatusCode.OK; } return(await Task.FromResult(response)); }