dosubot[bot] commented on issue #38555:
URL: https://github.com/apache/superset/issues/38555#issuecomment-4030027483

   <!-- Answer -->
   Here's how to modify 
[`superset/utils/excel.py`](https://github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/utils/excel.py#L43-L53)
 to hardcode Spanish number formatting:
   
   **Current code (lines 43-53):**
   ```python
   def df_to_excel(df: pd.DataFrame, **kwargs: Any) -> Any:
       output = io.BytesIO()
       df = quote_formulas(df)
       with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
           df.to_excel(writer, **kwargs)
       return output.getvalue()
   ```
   
   **Replace with:**
   ```python
   def df_to_excel(df: pd.DataFrame, **kwargs: Any) -> Any:
       output = io.BytesIO()
       df = quote_formulas(df)
       
       with pd.ExcelWriter(output, engine="xlsxwriter") as writer:
           df.to_excel(writer, **kwargs)
           
           # Access xlsxwriter objects for custom formatting
           workbook = writer.book
           worksheet = writer.sheets['Sheet1']
           
           # Spanish format: period for thousands, comma for decimal
           spanish_format = workbook.add_format({
               'num_format': '#.##0,00'
           })
           
           # Apply to numeric columns
           numeric_cols = df.select_dtypes(include=['float64', 'int64', 
'float32', 'int32']).columns
           for col_idx, col_name in enumerate(df.columns):
               if col_name in numeric_cols:
                   # +1 offset because pandas writes index as first column by 
default
                   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)
       
       return output.getvalue()
   ```
   
   **Key points:**
   - The format string `'#.##0,00'` uses period for thousands and comma for 
decimals (Spanish style)
   - Access the workbook/worksheet **after** `df.to_excel()` writes the data
   - The `+1` offset accounts for pandas writing the DataFrame index as column 
A by default
   
   After modifying, restart Superset and test the export. Let me know if you 
hit any issues!
   
   
   <!-- 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/b1f2a247-76c1-4262-829e-18fe6ab711ca?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/b1f2a247-76c1-4262-829e-18fe6ab711ca?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/b1f2a247-76c1-4262-829e-18fe6ab711ca?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/b1f2a247-76c1-4262-829e-18fe6ab711ca?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/b1f2a247-76c1
 
-4262-829e-18fe6ab711ca?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/b1f2a247-76c1-4262-829e-18fe6ab711ca?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/b1f2a247-76c1-4262-829e-18fe6ab711ca?feedback_type=other&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-other)</sup>
   
   [![Chat with 
Dosu](https://dosu.dev/dosu-chat-badge.svg)](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)&nbsp;[![Open
 in 
Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=Here%27s%20how%20to%20modify%20%5B%60superset/utils/excel.py%60%5D%28https%3A//github.com/apache/superset/blob/829e4d92d91ceae4b43b1ed3b063ffe45377799c/superset/utils/excel.py%23L43-L53%29%20to%20hardcode%20Spanish%20number%20formatting%3A%0A%0A%2A%2ACurrent%20code%20%28lines%2043-53%29%3A%2A%2A%0A%60%60%60python%0Adef%20df_to_excel%28df%3A%20pd.DataFrame%2C%20%2A%2Akwargs%3A%20Any%29%20-%3E%20Any%3A%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%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%20return
 
%20output.getvalue%28%29%0A%60%60%60%0A%0A%2A%2AReplace%20with%3A%2A%2A%0A%60%60%60python%0Adef%20df_to_excel%28df%3A%20pd.DataFrame%2C%20%2A%2Akwargs%3A%20Any%29%20-%3E%20Any%3A%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%20%23%20Access%20xlsxwriter%20objects%20for%20custom%20formatting%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%27Sheet1%27%5D%0A%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%23%20Spanish%20format%3A%20period%20for%20thousands%2C%20comma%20for%20decimal%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%20%23%20Apply%20to%20numeric%20columns%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%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%20%23%20%2B1%20offset%20because%20pandas%20writes%20index%20as%20first%20column%20by%20default%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%20works
 
heet.set_column%28f%27%7Bcol_letter%7D%3A%7Bcol_letter%7D%27%2C%20None%2C%20spanish_format%29%0A%20%20%20%20%0A%20%20%20%20return%20output.getvalue%28%29%0A%60%60%60%0A%0A%2A%2AKey%20points%3A%2A%2A%0A-%20The%20format%20string%20%60%27%23.%23%230%2C00%27%60%20uses%20period%20for%20thousands%20and%20comma%20for%20decimals%20%28Spanish%20style%29%0A-%20Access%20the%20workbook/worksheet%20%2A%2Aafter%2A%2A%20%60df.to_excel%28%29%60%20writes%20the%20data%0A-%20The%20%60%2B1%60%20offset%20accounts%20for%20pandas%20writing%20the%20DataFrame%20index%20as%20column%20A%20by%20default%0A%0AAfter%20modifying%2C%20restart%20Superset%20and%20test%20the%20export.%20Let%20me%20know%20if%20you%20hit%20any%20issues%21)&nbsp;[![Join
 
Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord)&nbsp;[![Share
 on X](https://img.shields.io/badge/X-shar
 
e-black)](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]

Reply via email to