-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/export xlsx #2658
Feat/export xlsx #2658
Conversation
Thanks for the PR - appreciate it. However, expectation of export to excel here can mean export the entire database. |
Thanks for the answer. I have numerous users (and potential users) on my nocodb instance who don't know how to import a CSV on excel. I'm open for any critics and way to solves this problem. If you know a way to do it without having to contribute, I'd be very pleased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -26,6 +26,7 @@ export default { | |||
dataGroupBy: true, | |||
commentsCount: true, | |||
exportCsv: true, | |||
exportCsvData: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's difference with between exportCsv
and exportCsvData
? Why not using exportExcel
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The xlsx file is created on the frontend. The backend send data as CSV (just data, not file) and the frontend use this data to build a XLSX file.
That's why the endpoint I created is not excel
or xlsx
because the backend doesn't know about all theses things, it only sends CSV file or CSV data.
@@ -13,6 +13,7 @@ export enum RelationTypes { | |||
|
|||
export enum ExportTypes { | |||
CSV = 'csv', | |||
CSV_DATA = 'csvData', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be EXCEL
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I said, the backend doesn't build the excel file. But maybe it'd be better to do so ?
@@ -2554,7 +2554,7 @@ export class Api< | |||
orgs: string, | |||
projectName: string, | |||
tableName: string, | |||
type: 'csv' | 'excel', | |||
type: 'csv' | 'excel' | 'csvData', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why adding a new one instead of using existing excel
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I made the backend send data instead of file.
@@ -2917,7 +2917,7 @@ export class Api< | |||
projectName: string, | |||
tableName: string, | |||
viewName: string, | |||
type: 'csv' | 'excel', | |||
type: 'csv' | 'excel' | 'xlsx', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When to use xlsx
and when to use csvData
?
@@ -18,6 +18,19 @@ async function exportCsv(req: Request, res: Response) { | |||
res.send(data); | |||
} | |||
|
|||
async function exportCsvData(req: Request, res: Response) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably make a generic function, i.e. combining into exportCsv
@@ -39,4 +56,10 @@ router.get( | |||
ncMetaAclMw(csvDataExport, 'exportCsv') | |||
); | |||
|
|||
router.get( | |||
'/api/v1/db/data/:orgs/:projectName/:tableName/views/:viewName/export/csvData', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
naming - similar to other comments.
|
Are you setting the right cell type ? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the PR, left some comments waiting for your update. You can ask for a review when you are done. Feel free to ask anything on process.
res = await this.$api.public.csvExport(this.publicViewId, ExportTypes.CSV_DATA, { | ||
query: { | ||
fields: | ||
this.queryParams && | ||
this.queryParams.fieldsOrder && | ||
this.queryParams.fieldsOrder.filter(c => this.queryParams.showFields[c]), | ||
offset, | ||
sortArrJson: JSON.stringify( | ||
this.reqPayload && | ||
this.reqPayload.sorts && | ||
this.reqPayload.sorts.map(({ fk_column_id, direction }) => ({ | ||
direction, | ||
fk_column_id, | ||
})) | ||
), | ||
filterArrJson: JSON.stringify(this.reqPayload && this.reqPayload.filters), | ||
}, | ||
headers: { | ||
'xc-password': this.reqPayload && this.reqPayload.password, | ||
}, | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should handle shared view case as well. Nothing exported + no corresponding endpoint on backend.
const { data } = res | ||
const xlsx = XLSX.read(data.csvData, { type: 'string' }) | ||
offset = +res.headers['nc-export-offset'] | ||
XLSX.writeFile(xlsx, `${this.meta.title}_exported_${c++}.xlsx`) | ||
if (offset > -1) { | ||
this.$toast.info('Downloading more files').goAway(3000) | ||
} else { | ||
this.$toast.success('Successfully exported all table data').goAway(3000) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part should be out of if/else block, we should return file for both cases.
ExportTypes.CSV_DATA | ||
) | ||
const { data } = res | ||
const xlsx = XLSX.read(data.csvData, { type: 'string' }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like you can use raw: true
to avoid unwanted processing of dates, also looks like it fixes extra empty cells.
Change Summary
Add export xlsx button and on nc-gui.
Here the issue#2565
Change type
Test/ Verification
More
button to have an xlsx exportAdditional information / screenshots (optional)
I decide to have the file construction done by frontend because it was simpler for the backend logic (not duplicate or refactor convoluted code which can be fragile).
If you would like another way of doing things, let me know and I'd gladly implement them.