更新Power Query公式项
Contents
[
Hide
]
使用场景
可能存在数据源文件移动,Excel文件无法找到文件的情况。在这种情况下,Aspose.Cells API提供了使用PowerQueryFormulaItem类来更新Power Query Formula项的选项,以更新源文件的位置。
更新Power Query公式项
Aspose.Cells API提供了更新Power Query公式项的功能。以下代码片段演示了通过使用PowerQueryFormulaItem.Value属性在Excel文件中更新数据源文件的位置。源文件和输出文件附在下方供参考。
示例代码
This file contains 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
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Working directories | |
string SourceDir = RunExamples.Get_SourceDirectory(); | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
Workbook workbook = new Workbook(SourceDir + "SamplePowerQueryFormula.xlsx"); | |
DataMashup mashupData = workbook.DataMashup; | |
foreach (PowerQueryFormula formula in mashupData.PowerQueryFormulas) | |
{ | |
foreach (PowerQueryFormulaItem item in formula.PowerQueryFormulaItems) | |
{ | |
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"); |