t-chatoyan / vue-excel-xlsx

Convert your Data as an XLSX file
MIT License
39 stars 28 forks source link

Only create the Excel data on button click? #6

Open jdl2206 opened 4 years ago

jdl2206 commented 4 years ago

Thanks so much for this awesome component! Our data is in a 2D String array so I need to format it as json before the Excel file is created. I'd prefer to only have to format the data when the Download Excel button is clicked. Is there a way to do that?

antiv commented 1 year ago

Hi,

this is workaround, but you can use ref and call exportExcel().

    <vue-excel-xlsx
            ref="xlsxData"
            style="display: none"
            :data="jsonData['data']"
            :columns="jsonData['columns']"
            file-name="Exported data"
            :file-type="'xlsx'"
            :sheet-name="'Export'"
          >
    </vue-excel-xlsx>
    <button
            type="button"
            class="btn btn-success bi bi-download"
            @click="clickOk"
          >
            Download
     </button>

and in script part:

async clickOk() {
   this.jsonData = await getData();
   setTimeout(() => {
        this.$refs["xlsxData"].exportExcel();
      }, 200);
}