Azure Bicep -在Bicep中加载excel文件

vmdwslir  于 2022-12-19  发布在  其他
关注(0)|答案(1)|浏览(133)

我想从excel文件加载值,他们只是名字里面,我有很多。所以我不想复制所有的,并把他们放在一个数组。我想一些解决方案,如果可能的话,像[loadJsonContent]。

wbgh16ku

wbgh16ku1#

如果可能的话,我希望有一些解决方案,如[loadJsonContent]。
如果您想要二头肌的内置文件功能,答案是否定的。
从官方文件来看,File functions for Bicep只有三个:
加载文件为Base64
将文件作为base64字符串加载。
加载JSON内容
将指定的JSON文件作为Any对象加载。
加载文本内容
将指定文件的内容作为字符串加载。
我认为你的要求需要通过编写代码来实现。
顺便说一下,你没有明确定义excel文件,xlsx或csv?如果可能的话,请提供一个样本文件格式,以便我们可以提供具体的代码。
例如,我有这样一个Student.xlsx文件(CSV文件也是这样的结构。):

然后,我可以使用下面的Python代码来解析并获得我想要的数据:

import os
import openpyxl
import csv

#get the student name from 'Student Name' of sheet 'Tabelle1' of the file 'XLSX_Folder/Student.xlsx'
def get_student_name(file_path, sheet_name, col):
    student_name = []
    #if file_path ends with '.xlsx'
    if file_path.endswith('.xlsx'):
        wb = openpyxl.load_workbook(file_path)
        sheet = wb[sheet_name]
        #get all the values under the column 'Student Name'
        for i in range(col, sheet.max_row+1):
            student_name.append(sheet.cell(row=i, column=col).value)
        print('This is xlsx file.')
        return student_name
    elif file_path.endswith('.csv'):
        #get all the values under the column 'Student Name', except the first row
        with open(file_path, 'r') as f:
            reader = csv.reader(f)
            for row in reader:
                if reader.line_num == 1:
                    continue
                student_name.append(row[col-1])
        print('This is csv file.')
        return student_name
        print('This is csv file.')
    else:
        print('This is other format file.')

XLSX_file_path = 'XLSX_Folder/Student.xlsx'
CSV_file_path = 'CSV_Folder/Student.csv'
sheet_name = 'Tabelle1'
col = 2

print(get_student_name(XLSX_file_path, sheet_name, col))
print(get_student_name(CSV_file_path, sheet_name, col))

结果:

之后,解析你的二头肌文件,把上面的数据放进你的二头肌文件。
上面的代码只是一个演示,你可以用你喜欢的开发语言编写你自己的代码。无论如何,没有你要求的内置特性。

相关问题