环境配置
VSCode && python环境搭建
安装Python
官网下载地址:https://www.python.org/ftp/python/3.8.0/python-3.8.0-amd64.exe
双击打开.exe文件
勾选 Add Python 3.8 to Path选项,然后点击install now即可安装。
测试python是否安装完成
按键盘win+r,在左下角运行窗口里输入cmd,回车。
输入python --version 有版本号出现即可
(以上文章内容是偷的,来自:https://blog.csdn.net/weixin_43737995/article/details/125690015)
安装python的表格库
按键盘win+r,在左下角运行窗口里输入cmd,回车。
输入pip install xlrd 安装完毕后 pip install xlwt(可以试试pip install xlrd xlwt)
耐心等待
安装VSCode
官网下载地址:https://code.visualstudio.com/download
下载python插件
就一个python就行
前往settings(左下角manage->settings)
打开JSON,在你原有的基础上加入以下内容
"python.languageServer": "Pylance",
"[python]": {
"editor.formatOnType": true,
},
"code-runner.executorMap":{
"python":"set PYTHONIOENCODING=utf8 && python"
},
读写wps表格
import xlrd
import xlwt
i = 0
new_excel = []
filename = r'2024.04.08-2024.04.13.xlsx'
f_txt = open("client.txt","w",encoding='utf-8') #打开txt文件 f_txt来操作
xlsx_object = xlrd.open_workbook(filename,encoding_override='gb2312') #打开wps文件 xlsx_object来操作
sheet1 = xlsx_object.sheet_by_index(1) #获取第二个表 要第一个的话取0
excel_title = sheet1.row_values(2) #获取第二行数据(我这里第二行是标题)
client_col = excel_title.index("客户") #获取标题中客户所在序号
lst_client_col = sheet1.col_values(client_col) #获取客户列的数据
for client in lst_client_col:
if(client == "CHINA"): #客户匹配就写出txt 存入new_excel
new_excel.append(sheet1.row_values(i))
f_txt.write(str(i) +str(sheet1.row_values(i)) + '\n')
i = i + 1
print(sheet1.cell_value(3,client_col))
f_txt.close() #关txt文件
遇到的问题
- 1、VSCode print 中文乱码 解决方式:在设置中加入
"code-runner.executorMap":{
"python":"set PYTHONIOENCODING=utf8 && python"
},