Uppdatera Power Query Formel Objekt
Contents
[
Hide
]
Användningsscenario
Det kan finnas fall där datakällfilerna flyttas och excel-filen inte kan hitta filen. I sådana fall ger Aspose.Cells API alternativet att uppdatera Power Query Formula-objektet genom att användaPowerQueryFormulaItem klass för att uppdatera platsen för källfilen.
Uppdaterar Power Query Formel Objekt
Aspose.Cells API ger möjlighet att uppdatera Power Query Formula Items. Följande kodavsnitt visar uppdatering av datakällans filplats i excel-filen med hjälp avPowerQueryFormulaItem.Valuefast egendom. Käll- och utdatafilerna bifogas för din referens.
Exempelkod
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"); |