easyeExcel把SqlServer数据库的数据写入Excel并返回下载链接

本文介绍了如何使用easyeExcel库将SqlServer数据库中的数据导出到Excel文件,并提供了从Controller到Service、Mapper的相关代码示例,帮助开发者实现数据导出功能,并能直接获取下载链接。
摘要由CSDN通过智能技术生成

改要求了,要返回下载链接了,自从学了easyeExcel没那么复杂,建议可以去学学,以后这种操作excel不用慌了!!!

在这里插入图片描述

controller

package com.wql.codebase.controller;

import com.wql.codebase.pojo.Msg;
import com.wql.codebase.pojo.UserStoreSales;
import com.wql.codebase.service.StoreSalesService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@RestController
public class StoreSalesServiceController {
   
    @Resource
    private StoreSalesService storeSalesService;
    @Resource
    private HttpServletRequest request;

    /**
     * 通过查询SqlServer数据库,把数据存放Excel,返回一个Excel链接
     * @param userStoreSales
     * @return
     * @throws IOException
     */
    @PostMapping("/getStoreSales")
    public Msg getStoreSales(UserStoreSales userStoreSales) throws IOException {
   
        String token = request.getHeader("token");
//        return storeSalesService.getStoreSales(userStoreSales);
       return storeSalesService.getStoreSales(userStoreSales);
    }
}

两个util

package com.wql.codebase.utils;
import com.microsoft.azure.storage.blob.*;
import com.microsoft.azure.storage.blob.models.ContainerCreateResponse;
import com.microsoft.rest.v2.RestException;
import com.wql.codebase.pojo.Msg;
import io.reactivex.Single;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.AsynchronousFileChannel;
import java.security.InvalidKeyException;

/**
 * 功能描述:
 *
 * @author by lgq
 * @create 2019/11/13
 */
public class MicrosoftOssUtil {
   

	private static ContainerURL containerURL;
	static {
   
		try {
   

			// Retrieve the credentials and initialize SharedKeyCredentials
			String accountName = "manwahcrmapiprd";
			String accountKey = "9nqa+nAsDi0MsGpCCGb5gJLZq7wUzcJzhM56r3LnKUEdKi3CS/RCUvaZ0SgvN2lLjyATAinzBqjpEa2ZOumqUQ==";

			// Create a ServiceURL to call the Blob service. We will also use this to construct the ContainerURL
			SharedKeyCredentials creds = new SharedKeyCredentials(accountName, accountKey);
			// We are using a default pipeline here, you can learn more about it at https://github.com/Azure/azure-storage-java/wiki/Azure-Storage-Java-V10-Overview
			final ServiceURL serviceURL = new ServiceURL(new URL("https://" + accountName + ".blob.core.windows.net"), StorageURL.createPipeline(creds, new PipelineOptions()));

			// Let's create a container using a blocking call to Azure Storage
			// If container exists, we'll catch and continue
			containerURL = serviceURL.createContainerURL("excel");

			try {
   
				ContainerCreateResponse response = containerURL.create(null, null, null).blockingGet();
				System.out.println("Container Create Response was " + response.statusCode());
			} catch (RestException e) {
   
				if (((RestException) e).response().statusCode() != 409) {
   
					throw e;
				} else {
   
					System.out.println("quickstart container already exists, resuming...");
				}
			}

		} catch (InvalidKeyException e) {
   
			System.out.println("Invalid Storage account name/key provided");
		} catch (MalformedURLException e) {
   
			System.out.println("Invalid URI provided");
		} catch (RestException e){
   
			System.out.println("Service 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值