当前位置:网站首页>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")
边栏推荐
猜你喜欢
随机推荐
xctf攻防世界 Web高手进阶区 ics-05
JS中表单操作、addEventListener事件监听器
Analyze the Add() method in Fragment management from the source code
力扣 1413. 逐步求和得到正数的最小值
JuiceFS 在多云存储架构中的应用 | 深势科技分享
R语言拟合ARIMA模型并使用拟合模型进行预测推理:使用forecast函数计算ARIMA模型未来值(包含时间点、预测值、两个置信区间)
请讲一讲JS中的 for...in 与 for...of (上)
[Microservice~Nacos] Configuration Center of Nacos
c:forEach varStatus属性
电脑系统重装后怎么用打印机扫描出文件?
Janus官方DEMO介绍
leetcode:319. 灯泡开关
Bi Sheng Compiler Optimization: Lazy Code Motion
2022年中国第三方证券APP创新专题分析
HUAWEI CLOUD escorts the whole process of "Wandering Ark" for the first time, creating a popular brand
HBuilder X 不能运行到内置终端
第十七期八股文巴拉巴拉说(数据库篇)
How to insist to use procedural system?
第 1 章 一大波数正在靠近——排序
leetcode 38. 外观数列