什么是錯誤的原因:“$”的意外“$”以及如何將txt文件轉換為xlsx文件?

[英]What is the cause of Error: unexpected '$' in “$” and how to convert txt file into xlsx file in R?


I wanted to write a code to convert automatically a huge number of .txt files into .xlsx files (Excel). I saw a code at this page Powershell Script to convert txt to xlsx and I modified just the name and the link of the folder. But when trying to run the code I get this error message:

我想編寫一個代碼,將大量的.txt文件自動轉換成。xlsx文件(Excel)。我在這個頁面Powershell腳本中看到了將txt轉換為xlsx的代碼,我只修改了文件夾的名稱和鏈接。但是當我嘗試運行代碼時,我得到了這個錯誤信息:

Error: unexpected '$' in "$"

錯誤:“$”的意外“$”

This is the code:

這是代碼:

$xlFixedFormat = Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbook 
$wb.SaveAs("C:\Users\wascal\Desktop\transfo\Test.xlsx”, $xlFixedFormat)

Could someone explain me the cause of the error help me to solve the issue? Thank you in advance.

誰能解釋一下錯誤的原因,幫助我解決這個問題嗎?提前謝謝你。

2 个解决方案

#1


1  

There is a missing [ in :

缺了一個。

$xlFixedFormat = Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbook

correct code should be

正確的代碼應該是

$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbook

#2


0  

Note that your

注意你的

$wb.SaveAs("C:\Users\wascal\Desktop\transfo\Test.xlsx”, $xlFixedFormat)

wb.SaveAs美元(“C:\用戶桌面\ transfo \ \ wascal \測試。xlsx”,xlFixedFormat美元)

Has another double quote at the end of the string.

在字符串的末尾有另一個雙引號。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2016/12/11/720dfcaf8f1de266e83edae11ee78424.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com