如何在Web API2.0中从数据库导出Excel文件中的数据 [英] how to export data in Excel file from database in web API2.0

查看:224
本文介绍了如何在Web API2.0中从数据库导出Excel文件中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想在WEB API2.0中从数据库导出数据到excel格式

Hi All,

I want to export data into excel format from database in WEB API2.0

推荐答案

你可以这样试试





can you try this way


// GET api/values/
    public HttpResponseMessage Get()
    {

        //DataTable Dt= GetData();  Getdata from database in thr form d
        //Generate  html table sturcture
        string str = "<table><tr> <th>colume1</th></tr><tr> <td>abc</td> </tr></table>";
        HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
        result.Content = new StringContent(str);
        result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/vnd.ms-excel");
        result.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); //attachment will force download
        result.Content.Headers.ContentDisposition.FileName = "data.xlsx";
        return result;
    }


这篇关于如何在Web API2.0中从数据库导出Excel文件中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