当前位置:网站首页>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")
边栏推荐
- Janus Official DEMO Introduction
- 第十七期八股文巴拉巴拉说(数据库篇)
- PyQt5: Getting Started Tutorial
- HBuilder X 不能运行到内置终端
- 信息系统项目管理师---第十一章项目风险管理历年考题
- What is the stability of the quantitative trading interface system?
- 关于ETL的两种架构(ETL架构和ELT架构)
- R语言将列表数据转化为向量数据(使用unlist函数将列表数据转化为向量数据)
- 17-GuliMall 搭建虚拟域名访问环境
- R语言ggplot2可视化:使用ggpubr包的ggerrorplot函数可视化误差线(可视化不同水平均值点以及se标准误差)、设置add参数为dotplot添加点阵图
猜你喜欢
随机推荐
README_Albumentations
PyQt5: Getting Started Tutorial
力扣 1413. 逐步求和得到正数的最小值
【Apifox】为什么如此受青睐,此篇文章和大家分享
17-GuliMall 搭建虚拟域名访问环境
CGLIB源码易懂解析
R语言使用mean函数计算样本(观测)数据中指定变量的相对频数:计算时间序列数据中大于前一个观测值的观测值所占的比例总体的比例
Socket发送缓冲区接收缓冲区快问快答
The 2022-8-9 sixth group of input and output streams
c:forEach varStatus属性
three.js镂空圆球拖拽变形js特效
Analyses the development status quo of stock trading
开发者必备:一文快速熟记【数据库系统】和【软件开发模型】常用知识点
leetcode:319. 灯泡开关
【服务器数据恢复】SAN LUN映射出错导致文件系统数据丢失的数据恢复案例
Bi Sheng Compiler Optimization: Lazy Code Motion
ArrayList 和 LinkedList 区别
Core Data浅谈系列之五 : 在UITableView中展示
C. Mere Array
工作经验-组件封装(拖拽排序组件)