def create_file():
file_writer= open('testFile.txt','w')
file_writer.write('TESTING...;\n')
file_writer.flush()
file_writer.close()
def my_macro():
wb = Workbook.caller() # Creates a reference to the calling Excel file
Range('Sheet1', 'C3').value = random.randint(0,10)
updateValue = Range('Sheet1', 'C3').value
print("updatedValue=" , updateValue);
create_file()
if __name__ == '__main__':
path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'FirstExcel.xlsm'))
Workbook.set_mock_caller(path)
my_macro()
当我在 Eclipse 中运行上述代码时,它会创建一个文件并更新 Excel 电子表格。但是,当我从 excel 运行它时,它会更新电子表格,但不会创建文件。