Select to view content in your preferred language

Export feature table to an excel file

657
3
03-19-2024 11:06 AM
cadgism
Regular Contributor

Hi All, Thanks in advance. Please throw some light on the following:

1 . What is the simplest way to export a feature table content to excel.

2. How can I convert feature Table into html table

Thank you

0 Kudos
3 Replies
clt_cabq
Frequent Contributor

If you working in ArcGIS Pro, find the table you want in your table of contents in ArcGIS Pro, right click and from the context menu click on Data, the export. Rename the output to go where you want it to be and give it a .csv file extension which you can open it up in excel.

I don't know about #2 unfortunately. 

0 Kudos
cadgism
Regular Contributor

Thank you

But I am looking a way to accomplish it in ArcGIS Javascript API

0 Kudos
JeffreyThompson2
MVP Regular Contributor

This block of code should create a downloadable csv and add it as a button to a FeatureTable.

function customExportCSV() {
    let query = featureLayer.createQuery()
    query.where = '1=1'
    let csv = ''
    let headers = ''

    featureLayer.queryFeatures(query).then((featureSet) => {
        headers = Object.keys(featureSet.features[0].attributes).join(',')

        for (let i = 0; i < featureSet.features.length; i++) {
            const data = Object.values(featureSet.features[i].attributes).join(',')
            csv += data + '\n'
        }

        csv = headers + '\n' + csv

        downloadCSV(csv)
    })   
}   

function downloadCSV(csv) {
    const csvFile = new Blob([csv], { type: 'text/csv' });
    const downloadLink = document.createElement("a");
    downloadLink.download = 'search_results.csv';
    downloadLink.href = window.URL.createObjectURL(csvFile);
    downloadLink.style.display = "none";

    document.body.appendChild(downloadLink);
    downloadLink.click();
}  

const downloadButton = new ButtonMenuItem({
    label: 'Download CSV',
    iconClass: 'esri-icon-download',
    clickFunction: customExportCSV,
    autoCloseMenu: true
})

const newTable =  new FeatureTable({
    view: mapView.view,
    layer: featureLayer,
    container: table,
    autoRefreshEnabled: true,
    id: props.key,
    menuConfig: {
        items: [downloadButton]
    }
})
GIS Developer
City of Arlington, Texas