python读xlsx中的A2到1764C的三维坐标数据的程序
要读取xlsx中的A2到1764C的三维坐标数据,你可以使用openpyxl库来实现。以下是一个示例程序:
import openpyxl
def read_coordinates(file_path):
wb = openpyxl.load_workbook(file_path)
sheet = wb.active
coordinates = []
for row in sheet.iter_rows(min_row=2, max_row=1764, min_col=1, max_col=1764*3, values_only=True):
coordinate = []
for i in range(0, len(row), 3):
x = row[i]
y = row[i+1]
z = row[i+2]
coordinate.append((x, y, z))
coordinates.append(coordinate)
return coordinates
# 调用函数读取xlsx文件中的坐标数据
coordinates = read_coordinates('data.xlsx')
# 打印第一个坐标点的x、y、z值
print(coordinates[0][0])
在上面的示例中,read_coordinates函数使用openpyxl库打开xlsx文件,并从第2行的A列开始读取到1764行的C列为止的数据。然后,将每个三维坐标的x、y、z值作为一个元组存储在一个列表中,并返回该列表。最后,通过调用print(coordinates[0][0])打印第一个坐标点的x、y、z值。
你需要将file_path参数替换为你自己的xlsx文件路径
原文地址: http://www.cveoy.top/t/topic/i1QH 著作权归作者所有。请勿转载和采集!