小编jmc*_*ara的帖子

使用Pandas将工作表添加到现有的Excel文件中

# Set the working folder to the same folder as the script
os.chdir(os.path.dirname(os.path.abspath(__file__)))

test = send_request().content
df = pd.read_csv(io.StringIO(test.decode('utf-8')))
writer = pd.ExcelWriter('NHL_STATS_JSB_final.xlsx', \
                        engine = 'xlsxwriter')
df.to_excel(writer, 'Player statistics', index=False)
writer.save()
Run Code Online (Sandbox Code Playgroud)

我不明白为什么,但是我正在尝试将工作表添加Player statistics到当前NHL_STATS_JSB_final.xlsx文件中,但是无法正常工作。我的代码没有将工作表添加到文件中,而是使用当前文件并擦除所有先前的工作表以添加新的工作表。

如何Player statistics删除所有其他工作表添加到当前的Excel文件中?

python excel pandas

4
推荐指数
2
解决办法
4647
查看次数

如何在 xlsxwriter Python 中的数据验证中添加超过 255 个字符

我正在创建一个 Excel 工作表,我必须在其中下拉显示所有州。代码如下所示:

excel_file_dir = os.path.join(os.path.dirname(__file__), 'template')
name = 'Template.xlsx'
excel_file = os.path.join(os.path.dirname(__file__), 'template', name)
workbook = xlsxwriter.Workbook(excel_file)
sheet = workbook.add_worksheet("Details")

sheet.write("C1", "Address", style_center)
sheet.write("D1", "State", style_center)

sheet.data_validation(1, 3, 5000, 3, {'validate': 'list', 'source': ["Alabama-AL", "Alaska-AK", "Arizona-AZ", "Arkansas-AR", "California-CA", "Colorado-CO", "Connecticut-CT",
                                              "Delaware-DE", "District of Columbia-DC", "Florida-FL", "Georgia-GA", "Hawaii-HI", "Idaho-ID", "Illinois-IL", "Indiana-IN",
                                              "Iowa-IA", "Kansas-KS", "Louisiana-LA", "Maine-ME", "Maryland-MD", "Massachusetts-MA", "Michigan-MI", "Minnesota-MN", "Mississippi-MS",
                                              "Missouri-MO", "Montana-MT", "Nebraska-NE", "Nevada-NV", "New Hampshire-NH", "New Jersey-NZ", "New Mexico-NM", "New York-NY",
                                              "North Carolina-NC", "North Dakota", "Ohio", "Oklahoma-OK", "Oregon-OR", "Pennsylvania-PA", …
Run Code Online (Sandbox Code Playgroud)

python excel xlsxwriter

4
推荐指数
1
解决办法
3253
查看次数

使用 python 中 xlsxwriter 的 data_validation() 方法中的 validate 作为列表从源设置默认值?

我使用 python 中的xlsxwriter模块创建了一个 Excel 工作表。我试图为使用 xlsxwriter 的 data_validation() 方法创建的下拉列表设置默认值。
但是,根据xlsxwriter的文档,如果我们使用validate as list,它没有默认值。

sheet.data_validation('G5', {'validate': 'list',
                             'source': ['Completed',
                                        'Pending',
                                        'Script Error']})
Run Code Online (Sandbox Code Playgroud)

谁能建议我一些解决办法,在同一单元格中设置默认值和下拉列表?

python excel python-module python-3.x xlsxwriter

3
推荐指数
1
解决办法
2751
查看次数

pandas ExcelWriter 从右到左写入工作表方向

我在 python Django 中创建下载的动态 Excel 文件(未存储在本地),我需要使工作表从右到左而不是从左到右显示。

这是我使用的代码:


import pandas
from io import BytesIO, StringIO

sio = BytesIO()

PandasDataFrame = pandas.DataFrame([['t1', 't2'], ['t3', 't4']], index = ['t1', 't2'], columns = ['t11', 't1']  )

PandasWriter = pandas.ExcelWriter(sio, engine='xlsxwriter')



PandasDataFrame.to_excel(PandasWriter, sheet_name='Sheet1')

PandasWriter.book.add_format({'reading_order': 2})

PandasWriter.save()

PandasWriter.close()

sio.seek(0)

workbook = sio.read()

response = HttpResponse(workbook,content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')

response['Content-Disposition'] = 'attachment; filename=wrong_data.xlsx'

return (response)

Run Code Online (Sandbox Code Playgroud)

python pandas

2
推荐指数
1
解决办法
688
查看次数

如何在xlsxWriter中从数字单元格地址获取Excell格式python

导入 xlsxwriter

我有像

Ex1: form1 = worksheet.write(0, 0, 'Foo', format)

像这样的“A1”的实际地址。

像 Ex2:form2 = worksheet.write(8, 27 'Foo', format)

单元格地址为AB8

如何从数字中获取“A1”和“AB8”等值。xlsxwriter 中是否有任何函数或必须编写任何逻辑。

因为如果我们给予

工作表。write_formula (row_Number, Col_Num+1,'{=SUM(row_number,Col_Num-len(issueList)+1,row_Number,Col_Num)}')/

而是进行求和'{=SUM(row_number,Col_Num-len(issueList)+1,row_Number,Col_Num)}' .only 正在打印的文本。

提前致谢。

python excel xlsxwriter

1
推荐指数
1
解决办法
1859
查看次数

标签 统计

python ×5

excel ×4

xlsxwriter ×3

pandas ×2

python-3.x ×1

python-module ×1