dosubot[bot] commented on issue #38555: URL: https://github.com/apache/superset/issues/38555#issuecomment-4030313252
<!-- Answer --> I found an important issue - looking at the actual [`excel.py` source](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/utils/excel.py#L43-L53), the sheet name is `"Sheet 1"` (with a space), not `'Sheet1'`. My earlier suggestion was wrong. Let's add logging to verify your changes are being executed. Update your `df_to_excel()` function in `superset/utils/excel.py`: ```python import logging # Add at top of file if not present logger = logging.getLogger(__name__) def df_to_excel(df: pd.DataFrame, **kwargs: Any) -> Any: logger.warning("=== df_to_excel called ===") # Using warning so it shows regardless of log level logger.warning("DataFrame shape: %s, columns: %s", df.shape, list(df.columns)) output = io.BytesIO() df = quote_formulas(df) with pd.ExcelWriter(output, engine="xlsxwriter") as writer: df.to_excel(writer, **kwargs) workbook = writer.book worksheet = writer.sheets["Sheet 1"] # Note: "Sheet 1" with space! spanish_format = workbook.add_format({ 'num_format': '#.##0,00' }) numeric_cols = df.select_dtypes(include=['float64', 'int64', 'float32', 'int32']).columns logger.warning("Numeric columns found: %s", list(numeric_cols)) for col_idx, col_name in enumerate(df.columns): if col_name in numeric_cols: excel_col_idx = col_idx + 1 if kwargs.get('index', True) else col_idx from xlsxwriter.utility import xl_col_to_name col_letter = xl_col_to_name(excel_col_idx) worksheet.set_column(f'{col_letter}:{col_letter}', None, spanish_format) logger.warning("Applied Spanish format to column %s (%s)", col_name, col_letter) logger.warning("=== Excel generation complete ===") return output.getvalue() ``` After restarting Superset: 1. Perform the export and check your server logs for the `=== df_to_excel called ===` messages 2. If you **don't** see these log messages, the code isn't being reached (might be caching or a different export path) 3. If you **do** see them but no formatting change, let me know what the logs say about numeric columns Also, make sure to fully restart Superset (not just reload) after making changes. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/d8788476-7e04-42fa-a32a-543839aec25c?feedback_type=great_response&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/d8788476-7e04-42fa-a32a-543839aec25c?feedback_type=irrelevant_answer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/d8788476-7e04-42fa-a32a-543839aec25c?feedback_type=incorrect_sources&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/d8788476-7e04-42fa-a32a-543839aec25c?feedback_type=too_verbose&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/d8788476-7e04 -42fa-a32a-543839aec25c?feedback_type=hallucination&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/d8788476-7e04-42fa-a32a-543839aec25c?feedback_type=bug_report&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report) | [Other](https://app.dosu.dev/response-feedback/d8788476-7e04-42fa-a32a-543839aec25c?feedback_type=other&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-other)</sup> [](https://app.dosu.dev/a28d3c7e-a9d3-459e-9fb6-3a6f9ff4f357/ask?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge) [](https://cursor.com/link/prompt?text=I%20found%20an%20important%20issue%20-%20looking%20at%20the%20actual%20%5B%60excel.py%60%20source%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/utils/excel.py%23L43-L53%29%2C%20the%20sheet%20name%20is%20%60%22Sheet%201%22%60%20%28with%20a%20space%29%2C%20not%20%60%27Sheet1%27%60.%20My%20earlier%20suggestion%20was%20wrong.%0A%0ALet%27s%20add%20logging%20to%20verify%20your%20changes%20are%20being%20executed.%20Update%20your%20%60df_to_excel%28%29%60%20function%20in%20%60superset/utils/excel.py%60%3A%0A%0A%60%60%60python%0Aimport%20logging%20%20%23%20Add%20at%20top%20of%20file%20if%20not%20present%0A%0Alogger%20%3D%20logging.g etLogger%28__name__%29%0A%0Adef%20df_to_excel%28df%3A%20pd.DataFrame%2C%20%2A%2Akwargs%3A%20Any%29%20-%3E%20Any%3A%0A%20%20%20%20logger.warning%28%22%3D%3D%3D%20df_to_excel%20called%20%3D%3D%3D%22%29%20%20%23%20Using%20warning%20so%20it%20shows%20regardless%20of%20log%20level%0A%20%20%20%20logger.warning%28%22DataFrame%20shape%3A%20%25s%2C%20columns%3A%20%25s%22%2C%20df.shape%2C%20list%28df.columns%29%29%0A%20%20%20%20%0A%20%20%20%20output%20%3D%20io.BytesIO%28%29%0A%20%20%20%20df%20%3D%20quote_formulas%28df%29%0A%20%20%20%20%0A%20%20%20%20with%20pd.ExcelWriter%28output%2C%20engine%3D%22xlsxwriter%22%29%20as%20writer%3A%0A%20%20%20%20%20%20%20%20df.to_excel%28writer%2C%20%2A%2Akwargs%29%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20workbook%20%3D%20writer.book%0A%20%20%20%20%20%20%20%20worksheet%20%3D%20writer.sheets%5B%22Sheet%201%22%5D%20%20%23%20Note%3A%20%22Sheet%201%22%20with%20space%21%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20spanish_format%20%3D%20workbook. add_format%28%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%27num_format%27%3A%20%27%23.%23%230%2C00%27%0A%20%20%20%20%20%20%20%20%7D%29%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20numeric_cols%20%3D%20df.select_dtypes%28include%3D%5B%27float64%27%2C%20%27int64%27%2C%20%27float32%27%2C%20%27int32%27%5D%29.columns%0A%20%20%20%20%20%20%20%20logger.warning%28%22Numeric%20columns%20found%3A%20%25s%22%2C%20list%28numeric_cols%29%29%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20for%20col_idx%2C%20col_name%20in%20enumerate%28df.columns%29%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20col_name%20in%20numeric_cols%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20excel_col_idx%20%3D%20col_idx%20%2B%201%20if%20kwargs.get%28%27index%27%2C%20True%29%20else%20col_idx%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20from%20xlsxwriter.utility%20import%20xl_col_to_name%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20col_letter%20%3D%20xl_col_to_name%28excel_col_idx%29%0A%20%20%20% 20%20%20%20%20%20%20%20%20%20%20%20%20worksheet.set_column%28f%27%7Bcol_letter%7D%3A%7Bcol_letter%7D%27%2C%20None%2C%20spanish_format%29%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20logger.warning%28%22Applied%20Spanish%20format%20to%20column%20%25s%20%28%25s%29%22%2C%20col_name%2C%20col_letter%29%0A%20%20%20%20%0A%20%20%20%20logger.warning%28%22%3D%3D%3D%20Excel%20generation%20complete%20%3D%3D%3D%22%29%0A%20%20%20%20return%20output.getvalue%28%29%0A%60%60%60%0A%0AAfter%20restarting%20Superset%3A%0A1.%20Perform%20the%20export%20and%20check%20your%20server%20logs%20for%20the%20%60%3D%3D%3D%20df_to_excel%20called%20%3D%3D%3D%60%20messages%0A2.%20If%20you%20%2A%2Adon%27t%2A%2A%20see%20these%20log%20messages%2C%20the%20code%20isn%27t%20being%20reached%20%28might%20be%20caching%20or%20a%20different%20export%20path%29%0A3.%20If%20you%20%2A%2Ado%2A%2A%20see%20them%20but%20no%20formatting%20change%2C%20let%20me%20know%20what%20the%20logs%20say%20about%20numeric%20columns%0A%0AAlso%2C% 20make%20sure%20to%20fully%20restart%20Superset%20%28not%20just%20reload%29%20after%20making%20changes.) [](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord) [](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/apache/superset/issues/38555) -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
