ExcelWriter openpyxl add Multiple Namespace

44 Views Asked by At

How to add multiple namespace when creating a excel file using pandas

I am using the below code to generate excel file. This Excel file will be fed to AWS Translate function, which will accept only utf-8 encoded files

df = pd.read_csv(download_path, encoding='utf-8')
    
    
    with pd.ExcelWriter(xlsx_path, engine='openpyxl' ) as writer:
        df.to_excel(writer, index=False)

This works fine creates an excel file. But i am not sure if this excel is utf-8. So i checked the Sheet1.xml It only has one namespace

<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">

But when i save as the same excel file manually and select encoding using web options, i get the following namespaces. And AWS Translate service uses this without any issues

<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" xmlns:xr="http://schemas.microsoft.com/office/spreadsheetml/2014/revision" xmlns:xr2="http://schemas.microsoft.com/office/spreadsheetml/2015/revision2"  mc:Ignorable="x14ac xr xr2 xr3" >

Is there a way i can produce these namespaces using ExcelWriter and openpyxl engine

0

There are 0 best solutions below