Xuất dữ liệu jquery sang phía máy chủ excel

Để có thể xuất dữ liệu, sao chép vào khay nhớ tạm hoặc in, bạn nên sử dụng plugin Công cụ bảng cho DataTables.

Lấy các liên kết CSS và JavaScript CDN của plugin TableTools từ URL sau
https. //www. bảng dữ liệu. net/download/index

Ngoài các tệp CSS và JavaScript, bạn cũng cần có tệp TableTools Flash SWF. Bạn có thể lấy liên kết CDN của tệp TableTools Flash SWF từ URL sau. Bạn sẽ tìm thấy 2 tệp SWF khác nhau. Sự khác biệt duy nhất giữa chúng là một trong số chúng cung cấp khả năng lưu tệp PDF trong khi cái kia thì không. Sự đánh đổi là tệp có khả năng PDF có kích thước lớn hơn đáng kể (56K v 2K).
https. //cdn. bảng dữ liệu. net/tabletools

Tham chiếu JavaScript cần có trên trang
JQuery
DataTables
TableToolsDataTablesTableTools . DataTablesTableTools .

CSS References required on the page
DataTables
TableTools

You also need to set the sSwfPath TableTools option, if you aren't using the same directory structure as the TableTools package.

Hãy thử sử dụng các công cụ dành cho nhà phát triển F12 để kiểm tra xem có bất kỳ lỗi nào không và liệu tải tham chiếu JS và CSS có liên quan có thành công không?

Theo mẫu chính thức của JQuery DataTables và mã của bạn, tôi tạo một mẫu với mã sau, mọi thứ hoạt động tốt bên tôi

< link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css" />  
< link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/2.0.1/css/buttons.dataTables.min.css" />  
@*Since we have already added the JQuery reference in the Layout page, there is no need to add it again.   
If you doesn't add the jquery reference before, remember to add it.*@  
@**@  
< script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js">  
< script src="https://cdn.datatables.net/buttons/2.0.1/js/dataTables.buttons.min.js">  
< script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js">  
< script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js">  
< script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js">  
< script src="https://cdn.datatables.net/buttons/2.0.1/js/buttons.html5.min.js">  
< script type="text/javascript">  
    $(function () {  
        $('#example').DataTable({  
            dom: 'Bfrtip',  
            buttons: [  
                "excel",  
                "pdf",  
                { extent: "print", text: " Print" },  
                { extent: "excelHtml5", text: " Excel HTML5 Export" },  
                { extent: "pdfHtml5", text: " PDF HTML5 Export", title: "Filename" }  
            ]  
        });  
    });  
  

[Lưu ý] Trong đoạn mã trên, giữa '