我正在用python编写脚本,该脚本允许我加载excel文档并输出具有正确数据的XML文档。
我已经完成了一半以上的工作,可以将数据写入XML,但是我不确定100%如何解决该问题,因为我正在努力从xlsx文档中选择正确的数据转换为XML ,我是python的新手,这是我使用python的第二周,所以我是菜鸟。
from openpyxl import load_workbook
import xml.etree.cElementTree as ET
def read_xlsx:
filename="test.xlsx"
book = load_workbook(filename)
print(book)
sh = book.active
row = sh.max_row
col = sh.max_column
data = []
for i in range(1, row + 1):
for j in range(1, col + 1):
c = sh.cell(row=i, column=j)
data.append(c.value)
def convert_cells(data):
return data[0], data[1], data[2], data[3], data[4], data[5], data[6], data[7], data[8], data[9]
str1 = ('\n'.join(str(e) for e in data))
#this is how i store data from Excel
<context>
<name>Example</name>
<message>
<source>Example</source>
<translation-GBR_en-GB>Example</translation-GBR_en-GB>
<translation-AUT_de-AT>Example.</translation-AUT_de-AT>
<translation-BEL_nl-BE>Example</translation-BEL_nl-BE>
<translation-CHE_de-CH>Example.</translation-CHE_de-CH>
<translation-CHE_fr-CH>Example</translation-CHE_fr-CH>
<translation-CHE_it-CH>Example</translation-CHE_it-CH>
<translation-CI_zh-Hant>Example</translation-CI_zh-Hant>
<translation-CZE_cs-CZ>Example</translation-CZE_cs-CZ>
<translation-DEU_de-DE>Example</translation-DEU_de-DE>
<translation-DNK_da-DK>Example</translation-DNK_da-DK>
<translation-ESP_es-ES>Example</translation-ESP_es-ES>
<translation-FIN_fi-FI>Example</translation-FIN_fi-FI>
<translation-FRA_fr-FR>Example</translation-FRA_fr-FR>
<translation-HUN_hu-HU>Example</translation-HUN_hu-HU>
<translation-ITA_it-IT>Example</translation-ITA_it-IT>
<translation-KOR_ko-KR>Example</translation-KOR_ko-KR>
<translation-NLD_nl-NL>Example</translation-NLD_nl-NL>
<translation-NOR_nb-NO>Example</translation-NOR_nb-NO>
<translation-POL_pl-PL>Example</translation-POL_pl-PL>
<translation-PRT_pt-PT>Example</translation-PRT_pt-PT>
<translation-RUS_ru-RU>Example</translation-RUS_ru-RU>
<translation-SVK_sk-SK>Example</translation-SVK_sk-SK>
<translation-SWE_sv-SE>Example</translation-SWE_sv-SE>
<translation-TRK_tk-TK>Example</translation-TRK_tk-TK>
</message>
<message>