{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "vscode": { "languageId": "plaintext" } }, "outputs": [], "source": [ "import requests\n", "import json\n", "import xlrd\n", "import xlwt\n", "from datetime import datetime, timedelta \n", "import time\n", "import pandas as pd\n", "pd.set_option('display.max_columns', None)\n", "\n", "import numpy as np\n", "# 变量定义\n", "login_url = \"http://10.200.32.39/jingbo-api/api/server/login\"\n", "search_url = \"http://10.200.32.39/jingbo-api/api/warehouse/dwDataItem/queryByItemNos\"\n", "upload_url = \"http://10.200.32.39/jingbo-api/api/dw/dataValue/pushDataValueList\"\n", "\n", "\n", "login_data = {\n", " \"data\": {\n", " \"account\": \"api_dev\",\n", " \"password\": \"ZTEwYWRjMzk0OWJhNTlhYmJlNTZlMDU3ZjIwZjg4M2U=\",\n", " \"tenantHashCode\": \"8a4577dbd919675758d57999a1e891fe\",\n", " \"terminal\": \"API\"\n", " },\n", " \"funcModule\": \"API\",\n", " \"funcOperation\": \"获取token\"\n", "}\n", "\n", "\n", "read_file_path_name = \"定性模型数据项12-11.xls\"\n", "one_cols = []\n", "two_cols = []\n", "\n", "\n", "def update_e_value(file_path, column_index, threshold):\n", " \"\"\"\n", " 数据修正需求:2025年1月8日\n", " 如果如果今天的成本即期价跟昨天的成本价差正负1000以上,就按照昨天的成本价计算\n", "\n", " 更新Excel文件中指定列的值,如果新值与前一天的值变化大于阈值,则将新值改为前一天的值。\n", "\n", " :param file_path: Excel文件路径\n", " :param column_index: 需要更新的列索引\n", " :param threshold: 变化阈值\n", " \"\"\"\n", " # 读取Excel文件\n", " try:\n", " df = pd.read_excel(file_path, engine='openpyxl')\n", " except:\n", " df = pd.read_excel(file_path, engine='xlrd')\n", " # 所有列列统一数据格式为float\n", " df = df.applymap(lambda x: float(x) if isinstance(x, (int, float)) else x)\n", " \n", " print(df.tail())\n", " # 填充缺失值\n", " df = df.fillna(method='ffill')\n", "\n", " # 获取最后两行数据\n", " df1 = df.tail(2)\n", " print(df1)\n", " # 获取前一天的指定列值\n", " previous_value = df1.iloc[0, column_index]\n", " print(previous_value,type(previous_value))\n", " # 获取当前的指定列值\n", " current_value = df1.iloc[1, column_index]\n", " print(current_value,type(current_value))\n", " # 判断指定列值的变化是否大于阈值\n", " if abs(current_value - previous_value) > threshold:\n", " # 如果变化大于阈值,将当前的指定列值改为前一天的值\n", " df.iloc[-1, column_index] = previous_value\n", " print('修改了')\n", " print(df.tail())\n", " # 将修改后的数据写回Excel文件\n", " df.to_excel(file_path, index=False,engine='openpyxl')\n", "\n", "def getLogToken():\n", " login_res = requests.post(url=login_url, json=login_data, timeout=(3, 5))\n", " text = json.loads(login_res.text)\n", " if text[\"status\"]:\n", " token = text[\"data\"][\"accessToken\"]\n", " else:\n", " print(\"获取认证失败\")\n", " token = None\n", " return token\n", "\n", "def updateExcelData(date='',token=None):\n", " workbook = xlrd.open_workbook(read_file_path_name)\n", "\n", " # 选择第一个表格\n", " sheet = workbook.sheet_by_index(0)\n", "\n", " row_data = sheet.row_values(1)\n", " one_cols = row_data\n", "\n", " cur_time,cur_time2 = getNow(date)\n", " search_data = {\n", " \"data\": {\n", " \"date\": cur_time,\n", " \"dataItemNoList\": one_cols[1:]\n", " },\n", " \"funcModule\": \"数据项\",\n", " \"funcOperation\": \"查询\"\n", " }\n", " headers = {\"Authorization\": token}\n", " search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n", " search_value = json.loads(search_res.text)[\"data\"]\n", "# datas = search_value\n", " if search_value:\n", " datas = search_value\n", " else :\n", " datas = None\n", " \n", "\n", " append_rows = [cur_time2]\n", " dataItemNo_dataValue = {}\n", "# for data_value in datas:\n", "# dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for data_value in datas:\n", " if \"dataValue\" not in data_value:\n", " print(data_value)\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n", " else:\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for value in one_cols[1:]:\n", " if value in dataItemNo_dataValue:\n", " append_rows.append(dataItemNo_dataValue[value])\n", " else:\n", " append_rows.append(\"\")\n", "\n", " workbook = xlrd.open_workbook('定性模型数据项12-11.xls')\n", "\n", " # 获取所有sheet的个数\n", " sheet_count = len(workbook.sheet_names())\n", "\n", " # 获取所有sheet的名称\n", " sheet_names = workbook.sheet_names()\n", "\n", " new_workbook = xlwt.Workbook()\n", " for i in range(sheet_count):\n", " # 获取当前sheet\n", " sheet = workbook.sheet_by_index(i)\n", "\n", " # 获取sheet的行数和列数\n", " row_count = sheet.nrows\n", " col_count = sheet.ncols\n", " # 获取原有数据\n", " data = []\n", " for row in range(row_count):\n", " row_data = []\n", " for col in range(col_count):\n", " row_data.append(sheet.cell_value(row, col))\n", " data.append(row_data)\n", " # 创建xlwt的Workbook对象\n", " # 创建sheet\n", " new_sheet = new_workbook.add_sheet(sheet_names[i])\n", "\n", " # 将原有的数据写入新的sheet\n", " for row in range(row_count):\n", " for col in range(col_count):\n", " new_sheet.write(row, col, data[row][col])\n", "\n", " if i == 0:\n", " \n", " # 在新的sheet中添加数据\n", " for col in range(col_count):\n", " new_sheet.write(row_count, col, append_rows[col])\n", "\n", " # 保存新的xls文件\n", " new_workbook.save(\"定性模型数据项12-11.xls\")\n", "\n", "def qualitativeModel():\n", " df = pd.read_excel('定性模型数据项12-11.xls')\n", "\n", " df=df.fillna(df.ffill())\n", " df1 = df[-2:].reset_index()\n", " '''\n", " # if df1.loc[1,'70号沥青开工率'] > 0.3: \n", " 2025年1月8日 修改:\n", " 复盘分析后发现2024-7月开始,开工率数据从0.28 变为了28 ,改为下面的判断规则\n", " '''\n", " if df1.loc[1,'70号沥青开工率'] > 30:\n", " a = (df1.loc[1,'70号沥青开工率']-0.2)*5/0.1\n", " else :\n", " a = 0\n", " b = df1.loc[1,'资金因素']\n", " if df1.loc[1,'昨日计划提货偏差']>0:\n", " c = df1.loc[1,'昨日计划提货偏差']*10/2000\n", " else :\n", " c = df1.loc[1,'昨日计划提货偏差']*10/3000\n", " d = df1.loc[1,'生产情况']\n", " if df1.loc[1,'基质沥青库存']/265007 >0.8:\n", " e = (df1.loc[1,'基质沥青库存'] - df1.loc[0,'基质沥青库存'])*10/-5000\n", " else : \n", " e = 0\n", " f = df1.loc[1,'下游客户价格预期']\n", " if abs(df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])>=100:\n", " g = (df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])*50/100\n", " else :\n", " g = 0\n", " h = df1.loc[1,'订单结构']\n", " x = round(0.08*a+0*b+0.15*c+0.08*d +0.03*e +0.08*f +0.4*g+0.18*h+df1.loc[0,'京博指导价'],2)\n", " return x\n", "\n", "\n", "def getNow(date='',offset=0):\n", " if date == '':\n", " now = datetime.now() - timedelta(days=offset)\n", " else:\n", " date = datetime.strptime(date, \"%Y-%m-%d\")\n", " now = date\n", "\n", " year = now.year\n", " month = now.month\n", " day = now.day\n", "\n", " if month < 10:\n", " month = \"0\" + str(month)\n", " if day < 10:\n", " day = \"0\" + str(day)\n", " cur_time = str(year) + str(month) + str(day)\n", " cur_time2 = str(year) + \"-\" + str(month) + \"-\" + str(day)\n", " return cur_time,cur_time2\n", "\n", "def pushData(cur_time,x,token_push):\n", " data1 = {\n", " \"funcModule\": \"数据表信息列表\",\n", " \"funcOperation\": \"新增\",\n", " \"data\": [\n", " {\"dataItemNo\": \"C01100036|Forecast_Price|DX|ACN\",\n", " \"dataDate\": cur_time,\n", " \"dataStatus\": \"add\",\n", " \"dataValue\": x\n", " }\n", " ]\n", " }\n", " headers1 = {\"Authorization\": token_push}\n", " res = requests.post(url=upload_url, headers=headers1, json=data1, timeout=(3, 5))\n", " \n", "def start_2(date='',token=None):\n", " workbook = xlrd.open_workbook(read_file_path_name)\n", "\n", " # 选择第一个表格\n", " sheet = workbook.sheet_by_index(0)\n", "\n", " # 获取行数和列数\n", " num_rows = sheet.nrows\n", " \n", " row_data = sheet.row_values(1)\n", " one_cols = row_data\n", "\n", " cur_time,cur_time2 = getNow(date)\n", " \n", " \n", " \n", " search_data = {\n", " \"data\": {\n", " \"date\": cur_time,\n", " \"dataItemNoList\": one_cols[1:]\n", " },\n", " \"funcModule\": \"数据项\",\n", " \"funcOperation\": \"查询\"\n", " }\n", " headers = {\"Authorization\": token}\n", " search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n", " search_value = json.loads(search_res.text)[\"data\"]\n", "# datas = search_value\n", " if search_value:\n", " datas = search_value\n", " else :\n", " datas = None\n", " \n", "\n", " append_rows = [cur_time2]\n", " dataItemNo_dataValue = {}\n", "# for data_value in datas:\n", "# dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for data_value in datas:\n", " if \"dataValue\" not in data_value:\n", " print(data_value)\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n", " else:\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for value in one_cols[1:]:\n", " if value in dataItemNo_dataValue:\n", " append_rows.append(dataItemNo_dataValue[value])\n", " else:\n", " append_rows.append(\"\")\n", "\n", " workbook = xlrd.open_workbook('定性模型数据项12-11.xls')\n", "\n", " # 获取所有sheet的个数\n", " sheet_count = len(workbook.sheet_names())\n", "\n", " # 获取所有sheet的名称\n", " sheet_names = workbook.sheet_names()\n", "\n", " new_workbook = xlwt.Workbook()\n", " for i in range(sheet_count):\n", " # 获取当前sheet\n", " sheet = workbook.sheet_by_index(i)\n", "\n", " # 获取sheet的行数和列数\n", " row_count = sheet.nrows\n", " col_count = sheet.ncols\n", " # 获取原有数据\n", " data = []\n", " for row in range(row_count):\n", " row_data = []\n", " for col in range(col_count):\n", " row_data.append(sheet.cell_value(row, col))\n", " data.append(row_data)\n", " # 创建xlwt的Workbook对象\n", " # 创建sheet\n", " new_sheet = new_workbook.add_sheet(sheet_names[i])\n", "\n", " # 将原有的数据写入新的sheet\n", " for row in range(row_count):\n", " for col in range(col_count):\n", " new_sheet.write(row, col, data[row][col])\n", "\n", " if i == 0:\n", " \n", " # 在新的sheet中添加数据\n", " for col in range(col_count):\n", " new_sheet.write(row_count, col, append_rows[col])\n", "\n", " # 保存新的xls文件\n", " new_workbook.save(\"定性模型数据项12-11.xls\")\n", "\n", " update_e_value('定性模型数据项12-11.xls', 8, 1000)\n", "\n", " df = pd.read_excel('定性模型数据项12-11.xls')\n", "\n", " df=df.fillna(df.ffill())\n", " df1 = df[-2:].reset_index()\n", " '''\n", " # if df1.loc[1,'70号沥青开工率'] > 0.3: \n", " 2025年1月8日 修改:\n", " 复盘分析后发现2024-7月开始,开工率数据从0.28 变为了28 ,改为下面的判断规则\n", " '''\n", " if df1.loc[1,'70号沥青开工率'] > 30:\n", " a = (df1.loc[1,'70号沥青开工率']-0.2)*5/0.1\n", " else :\n", " a = 0\n", " b = df1.loc[1,'资金因素']\n", " if df1.loc[1,'昨日计划提货偏差']>0:\n", " c = df1.loc[1,'昨日计划提货偏差']*10/2000\n", " else :\n", " c = df1.loc[1,'昨日计划提货偏差']*10/3000\n", " d = df1.loc[1,'生产情况']\n", " if df1.loc[1,'基质沥青库存']/265007 >0.8:\n", " e = (df1.loc[1,'基质沥青库存'] - df1.loc[0,'基质沥青库存'])*10/-5000\n", " else : \n", " e = 0\n", " f = df1.loc[1,'下游客户价格预期']\n", " if abs(df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])>=100:\n", " g = (df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])*50/100\n", " else :\n", " g = 0\n", " h = df1.loc[1,'订单结构']\n", " x = round(0.08*a+0*b+0.15*c+0.08*d +0.03*e +0.08*f +0.4*g+0.18*h+df1.loc[0,'京博指导价'],2)\n", "\n", " login_res1 = requests.post(url=login_push_url, json=login_push_data, timeout=(3, 5))\n", " text1 = json.loads(login_res1.text)\n", " token_push = text1[\"data\"][\"accessToken\"]\n", "\n", "\n", " data1 = {\n", " \"funcModule\": \"数据表信息列表\",\n", " \"funcOperation\": \"新增\",\n", " \"data\": [\n", " {\"dataItemNo\": \"C01100036|Forecast_Price|DX|ACN\",\n", " \"dataDate\": cur_time,\n", " \"dataStatus\": \"add\",\n", " \"dataValue\": x\n", " }\n", "\n", " ]\n", " }\n", " headers1 = {\"Authorization\": token_push}\n", " # res = requests.post(url=upload_url, headers=headers1, json=data1, timeout=(3, 5))\n", " \n", "\n", "def start():\n", " workbook = xlrd.open_workbook(read_file_path_name)\n", "\n", "\n", "\n", " # 选择第一个表格\n", " sheet = workbook.sheet_by_index(0)\n", "\n", " # 获取行数和列数\n", " num_rows = sheet.nrows\n", "\n", "\n", "\n", " row_data = sheet.row_values(1)\n", " one_cols = row_data\n", "\n", "\n", " login_res = requests.post(url=login_url, json=login_data, timeout=(3, 5))\n", " text = json.loads(login_res.text)\n", " if text[\"status\"]:\n", " token = text[\"data\"][\"accessToken\"]\n", " else:\n", " print(\"获取认证失败\")\n", " token = None\n", "\n", "\n", " now = datetime.now()\n", " year = now.year\n", " month = now.month\n", " day = now.day\n", "\n", " if month < 10:\n", " month = \"0\" + str(month)\n", " if day < 10:\n", " day = \"0\" + str(day)\n", " cur_time = str(year) + str(month) + str(day)\n", " cur_time2 = str(year) + \"-\" + str(month) + \"-\" + str(day)\n", " search_data = {\n", " \"data\": {\n", " \"date\": cur_time,\n", " \"dataItemNoList\": one_cols[1:]\n", " },\n", " \"funcModule\": \"数据项\",\n", " \"funcOperation\": \"查询\"\n", " }\n", " headers = {\"Authorization\": token}\n", " search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n", " search_value = json.loads(search_res.text)[\"data\"]\n", "# datas = search_value\n", " if search_value:\n", " datas = search_value\n", " else :\n", " datas = None\n", " \n", "\n", " append_rows = [cur_time2]\n", " dataItemNo_dataValue = {}\n", "# for data_value in datas:\n", "# dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for data_value in datas:\n", " if \"dataValue\" not in data_value:\n", " print(data_value)\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n", " else:\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for value in one_cols[1:]:\n", " if value in dataItemNo_dataValue:\n", " append_rows.append(dataItemNo_dataValue[value])\n", " else:\n", " append_rows.append(\"\")\n", "\n", " workbook = xlrd.open_workbook('定性模型数据项12-11.xls')\n", "\n", " # 获取所有sheet的个数\n", " sheet_count = len(workbook.sheet_names())\n", "\n", " # 获取所有sheet的名称\n", " sheet_names = workbook.sheet_names()\n", "\n", " new_workbook = xlwt.Workbook()\n", " for i in range(sheet_count):\n", " # 获取当前sheet\n", " sheet = workbook.sheet_by_index(i)\n", "\n", " # 获取sheet的行数和列数\n", " row_count = sheet.nrows\n", " col_count = sheet.ncols\n", " # 获取原有数据\n", " data = []\n", " for row in range(row_count):\n", " row_data = []\n", " for col in range(col_count):\n", " row_data.append(sheet.cell_value(row, col))\n", " data.append(row_data)\n", " # 创建xlwt的Workbook对象\n", " # 创建sheet\n", " new_sheet = new_workbook.add_sheet(sheet_names[i])\n", "\n", " # 将原有的数据写入新的sheet\n", " for row in range(row_count):\n", " for col in range(col_count):\n", " new_sheet.write(row, col, data[row][col])\n", "\n", " if i == 0:\n", " # 在新的sheet中添加数据\n", " for col in range(col_count):\n", " new_sheet.write(row_count, col, append_rows[col])\n", "\n", " # 保存新的xls文件\n", " new_workbook.save(\"定性模型数据项12-11.xls\")\n", " \n", " update_e_value('定性模型数据项12-11.xls', 8, 1000)\n", "\n", " df = pd.read_excel('定性模型数据项12-11.xls')\n", " df=df.fillna(df.ffill())\n", " df1 = df[-2:].reset_index()\n", " # if df1.loc[1,'70号沥青开工率'] > 0.3: -- 2025年1月9日 发版更改\n", " if df1.loc[1,'70号沥青开工率'] > 30:\n", " a = (df1.loc[1,'70号沥青开工率']-0.2)*5/0.1\n", " else :\n", " a = 0\n", " b = df1.loc[1,'资金因素']\n", " if df1.loc[1,'昨日计划提货偏差']>0:\n", " c = df1.loc[1,'昨日计划提货偏差']*10/2000\n", " else :\n", " c = df1.loc[1,'昨日计划提货偏差']*10/3000\n", " d = df1.loc[1,'生产情况']\n", " if df1.loc[1,'基质沥青库存']/265007 >0.8:\n", " e = (df1.loc[1,'基质沥青库存'] - df1.loc[0,'基质沥青库存'])*10/-5000\n", " else : \n", " e = 0\n", " f = df1.loc[1,'下游客户价格预期']\n", " if abs(df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])>=100:\n", " g = (df1.loc[1,'即期成本'] - df1.loc[0,'即期成本'])*50/100\n", " else :\n", " g = 0\n", " h = df1.loc[1,'订单结构']\n", " x = round(0.08*a+0*b+0.15*c+0.08*d +0.03*e +0.08*f +0.4*g+0.18*h+df1.loc[0,'京博指导价'],2)\n", "\n", "\n", " login_res1 = requests.post(url=login_url, json=login_data, timeout=(3, 30))\n", " text1 = json.loads(login_res1.text)\n", " token_push = text1[\"data\"][\"accessToken\"]\n", "\n", "\n", " data1 = {\n", " \"funcModule\": \"数据表信息列表\",\n", " \"funcOperation\": \"新增\",\n", " \"data\": [\n", " {\"dataItemNo\": \"C01100036|Forecast_Price|DX|ACN\",\n", " \"dataDate\": cur_time,\n", " \"dataStatus\": \"add\",\n", " \"dataValue\": x\n", " }\n", "\n", " ]\n", " }\n", " headers1 = {\"Authorization\": token_push}\n", " res = requests.post(url=upload_url, headers=headers1, json=data1, timeout=(3, 5))\n", " \n", " \n", "\n", "\n", "def start_1():\n", " workbook = xlrd.open_workbook(read_file_path_name)\n", "\n", "\n", "\n", " # 选择第一个表格\n", " sheet = workbook.sheet_by_index(0)\n", "\n", " # 获取行数和列数\n", " num_rows = sheet.nrows\n", "\n", "\n", "\n", " row_data = sheet.row_values(1)\n", " one_cols = row_data\n", "\n", "\n", " login_res = requests.post(url=login_url, json=login_data, timeout=(3, 5))\n", " text = json.loads(login_res.text)\n", " if text[\"status\"]:\n", " token = text[\"data\"][\"accessToken\"]\n", " else:\n", " print(\"获取认证失败\")\n", " token = None\n", "\n", "\n", " now = datetime.now() - timedelta(days=1) \n", " year = now.year\n", " month = now.month\n", " day = now.day\n", "\n", " if month < 10:\n", " month = \"0\" + str(month)\n", " if day < 10:\n", " day = \"0\" + str(day)\n", " cur_time = str(year) + str(month) + str(day)\n", " cur_time2 = str(year) + \"-\" + str(month) + \"-\" + str(day)\n", " search_data = {\n", " \"data\": {\n", " \"date\": cur_time,\n", " \"dataItemNoList\": one_cols[1:]\n", " },\n", " \"funcModule\": \"数据项\",\n", " \"funcOperation\": \"查询\"\n", " }\n", " headers = {\"Authorization\": token}\n", " search_res = requests.post(url=search_url, headers=headers, json=search_data, timeout=(3, 5))\n", " search_value = json.loads(search_res.text)[\"data\"]\n", "# datas = search_value\n", " if search_value:\n", " datas = search_value\n", " else :\n", " datas = None\n", " \n", " \n", "\n", " append_rows = [cur_time2]\n", " dataItemNo_dataValue = {}\n", "# for data_value in datas:\n", "# dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for data_value in datas:\n", " if \"dataValue\" not in data_value:\n", " print(data_value)\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = \"\"\n", " else:\n", " dataItemNo_dataValue[data_value[\"dataItemNo\"]] = data_value[\"dataValue\"]\n", " for value in one_cols[1:]:\n", " if value in dataItemNo_dataValue:\n", " append_rows.append(dataItemNo_dataValue[value])\n", " else:\n", " append_rows.append(\"\")\n", "\n", " workbook = xlrd.open_workbook('定性模型数据项12-11.xls')\n", "\n", " # 获取所有sheet的个数\n", " sheet_count = len(workbook.sheet_names())\n", "\n", " # 获取所有sheet的名称\n", " sheet_names = workbook.sheet_names()\n", "\n", " new_workbook = xlwt.Workbook()\n", " for i in range(sheet_count):\n", " # 获取当前sheet\n", " sheet = workbook.sheet_by_index(i)\n", "\n", " # 获取sheet的行数和列数\n", " row_count = sheet.nrows - 1\n", " col_count = sheet.ncols\n", " # 获取原有数据\n", " data = []\n", " for row in range(row_count):\n", " row_data = []\n", " for col in range(col_count):\n", " row_data.append(sheet.cell_value(row, col))\n", " data.append(row_data)\n", " # 创建xlwt的Workbook对象\n", " # 创建sheet\n", " new_sheet = new_workbook.add_sheet(sheet_names[i])\n", "\n", " # 将原有的数据写入新的sheet\n", " for row in range(row_count):\n", " for col in range(col_count):\n", " new_sheet.write(row, col, data[row][col])\n", "\n", " if i == 0:\n", " # 在新的sheet中添加数据\n", " for col in range(col_count):\n", " new_sheet.write(row_count, col, append_rows[col])\n", "\n", " # 保存新的xls文件\n", " new_workbook.save(\"定性模型数据项12-11.xls\")\n", "\n", "\n", "\n", "\n" ] } ], "metadata": { "language_info": { "name": "python" } }, "nbformat": 4, "nbformat_minor": 2 }