【发布时间】:2020-03-21 13:43:02
【问题描述】:
我们如何重新制作程序以在 windows 窗体中打开 xml 文件并在文件 MIK_RT.xml 中的价格词之后读取百分比值,并且可以从 windows 窗体中更改此百分比值并通过单击确定按钮以新值保存文件?
你能在 windows 窗体中重新制作我的程序或在 windows 窗体中插入这个 powershell 代码吗?文件需要以utf8编码保存
$outputFile = 'MIK_RT.xml'
write-output $outputFile
[xml](Get-Content "$outputFile") | ForEach-Object {$_.SelectNodes('//FieldCostOptions/IncreaseCost') |ForEach-Object {$_.GetAttribute("Percent")}; write-output $node.percent }
$inputpercent = Read-Host -Prompt 'percent'
[xml](Get-Content "$outputFile") | ForEach-Object {$_.SelectNodes('//FieldCostOptions/IncreaseCost') | ForEach-Object {$_.SetAttribute("Percent", $inputpercent)}; $_.Save('Output.xml')}
用于编辑 MIK_RT.xml 的文件
<?xml version="1.0" encoding="utf-8"?>
<PriceConfiguration Name="MIK_RT" Version="1">
<Description></Description>
<AuthorID>s0011373519</AuthorID>
<LastEditedBy>s0011373519</LastEditedBy>
<LastUpdate>14.11.2019 12:56:27</LastUpdate>
<File Type="XLS" Engine="0">
<FilesMask>E:\FTP\PRICE_FORCEAUTO_MIK\RT.xls</FilesMask>
<IncludeFiles></IncludeFiles>
<ExcludeFiles></ExcludeFiles>
<Macro OnStart="" />
<XLSoptions>
<Password></Password>
<MergeXLSsheets>1</MergeXLSsheets>
</XLSoptions>
<CSVoptions>
<RowsSeparator>13-10</RowsSeparator>
<ColumnsSeparator>59</ColumnsSeparator>
<AddHeaderRow>0</AddHeaderRow>
<UseBrackets>0</UseBrackets>
<Encoding>windows-1251</Encoding>
</CSVoptions>
<ReplaceTable Name="Price Codes" IsEmpty="False">
<Replacement Find="{@КодПрайса}" ReplaceWith="" />
<Replacement Find="{@ИмяФайлаДляПрайса}" ReplaceWith="" />
</ReplaceTable>
</File>
<Sheets>
<SheetConfiguration index="1">
<Name>Обработчик листа</Name>
<Description></Description>
<SheetSelectMode>1</SheetSelectMode>
<SheetName>Итого_Наценка_Остатков</SheetName>
<SheetIndex>1</SheetIndex>
<ReplaceTable Name="Price Sheet Codes" IsEmpty="False">
<Replacement Find="{@КодЛиста}" ReplaceWith="" />
<Replacement Find="{@ИмяФайлаДляЛиста}" ReplaceWith="" />
</ReplaceTable>
<PriceFields>
<Field index="1" Enable="1">
<Name>Артикул</Name>
<SheetColumn>2</SheetColumn>
<UseCellText>1</UseCellText>
<Required>1</Required>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
<ReplaceTableName>Артикул (EXIST_RT)</ReplaceTableName>
</Field>
<Field index="2" Enable="1">
<Name>Наименование</Name>
<SheetColumn>3</SheetColumn>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
<ReplaceTableName>Наименование (FA)</ReplaceTableName>
</Field>
<Field index="3" Enable="1">
<Name>Производитель</Name>
<SheetColumn>1</SheetColumn>
<Required>1</Required>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
<ReplaceTableName>Производитель (FA_RT)</ReplaceTableName>
</Field>
<Field index="4" Enable="1">
<Name>Наличие</Name>
<SheetColumn>4</SheetColumn>
<Required>1</Required>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="1" Version="1">
<Function CodeName="Replace" Enabled="1" param1=">" param2="" />
</FieldFunctions>
<FieldConditions Enable="0" Version="1" />
</Field>
<Field index="5" Enable="1">
<Name>Цена</Name>
<SheetColumn>5</SheetColumn>
<Required>1</Required>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="1" Version="1">
<Function CodeName="CompareNumbers" Enabled="1" param1="2499" param2="1000000" />
</FieldFunctions>
<FieldConditions Enable="0" Version="1" />
<FieldCostOptions Enabled="1" Version="1">
<IncreaseCost Enabled="1" Percent="-5" />
</FieldCostOptions>
</Field>
<Field index="6" Enable="1">
<Name>ЦенаЗакупа</Name>
<SheetColumn>5</SheetColumn>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
</Field>
<Field index="7" Enable="1">
<Name>ПР</Name>
<SheetColumn>1</SheetColumn>
<ValueMode>1</ValueMode>
<Formula>RT</Formula>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
</Field>
<Field index="8">
<Name>Срок_ZZAP</Name>
<SheetColumn>1</SheetColumn>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
</Field>
<Field index="9">
<Name>КодСтраны</Name>
<SheetColumn>1</SheetColumn>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
</Field>
<Field index="10">
<Name>Страна</Name>
<SheetColumn>1</SheetColumn>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
</Field>
<Field index="11">
<Name>ГТД</Name>
<SheetColumn>1</SheetColumn>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
</Field>
<Field index="12">
<Name>ИНН_Поставщика</Name>
<SheetColumn>1</SheetColumn>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
</Field>
<Field index="13">
<Name>КПП_Поставщика</Name>
<SheetColumn>1</SheetColumn>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
</Field>
<Field index="14">
<Name>НомерН</Name>
<SheetColumn>1</SheetColumn>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
</Field>
<Field index="15">
<Name>ДатаН</Name>
<SheetColumn>1</SheetColumn>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
</Field>
<Field index="16">
<Name>НомерСчета</Name>
<SheetColumn>1</SheetColumn>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
</Field>
<Field index="17">
<Name>ДатаСчета</Name>
<SheetColumn>1</SheetColumn>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
</Field>
<Field index="18">
<Name>НамерСФ</Name>
<SheetColumn>1</SheetColumn>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
</Field>
<Field index="19">
<Name>ДатаСФ</Name>
<SheetColumn>1</SheetColumn>
<ValueMode>0</ValueMode>
<KeepValue>0</KeepValue>
<KeepLevel>0</KeepLevel>
<FieldFunctions Enabled="0" Version="1" />
<FieldConditions Enable="0" Version="1" />
</Field>
</PriceFields>
<FirstRow>4</FirstRow>
<LastRowColumn>1</LastRowColumn>
</SheetConfiguration>
</Sheets>
</PriceConfiguration>
【问题讨论】:
-
与previous question 一样,您在不属于它们的地方添加空格字符。
$_.SelectNodes(' //FieldCostOptions/IncreaseCost')-->$_.SelectNodes('//FieldCostOptions/IncreaseCost') -
我们还没有收到您的来信.. 我的回答解决了您的问题吗?如果是这样,请点击左侧的✓ 考虑accepting。这将帮助其他有类似问题的人更轻松地找到它。
标签: java c# c++ powershell