更新Power Query公式项
Contents
[
Hide
]
使用场景
可能出现数据源文件被移动,Excel文件无法定位文件的情况。在此类情况下,Aspose.Cells for Python via .NET API提供使用PowerQueryFormulaItem类更新源文件位置的选项。
更新Power Query公式项
Aspose.Cells for Python via .NET API支持更新Power Query公式项。以下代码片段演示了如何通过使用PowerQueryFormulaItem.value属性更新Excel文件中的数据源文件位置。附上示例源文件和输出文件供您参考。
示例代码
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Working directories | |
SourceDir = RunExamples.Get_SourceDirectory() | |
outputDir = RunExamples.Get_OutputDirectory() | |
workbook = Workbook(SourceDir + "SamplePowerQueryFormula.xlsx") | |
mashupData = workbook.data_mashup | |
for formula in mashupData.power_query_formulas: | |
for item in formula.power_query_formula_items: | |
if item.name == "Source": | |
item.value = "Excel.Workbook(File.Contents(\"" + SourceDir + "SamplePowerQueryFormulaSource.xlsx" + "\"), null, true)" | |
# Save the output workbook. | |
workbook.save(outputDir + "SamplePowerQueryFormula_out.xlsx") |