Power Query Formulaアイテムの更新

使用シナリオ

データソースファイルが移動され、Excelファイルがファイルを見つけることができない場合があります。そのような場合には、PowerQueryFormulaItemクラスを使用して、Power Query Formulaアイテムを更新するオプションがAspose.Cells APIに用意されています。

Power Query Formulaアイテムの更新

Aspose.Cells APIでは、Power Query Formulaアイテムを更新する機能が提供されています。次のコードスニペットは、Excelファイル内のデータソースファイルの場所をPowerQueryFormulaItem.Valueプロパティを使用して更新する方法を示しています。参照用に元のファイルと出力ファイルが添付されています。

サンプルコード

// 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");