使用powershell将数据从excel复制到outlook | 珊瑚贝

Copy data from excel to outlook using powershell


我尝试了以下代码,但它在将数据从 Excel 复制到 Outlook 时粘贴了一些垃圾文本。使用 PowerShell。
使用的代码:

1
2
$body=“”
get-content“C:\\Users\\smi00019\\Desktop\\AO\\Book1.xlsx” | foreach{$body+=“$_`n}

Excel 数据:

1
2
3
Name    Place   Animal
ABC     Mumbai  Dog
XYZ     Pune    Cat

我正在尝试复制上述数据范围 A1:c3

  • 使用 Powershell 读取 Excel 数据并写入变量的可能重复项
  • 您不是在阅读”垃圾数据”,而是在尝试获取文件中的内容,而不仅仅是单元格中的值。
  • 您需要发布的链接 Pac0 或将文件保存为 csv 而不是 xlsx,并使用 Import-Csv 将数据导入 Powershell。


Get-Content 用于基于文本的文件。 Excel 文件不是基于文本的,而是包含其他元素(格式、公式、宏、图表等)

我建议使用 PSExcel 模块,因为它包含 Import-XLSX 函数,这使得处理 Excel 文件变得非常容易。

Import-XLSX 像 Import-CSV 一样工作,并从文件中生成一个 \\’array\\’ 对象。

Excel:

enter

1
$Imported = ImportXLSX -Path C:\\Temp\\Demo.xlsx Header samaccountname, EID, Date

PS 对象:

enter

然后您可以使用 Select-Object 来获取您想要的 Property(列名)并且您只需要 First 两个条目(行)。

1
$Imported | Select-Object -Property Column1,Column1,Column1 -First 2

来源:https://www.codenong.com/49410016/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_9493.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?