Issue with the excel file opening.

Issue with the excel file opening.

srtotasrtota Posts: 5Questions: 1Answers: 0

I have exported the excel file from datatable. When i try to open the file it is giving warning like " The file format and extension of file don't match . The file could be corrupted of unsafe.Unless you trust its source, don't open it. Do you want to open it anyway ?".
please suggest how to avoid this warning.

Replies

  • kthorngrenkthorngren Posts: 20,545Questions: 26Answers: 4,818

    Are you trying to customize the data export? If so then the customization code is setting something improperly.

    Please post your code for the Excel export.

    Kevin

  • srtotasrtota Posts: 5Questions: 1Answers: 0

    This is the code to export -
    $("#mysowDTTableForExcel").table2excel({

            name: "Request Data",
            filename: "SowRequests" //do not include extension
        });
    

    Data table code :

    mysowDTExcelTable=$('#mysowDTTableForExcel').dataTable({

        "bLengthChange": false, /*option to select size of the page*/
        "bPaginate": false,     /*pagination*/
        "bInfo" : false,
        "showNEntries" : false,
        "dom": "lfrti",
            "order" : [],
            "bFilter": false,
    
            "columns" : [
                         {
                             "defaultContent" : "",
                             "mData" : "RequestId",
    
                         },
                         {
                             "defaultContent" : "",
                             "mData" : "DealId",
                         },
                         {
                             "defaultContent" : "",
                             "mData" : "ProjectId",                          
    
                         },
                         {
                             "defaultContent" : "",
                             "mData" : "CustomerName",
    
                         },
                         {
                             "defaultContent" : "",
                             "mData" : "Status",
                         },
                         {
                             "defaultContent" : "",
                             "mData" : "CreatedDate",
                         },
                         {
                             "defaultContent" : "",
                             "mData" : "CreatorUserID",
                         },
                         {
                             "defaultContent" : "",
                             "mData" : "Coowners",
    
                         }
                         ]
    });
    
  • bindridbindrid Posts: 730Questions: 0Answers: 119

    https://github.com/rainabba/jquery-table2excel Look at their disclaimer.

    It says you will probably get that warning.

    Any particular reason you choose that one over the one that comes with DataTables?

  • srtotasrtota Posts: 5Questions: 1Answers: 0

    If i use the one comes with data table..
    1.i will get current page details . but we have pagination.
    2. In table data we have column values as trimmed( like value...), but while export the complete value should go.
    3. we are using separate icon for export functionality, if i use data table it will show the button.

  • kthorngrenkthorngren Posts: 20,545Questions: 26Answers: 4,818

    As Bindrid mentioned table2excel is not a Datatables product.

    If i use the one comes with data table..
    1.i will get current page details . but we have pagination.

    As long as you are not using server side processing (which it doesn't look like you are by the code) then you will, by default, get all the data loaded on the client side.

    1. In table data we have column values as trimmed( like value...), but while export the complete value should go.

    With client side processing you should be able to do this also.

    1. we are using separate icon for export functionality, if i use data table it will show the button.

    It is possible to call the export code from Javascript, see this thread for details:
    https://datatables.net/forums/discussion/32764

    Unless you are using server side processing you might find it easier to get the functionality needed from the Datatables export buttons than to troubleshoot why table2excel is writing a corrupt Excel file.

    Kevin

  • srtotasrtota Posts: 5Questions: 1Answers: 0

    Thanks for the Reply.

    I tried this , but got "object doesn't support property or method button". Any input on this.

    var tablex = $('#mysowDTTableForExcel').DataTable();

    tablex.button( '2-1' ).trigger();
    
  • kthorngrenkthorngren Posts: 20,545Questions: 26Answers: 4,818

    Did you load the appropriate buttons libraries?

    If not the download builder might be the easiest way to get them:
    https://datatables.net/download/index

    Kevin

This discussion has been closed.