You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "EugeneTorap (via GitHub)" <gi...@apache.org> on 2023/01/28 11:57:52 UTC

[GitHub] [superset] EugeneTorap commented on a diff in pull request #19810: feat(reports): xlsx attachments

EugeneTorap commented on code in PR #19810:
URL: https://github.com/apache/superset/pull/19810#discussion_r1089720796


##########
superset/reports/commands/execute.py:
##########
@@ -330,13 +332,25 @@ def _get_log_data(self) -> HeaderDataType:
         }
         return log_data
 
+    def _get_xlsx_data(self) -> bytes:
+        csv_data = self._get_csv_data()
+
+        df = pd.read_csv(BytesIO(csv_data))
+        bio = BytesIO()
+
+        # pylint: disable=abstract-class-instantiated
+        with pd.ExcelWriter(bio, engine="openpyxl") as writer:
+            df.to_excel(writer, index=False)

Review Comment:
   Use `df_to_excel` in `superset/utils/excel.py`



##########
superset/reports/commands/execute.py:
##########
@@ -330,13 +332,25 @@ def _get_log_data(self) -> HeaderDataType:
         }
         return log_data
 
+    def _get_xlsx_data(self) -> bytes:
+        csv_data = self._get_csv_data()
+
+        df = pd.read_csv(BytesIO(csv_data))

Review Comment:
   Retrieving `df` from csv data it's not the good approach. We need to write a common method for csv and excel where we provide `df` param like `get_data(self, df: pd.DataFrame)` in `superset/common/query_context_processor.py`.
   @dpgaspar Am I correct?
   ![image](https://user-images.githubusercontent.com/29536522/215264995-1cfd07c4-1c12-43b8-8d03-2920b40d0ce1.png)
   



##########
superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx:
##########
@@ -418,6 +418,7 @@ const TRANSLATIONS = {
   CHART_TEXT: t('Chart'),
   SEND_AS_PNG_TEXT: t('Send as PNG'),
   SEND_AS_CSV_TEXT: t('Send as CSV'),
+  SEND_AS_XLSX_TEXT: t('Send as XLSX'),

Review Comment:
   Rename to 'Send as Excel'



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org