当前位置:网站首页>Basic operations of xlrd and xlsxwriter
Basic operations of xlrd and xlsxwriter
2022-08-10 00:12:00 【Chandler_river】
import xlrd as xldata = xl.open_workbook("hypothetical data 0.xls")#Number of sheets in the workbookwork_sheets = data.nsheets#Name string of all tables in list formwork_names = data.sheet_names()#Get specific worksheet three wayssheet_index = 1work_sheet = data.sheets()[sheet_index]work_sheet = data.sheet_by_index(sheet_index)sheet_name = "Sheet2"work_sheet = data.sheet_by_name(sheet_name)#Check if the worksheet is importedcheck = data.sheet_loaded(sheet_name)check = data.sheet_loaded(sheet_index)#Get the worksheet namesheet_name = work_sheet.name#Get the number of valid rows/columns in the worksheetall_rows = work_sheet.nrows#Get a list of all cell objects in the specified rowrow_object = work_sheet.row(5)row_object2 = work_sheet.row_values(5)# cell data type#0:empty#1: text#2:number#3: date#4: boolean#5:errorrow_type = work_sheet.row_types(5)#Get the length of the valid cells in the specified rowrow_length = work_sheet.row_len(5)#get generator for all rows of worksheetrows_generator = work_sheet.get_rows()#Get the contents of the specified cellrowx = 1colx = 1cell_object = work_sheet.cell(rowx,colx)cell_value = work_sheet.cell_value(rowx,colx)cell_value2 = cell_object.value#read date#The date in excel is the number of days relative to the base time 1900-01-01 as the starting point (1)# Dates in Python are generally based on itcol_content = work_sheet.col_values(4)col_type = work_sheet.col_types(4)#0 means 1900-01-01 1 means 1904-01-01date_cell = xl.xldate_as_tuple(work_sheet.cell_value(4,4),0)date_cell = xl.xldate_as_datetime(work_sheet.cell_value(4,4),0)import xlsxwriter as xls#Create workbookworkbook = xls.Workbook("new_excel.xlsx")#Create worksheetworksheet = workbook.add_worksheet("sheet1")#data inputheadings = ["Number","testA","testB"]data = [[1,1,1],[2,2,2],[3,4,5],[5,6,7]]worksheet.write_row("A1",headings)worksheet.write_column("A2",data[0])worksheet.write_column("B2",data[1])worksheet.write_column("C2",data[2])#set the format of the cellworkfomat = workbook.add_format()workfomat.set_bold(1) #Set the border width to 1workfomat.set_num_format("0.00") #Format data to two decimal placesworkfomat.set_align("center") #alignmentworkfomat.set_fg_color("blue") #Set the background color#Merge Cellsworksheet.merge_range("D1:D7","What needs to be written in the cell")#change cell widthworksheet.set_column("D:E",30)#insert imageworksheet.insert_image("E1","absolute path")
边栏推荐
- Sun Zhengyi lost 150 billion: it was expensive at the beginning
- chart.js面积图曲线图统计插件
- R语言使用mean函数计算样本(观测)数据中指定变量的相对频数:计算时间序列数据中大于前一个观测值的观测值所占的比例总体的比例
- C 在函数声明前加typedef
- 量化交易接口系统有哪些稳定性?
- xlrd 与 xlsxwritter 的基本操作
- 【Apifox】为什么如此受青睐,此篇文章和大家分享
- D. Binary String To Subsequences
- MySQL——JDBC
- Install win7 virtual machine in Vmware and related simple knowledge
猜你喜欢
leetcode:323. 无向图中连通分量的数目
Qt 消息机制和事件
用PLSQL导出Oracle一个表
“我“是一名测试/开发程序员,小孙的内心独白......
Chatting embarrassing scenes, have you encountered it?Teach you to get the Doutu emoticon package with one click, and become a chat expert
17-GuliMall 搭建虚拟域名访问环境
Evolution of MLOps
月薪5K的运维小白如何成为月薪5W的高级架构师?
Flask's routing (app.route) detailed
Liver all night to write a thirty thousand - word all the commands the SQL database, function, speaks clearly explain operators, content is rich, proposal collection + 3 even high praise!
随机推荐
2022-8-9 第六组 输入输出流
JuiceFS 在多云存储架构中的应用 | 深势科技分享
Rust dereference
Common commands and technical function modules of Metasploit
leetcode:332. 重新安排行程
开发者必备:一文快速熟记【数据库系统】和【软件开发模型】常用知识点
C. Omkar and Baseball
Presto Event Listener开发
R语言将列表数据转化为向量数据(使用unlist函数将列表数据转化为向量数据)
Qt 消息机制和事件
R语言使用mean函数计算样本(观测)数据中指定变量的相对频数:计算时间序列数据中大于前一个观测值的观测值所占的比例总体的比例
Janus官方DEMO介绍
Arcgis工具箱无法使用,显示“XML包含错误“的解决方法
shell数组
three.js镂空圆球拖拽变形js特效
Five Star Holdings Wang Jianguo: Deepen the track with "plant spirit" and promote growth with "animal spirit"
OSS文件上传
xctf攻防世界 Web高手进阶区 shrine
第十七期八股文巴拉巴拉说(数据库篇)
关于ETL的两种架构(ETL架构和ELT架构)