xlsxwriter

xlsxwriter: is there a way to open an existing worksheet in my workbook?

匿名 (未验证) 提交于 2019-12-03 02:13:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm able to open my pre-existing workbook, but I don't see any way to open pre-existing worksheets within that workbook. Is there any way to do this? 回答1: You cannot append to an existing xlsx file with xlsxwriter . There is a module called openpyxl which allows you to read and write to preexisting excel file, but I am sure that the method to do so involves reading from the excel file, storing all the information somehow (database or arrays), and then rewriting when you call workbook.close() which will then write all of the information to

Saving list of many python variables into excel sheet while simultaneously keeping variable types defined?

我是研究僧i 提交于 2019-12-03 01:44:49
It's possible with xlsxwriter to save variables to existing excel files and read them after, though the problem is that the variables are stored as strings in my excel file. Let's say I have a list of many different variables with various types (pd.datetimerange, pd.df, np.arrays, etc.), if I save them to the excel file the variable type would be lost. Also the Python script is called from my Excel file so I can't change anything in it without writing a VBA script. Which would temporarily close my workbook, dump the chars (with say pickle strings) and reopen it. Is it possible to retrieve the

xlsxwriter写入Excel文件

匿名 (未验证) 提交于 2019-12-03 00:14:01
#coding=utf-8 import xlsxwriter #加载包 myWorkbook = xlsxwriter . Workbook ( opath + '/' + file_realname + '_pre.xlsx' )#在路径下创建一个 excel 文件 sheet_file_realname = myWorkbook . add_worksheet ( file_realname_new )#在文件中创建一个名为 file_realname_new 的 sheet ,不加名字默认为 sheet1 bold = myWorkbook . add_format ({ 'bold' : True })#设置一个加粗的格式对象---单元格格式## 其他格式# workfomat = workbook . add_format ({# 'bold' : True , #字体加粗# 'border' : 1, #单元格边框宽度# 'align' : 'center', #对齐方式# 'valign' : 'vcenter', #字体对齐方式# 'fg_color' : '#F4B084', #单元格背景颜色# })para_1 = 10para_2 = 20sheet_file_realname.write(0, 0, para_1, bold) #写入方式一

Python合并多个Excel数据

匿名 (未验证) 提交于 2019-12-02 22:56:40
安装模块 pip install xlrd pip install XlsxWriter XlsxWriter示例 1 import xlsxwriter 2 3 # 创建一个工作簿并添加一个工作表 4 workbook = xlsxwriter . Workbook ( " demo.xlsx " ) 5 worksheet = workbook . add_worksheet () 6 7 # 设置列宽 8 worksheet . set_column ( " A:A " , 20 ) 9 10 # 设置格式 11 bold = workbook . add_format ({ " bold " : True }) 12 13 # 设置单元格的值 14 worksheet . write ( " A1 " , " Hello " ) 15 16 # 带格式的单元格 17 worksheet . write ( " A2 " , " World " ) 18 19 # 写一些数字,用行列标识 20 worksheet . write ( 2 , 0 , 123 ) 21 worksheet . write ( 3 , 0 , 123.456 , bold ) 22 23 # 插入一张图片 24 worksheet . insert_image ( " B5 " , " C:

Python Excel文件的读写操作(xlwt xlrd xlsxwriter)

允我心安 提交于 2019-12-02 09:13:49
转: https://www.cnblogs.com/ultimateWorld/p/8309197.html Python语法简洁清晰,作为工作中常用的开发语言还是很强大的(废话)。 python关于Excel的操作提供了xlwt和xlrd两个的包作为针对Excel通用操作的支持,跨平台(Mac、Windows均可)。 xlrdxlrd目前支持读写xlsx(2007版)与xls(2003版),简单的说明如下: import xlrd def open_excel(file='test.xls'): try: data = xlrd.open_workbook(file) # 通过索引获取工作表 sheet1 = data.sheets()[0] # 通过名称获取工作表 sheet1 = data.sheet_by_name(u'sheet1') # 获取table对象,根据table进行该工作表相关数据的读取 # 获取行列 row = sheet1.nrows col = sheet1.ncols # 获取单元格的值 cell_value = sheet1.cell(0, 1).value # 行列表数据 for i in range(row): print sheet1.row_values(i) # 数据写入 # 单元格类型 0 empty,1 string, 2

