我如何制作程序来修改文件MIK_Neva.xml中的值百分比
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我如何制作程序来修改文件MIK_Neva.xml中的值百分比相关的知识,希望对你有一定的参考价值。
我如何重新制作此程序以从Power Shell提示符输入百分比值?我如何修改此代码以从Powershell提示符中输入百分比值
[xml](Get-Content "MIK_Neva.xml") | ForEach-Object $_.SelectNodes('// FieldCostOptions/IncreaseCost') | ForEach-Object $_.SetAttribute("Percent", -9); $_.Save('Output.xml')
出现错误
无法阅读当地俄语文本。
文件MIK_Neva.xml
<?xml version="1.0" encoding="utf-8"?>
<PriceConfiguration Name="MIK_Neva" Version="1"><Description></Description><AuthorID>s0011373519</AuthorID><LastEditedBy>s0011373519</LastEditedBy><LastUpdate>14.11.2019 12:56:45</LastUpdate><File Type="XLS" Engine="0"><FilesMask>E:\FTP\PRICE_FORCEAUTO_MIK\NevaAvtocom.xlsx</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>1</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>Артикул (EMEX_Neva)</ReplaceTableName></Field><Field index="2" Enable="1"><Name>Наименование</Name><SheetColumn>2</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>5</SheetColumn><Required>1</Required><ValueMode>0</ValueMode><KeepValue>0</KeepValue><KeepLevel>0</KeepLevel><FieldFunctions Enabled="0" Version="1"/><FieldConditions Enable="0" Version="1"/></Field><Field index="4" Enable="1"><Name>Наличие</Name><SheetColumn>3</SheetColumn><Required>1</Required><ValueMode>0</ValueMode><KeepValue>0</KeepValue><KeepLevel>0</KeepLevel><FieldFunctions Enabled="0" Version="1"/><FieldConditions Enable="0" Version="1"/></Field><Field index="5" Enable="1"><Name>Цена</Name><SheetColumn>4</SheetColumn><Required>1</Required><ValueMode>0</ValueMode><KeepValue>1</KeepValue><KeepLevel>0</KeepLevel><FieldFunctions Enabled="1" Version="1"><Function CodeName="CompareNumbers" Enabled="1" param1="3000" param2="1000000"/></FieldFunctions><FieldConditions Enable="1" Version="1"/><FieldCostOptions Enabled="1" Version="1"><IncreaseCost Enabled="1" Percent="-5"/></FieldCostOptions></Field><Field index="6" Enable="1"><Name>ЦенаЗакупа</Name><SheetColumn>4</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>NevaAvtocom</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>2</FirstRow><LastRowColumn>1</LastRowColumn></SheetConfiguration></Sheets></PriceConfiguration>
答案
在您的代码中,使用“ .Percent”-从SelectSingleNode返回的对象不会解析为具有字段Percent的某些类。仅有XmlNodes具有可用于工作属性的方法您应该使用
x.SelectSingleNode ('// FieldCostOptions / IncreaseCost').SetAttribute("Percent", -5)
请,或者您可以使用此示例在一行中全部执行:
[xml](Get-Content "input.xml") | ForEach-Object $_.SelectNodes('// FieldCostOptions/IncreaseCost') | ForEach-Object $_.SetAttribute("Percent", -5); $_.Save('Output.xml')
如果您想编写脚本,那是您想要的吗?
$inputFile = Read-Host -Prompt 'Input file name to process'
$outputFile = Read-Host -Prompt 'Output file name'
$xml = New-Object -TypeName XML
$xml.Load($inputFile)
$utf8WithoutBom = New-Object System.Text.UTF8Encoding($false)
$sw = New-Object System.IO.StreamWriter($outputFile, $false, $utf8WithoutBom)
$xml.Save( $sw )
$sw.Close()
以上是关于我如何制作程序来修改文件MIK_Neva.xml中的值百分比的主要内容,如果未能解决你的问题,请参考以下文章