当前位置:网站首页>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")边栏推荐
- 干涉BGP的选路---社团属性
- charts.js插件实现的散点图样式
- 华为云全流程护航《流浪方舟》破竹首发,打造口碑爆款
- Analyses the development status quo of stock trading
- Leetcode.25 K个一组翻转链表(模拟/递归)
- 大型分布式存储方案MinIO介绍,看完你就懂了!
- typedef和#define的花里胡哨的用法
- EasyExcel使用
- R语言使用mean函数计算样本(观测)数据中指定变量的相对频数:计算时间序列数据中大于前一个观测值的观测值所占的比例总体的比例
- Users should clearly know that quantitative trading is not a simple procedure
猜你喜欢
随机推荐
用户要清晰知道,量化交易并非简单的程序
D. Binary String To Subsequences
Under the NVM node installation;The node environment variable configuration
UNI-APP_ monitor page scroll h5 monitor page scroll
制定量化交易策略的基本步骤有哪些?
基于ABP的AppUser对象扩展
浅析量股票化交易的发展现状
十步以内,用小程序快速生成App!
JS中表单操作、addEventListener事件监听器
(转)FreeType字体位图属性
R语言拟合ARIMA模型并使用拟合模型进行预测推理:使用forecast函数计算ARIMA模型未来值(包含时间点、预测值、两个置信区间)
PyQt5: Getting Started Tutorial
leetcode:320.列举单词的全部缩写
Bi Sheng Compiler Optimization: Lazy Code Motion
HUAWEI CLOUD escorts the whole process of "Wandering Ark" for the first time, creating a popular brand
Good future, want to be a second new Oriental
Leetcode.25 K个一组翻转链表(模拟/递归)
leetcode:325. 和等于k的最长子数组长度
2022-8-9 第六组 输入输出流
leetcode:286.墙和门









