Автоматизировать свойства ячейки нескольких файлов Excel - PullRequest
0 голосов
/ 17 июня 2019

У меня есть около 100 файлов Excel, в которых столбцы K и L представлены в виде чисел с плавающей запятой, например 0,5677.Я хочу представить эти столбцы в процентах, в данном случае 56,8%.Есть ли способ, которым я могу автоматизировать это?Очевидно, я могу отрегулировать столбцы вручную, но это отнимает много времени.

У меня нет опыта работы с Macro или VBA.

Любая помощь будет принята с благодарностью.

С уважением, М.

1 Ответ

0 голосов
/ 17 июня 2019

Я нашел полезный способ сделать это, используя Python Pandas.В моем случае Pandas также является источником файлов Excel.

import pandas as pd

# Create a Pandas dataframe from some data.
df = pd.DataFrame({'Numbers':    [1010, 2020, 3030, 2020, 1515, 3030, 4545],
                   'Percentage': [.1,   .2,   .33,  .25,  .5,   .75,  .45 ],
})

# Create a Pandas Excel writer using XlsxWriter as the engine.
writer = pd.ExcelWriter("pandas_column_formats.xlsx", engine='xlsxwriter')

# Convert the dataframe to an XlsxWriter Excel object.
df.to_excel(writer, sheet_name='Sheet1')

# Get the xlsxwriter workbook and worksheet objects.
workbook  = writer.book
worksheet = writer.sheets['Sheet1']

# Add some cell formats.
format1 = workbook.add_format({'num_format': '#,##0.00'})
format2 = workbook.add_format({'num_format': '0%'})

# Note: It isn't possible to format any cells that already have a format such
# as the index or headers or any cells that contain dates or datetimes.

# Set the column width and format.
worksheet.set_column('B:B', 18, format1)

# Set the format but not the column width.
worksheet.set_column('C:C', None, format2)

# Close the Pandas Excel writer and output the Excel file.
writer.save()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...