Skip to content

Commit

Permalink
Merge pull request #3603 from nextcloud/fix/colon-in-sheet-title
Browse files Browse the repository at this point in the history
fix: strip illegal colon from sheet name
  • Loading branch information
hamza221 authored Jul 15, 2024
2 parents fc95ac8 + df992fe commit 95744c4
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/js/components/Export/ExportPoll.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import { mapGetters, mapState } from 'vuex'
import { saveAs } from 'file-saver'
import { utils as xlsxUtils, write as xlsxWrite } from 'xlsx'
import { showError } from '@nextcloud/dialogs'
import { NcActions, NcActionButton } from '@nextcloud/vue'
import ExcelIcon from 'vue-material-design-icons/MicrosoftExcel.vue'
import FileTableIcon from 'vue-material-design-icons/FileTableOutline.vue'
Expand Down Expand Up @@ -96,8 +97,9 @@ export default {
// Not allowed characters for the sheet name: : \ / ? * [ ]
// Strip them out
// Stonger regex i.error. for file names: /[&/\\#,+()$~%.'":*?<>{}]/g
const regex = /[\\/?*[\]]/g
return this.pollConfiguration.title.replaceAll(regex, '').slice(0, 31)
const regex = /[:\\/?*[\]]/g
const title = this.pollConfiguration.title.replaceAll(regex, '').slice(0, 31)
return title || 'polls_export'
},
},

Expand Down Expand Up @@ -173,8 +175,13 @@ export default {
this.addVotesArray()
}

const workBookOutput = xlsxWrite(this.workBook, { bookType: exportType, type: 'binary' })
saveAs(new Blob([this.s2ab(workBookOutput)], { type: 'application/octet-stream' }), `poll.${exportType}`)
try {
const workBookOutput = xlsxWrite(this.workBook, { bookType: exportType, type: 'binary' })
saveAs(new Blob([this.s2ab(workBookOutput)], { type: 'application/octet-stream' }), `poll.${exportType}`)
} catch (error) {
console.error(error)
showError(t('polls', 'Error exporting file.'))
}
},

addVotesArray(style) {
Expand Down

0 comments on commit 95744c4

Please sign in to comment.