xlsxwriter写入Excel文件

ぐ巨炮叔叔 提交于 2019-12-01 08:37:49
#coding=utf-8 import xlsxwriter #加载包 myWorkbook = xlsxwriter.Workbook(opath+'/'+file_realname+'_pre.xlsx')#在路径下创建一个excel文件sheet_file_realname = myWorkbook.add_worksheet(file_realname_new)#在文件中创建一个名为file_realname_new的sheet,不加名字默认为sheet1 bold= myWorkbook.add_format({'bold':True})#设置一个加粗的格式对象---单元格格式## 其他格式# workfomat = workbook.add_format({# 'bold' : True, #字体加粗# 'border' : 1, #单元格边框宽度# 'align' : 'center', #对齐方式# 'valign' : 'vcenter', #字体对齐方式# 'fg_color' : '#F4B084', #单元格背景颜色# })para_1 = 10para_2 = 20sheet_file_realname.write(0, 0, para_1, bold) #写入方式一,也可采用循环写入sheet_file_realname.write(0, 1,

DateTime issues in django xlsxwriter

微笑、不失礼 提交于 2019-12-01 08:20:08
I am trying to create an export to excel functionality in my django view as follows: def export_myreport(request, sd, ed): from xlsxwriter.workbook import Workbook import cStringIO as StringIO from django.utils.encoding import smart_str # create a workbook in memory output = StringIO.StringIO() wb = Workbook(output) bg = wb.add_format({'bg_color': '#9CB640', 'font_color': 'black'}) bg2 = wb.add_format({'bg_color': '#FFFFFF', 'font_color': 'black'}) ws = wb.add_worksheet('My Report') row_num = 0 summary = MyModel.objects.filter(time__range = (sd, ed)).select_related() row_num += 2 row = [ smart

Merging Excel cells using Xlsxwriter in Python

六眼飞鱼酱① 提交于 2019-11-30 22:17:29
I want to merge several series of cell ranges in an Excel file using Python Xlsxwriter, I found the Python command in the Xlsxwriter documentation in this website http://xlsxwriter.readthedocs.org/en/latest/example_merge1.html as below: worksheet.merge_range('B4:D4') The only problem is that I have my ranges in row and columns numbers format for example (0,0) which is equal to A1. But Xlsxwriter seems to only accept format like A1. I was wondering if anybody else had the same problem and if there is any solution for that. Almost all methods in XlsxWriter support both A1 and (row, col) notation

Applying formatting row by row in addition to column formatting with xlsxwriter

夙愿已清 提交于 2019-11-30 16:04:39
问题 I am formatting all of my columns in an excel file using the xlsxwriter module: def to_excel(video_report, feed): # Create a Pandas Excel writer using XlsxWriter as the engine. writer = pd.ExcelWriter('daily_report.xlsx', engine='xlsxwriter') # Convert the dataframe to an XlsxWriter Excel object. video_report.to_excel(writer, sheet_name='Video Overview', na_rep="-") # Get the xlsxwriter objects from the dataframe writer object. workbook = writer.book worksheet = writer.sheets['Video Overview'

Applying formatting row by row in addition to column formatting with xlsxwriter

烈酒焚心 提交于 2019-11-30 15:54:30
I am formatting all of my columns in an excel file using the xlsxwriter module: def to_excel(video_report, feed): # Create a Pandas Excel writer using XlsxWriter as the engine. writer = pd.ExcelWriter('daily_report.xlsx', engine='xlsxwriter') # Convert the dataframe to an XlsxWriter Excel object. video_report.to_excel(writer, sheet_name='Video Overview', na_rep="-") # Get the xlsxwriter objects from the dataframe writer object. workbook = writer.book worksheet = writer.sheets['Video Overview'] # Add some cell formats. integer = workbook.add_format({'num_format': '0', 'align': 'center'})