()
| 72 | async def export_excel(session: SessionDep, trans: Trans, current_user: CurrentUser, |
| 73 | word: Optional[str] = Query(None, description="搜索术语(可选)")): |
| 74 | def inner(): |
| 75 | _list = get_all_terminology(session, word, oid=current_user.oid) |
| 76 | |
| 77 | data_list = [] |
| 78 | for obj in _list: |
| 79 | _data = { |
| 80 | "word": obj.word, |
| 81 | "other_words": ', '.join(obj.other_words) if obj.other_words else '', |
| 82 | "description": obj.description, |
| 83 | "all_data_sources": 'N' if obj.specific_ds else 'Y', |
| 84 | "datasource": ', '.join(obj.datasource_names) if obj.datasource_names and obj.specific_ds else '', |
| 85 | } |
| 86 | data_list.append(_data) |
| 87 | |
| 88 | fields = [] |
| 89 | fields.append(AxisObj(name=trans('i18n_terminology.term_name'), value='word')) |
| 90 | fields.append(AxisObj(name=trans('i18n_terminology.synonyms'), value='other_words')) |
| 91 | fields.append(AxisObj(name=trans('i18n_terminology.term_description'), value='description')) |
| 92 | fields.append(AxisObj(name=trans('i18n_terminology.effective_data_sources'), value='datasource')) |
| 93 | fields.append(AxisObj(name=trans('i18n_terminology.all_data_sources'), value='all_data_sources')) |
| 94 | |
| 95 | md_data, _fields_list = DataFormat.convert_object_array_for_pandas(fields, data_list) |
| 96 | |
| 97 | df = pd.DataFrame(md_data, columns=_fields_list) |
| 98 | |
| 99 | buffer = io.BytesIO() |
| 100 | |
| 101 | with pd.ExcelWriter(buffer, engine='xlsxwriter', |
| 102 | engine_kwargs={'options': {'strings_to_numbers': False}}) as writer: |
| 103 | df.to_excel(writer, sheet_name='Sheet1', index=False) |
| 104 | |
| 105 | buffer.seek(0) |
| 106 | return io.BytesIO(buffer.getvalue()) |
| 107 | |
| 108 | result = await asyncio.to_thread(inner) |
| 109 | return StreamingResponse(result, media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") |
nothing calls this directly
no test coverage detected