简体   繁体   English

如何使用Powershell从文本文件中提取字符串并将其复制到Excel工作表

[英]How to Extract Strings from a text file and copy them to excel sheet using Powershell

I have plenty of text files containing data like this: 我有很多包含如下数据的文本文件:

refresh: '<%= GlobalizationUtil.GetText(GlobalizationKey.Refresh) %>',
close: '<%= GlobalizationUtil.GetText(GlobalizationKey.Close) %>',
all: '<%= GlobalizationUtil.GetText(GlobalizationKey.All) %>',
entries: '<%= GlobalizationUtil.GetText("DepMethodEdit_Entries") %>',
archive: '<%= GlobalizationUtil.GetText("worklist_Archive") %>',
onequarter: '<%= GlobalizationUtil.GetText("worklist_onequarter") %>',
halfyear: '<%= GlobalizationUtil.GetText("worklist_halfyear") %>',
oneyear: '<%= GlobalizationUtil.GetText("worklist_oneyear") %>',
twoyears: '<%= GlobalizationUtil.GetText("worklist_twoyears") %>',
customize: '<%= GlobalizationUtil.GetText("CBW_EditDashlet") %>',
notSentLabel: '<%= GlobalizationUtil.GetText("status-notsend") %>',
sentLabel: '<%= GlobalizationUtil.GetText("status-sent") %>',
errorSendingLabel: '<%= GlobalizationUtil.GetText("status-error") %>',
openLabel: '<%= GlobalizationUtil.GetText(GlobalizationKey.Open) %>',
rejectedLabel: '<%= GlobalizationUtil.GetText("DocumentStatus_Rejected") %>',
normalLabel: '<%= GlobalizationUtil.GetText("Normal") %>',
creditLabel: '<%= GlobalizationUtil.GetText(GlobalizationKey.Credit) %>',
deleteinvoice: '<%= GlobalizationUtil.GetText("ProcessedInvoicingDelete") %>'

Is it possible to extract this string <%= GlobalizationUtil.GetText("ProcessedInvoicingDelete") %> and copy it to an excel sheet using Powershell? 是否可以提取此字符串<%= GlobalizationUtil.GetText(“ ProcessedInvoicingDelete”)%>并使用Powershell将其复制到excel工作表中?

Yes. 是。 High level: 高水平:

  • Get contents of the text file 获取文本文件的内容
  • use Select-String or [regex]::Matches for each element(row) 对每个元素(行)使用Select-String[regex]::Matches
  • Export to CSV (if you don't want headers, use Set-Content otherwise use Export-CSV ) 导出为CSV(如果您不希望标题,请使用Set-Content否则使用Export-CSV
  • Create an Excel ComObject 创建一个Excel ComObject
  • Open a workbook, and a worksheet 打开一个工作簿和一个工作表
  • use SaveAs method 使用SaveAs方法
  • quit Excel ComObject 退出Excel ComObject

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用PowerShell将txt文件中每行的第一个单词放入Excel工作表中? - How do I take the first word from each line in txt file and put them into an Excel sheet using PowerShell? 将文本文件复制到Excel工作表 - Copy text file to Excel sheet Excel VBA复制查询以将数据从工作表复制到文本文件 - Excel VBA copy query to copy data from sheet to text file Excel:如何从公式中提取文本字符串? - Excel: How to extract text strings from a formula? 如何使用 Python 从多个文本文件中提取数据到 Excel? (每张纸一个文件的数据) - How do I extract data from multiple text files to Excel using Python? (One file's data per sheet) 如何从 Outlook Email 附件中提取数据并将其复制到 Excel 文件中? - How to extract data from Outlook Email attachements and copy them into Excel file? 使用VBA从Excel工作表复制嵌入的文本文件 - Copy embedded text file from an Excel sheet with VBA Python,在列中搜索特定字符串的Excel工作表,并将这些行提取到文本文件中 - Python, search excel sheet for specific strings in a column and extract those rows to a text file 将Excel工作表的内容复制到文本或XML文件 - Copy content of Excel sheet to a text or XML file 如何从工作表复制到另一个工作表Excel? - How to copy from a sheet to another sheet excel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM