MCPcopy
hub / github.com/baidu/amis / exportExcel

Function exportExcel

packages/amis/src/renderers/Table/exportExcel.ts:254–619  ·  view source on GitHub ↗
(
  ExcelJS: any,
  props: TableProps,
  toolbar: ExportExcelToolbar,
  withoutData: boolean = false
)

Source from the content-addressed store, hash-verified

252 * @param withoutData 如果为 true 就不导出数据,只导出表头
253 */
254export async function exportExcel(
255 ExcelJS: any,
256 props: TableProps,
257 toolbar: ExportExcelToolbar,
258 withoutData: boolean = false
259) {
260 const {
261 store,
262 env,
263 classnames: cx,
264 translate: __,
265 data,
266 prefixRow,
267 affixRow
268 } = props;
269 let columns = store.exportColumns || [];
270
271 let rows = [];
272 let tmpStore;
273 let filename = 'data';
274 // 支持配置 api 远程获取
275 if (typeof toolbar === 'object' && toolbar.api) {
276 const pageField = toolbar.pageField || 'page';
277 const perPageField = toolbar.perPageField || 'perPage';
278 const ctx: any = createObject(data, {
279 ...props.query,
280 [pageField]: data.page || 1,
281 [perPageField]: data.perPage || 10
282 });
283
284 const res = await env.fetcher(toolbar.api, ctx, {
285 autoAppend: true,
286 pageField,
287 perPageField
288 });
289 if (!res.data) {
290 env.notify('warning', __('placeholder.noData'));
291 return;
292 }
293 /**
294 * 优先找items和rows,找不到就拿第一个值为数组的字段
295 * 和CRUD中的处理逻辑保持一致,避免能渲染和导出的不一致
296 */
297 if (Array.isArray(res.data)) {
298 rows = res.data;
299 } else if (Array.isArray(res.data?.rows)) {
300 rows = res.data.rows;
301 } else if (Array.isArray(res.data?.items)) {
302 rows = res.data.items;
303 } else {
304 for (const key of Object.keys(res.data)) {
305 if (res.data.hasOwnProperty(key) && Array.isArray(res.data[key])) {
306 rows = res.data[key];
307 break;
308 }
309 }
310 }
311

Callers 2

renderExportExcelMethod · 0.90

Calls 15

createObjectFunction · 0.90
filterFunction · 0.90
isPureVariableFunction · 0.90
resolveVariableAndFilterFunction · 0.90
arraySliceFunction · 0.90
flattenTreeFunction · 0.90
getVariableFunction · 0.90
isObjectFunction · 0.90
removeHTMLTagFunction · 0.90
decodeEntityFunction · 0.90
exportExcelWithoutDataFunction · 0.85
renderSummaryFunction · 0.85

Tested by

no test coverage detected