What is the cause of Error: unexpected '$' in "$" and how to convert txt file into xlsx file in R? - excel

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:
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.

There is a missing [ in :
$xlFixedFormat = Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbook
correct code should be
$xlFixedFormat = [Microsoft.Office.Interop.Excel.XlFileFormat]::xlOpenXMLWorkbook

Note that your
$wb.SaveAs("C:\Users\wascal\Desktop\transfo\Test.xlsx”, $xlFixedFormat)
Has another double quote at the end of the string.

Related

How to save python file in jupyter note if path contains spaces %20

When I try to save a file in a jupyter notebook I get an error saying there is no file or directory.
Error Message ___________________________________________________________
Unexpected error while saving file: OneDrive%%20-%%20Files/Desktop/PythonProjects/bhp.ipynb [Errno 2] No such file or directory: 'C:\Users\username\OneDrive%%20-%%20Files\Desktop\PythonProjects\bhp.ipynb'
I began having this problem after a software update where now I can only save things to "OneDrive - Files". Unfortunately, the path to OneDrive contains several spaces - causing this error every time I try to save a new file. I would use a different directory if I could. I was hoping for an easy fix like wrapping the path in quotes - but so far this didn't work.
Replacing the %20 characters with a literal space resolved the issue. I suppose the Jupyter Notebook treats the path the same way as a url and inserts %20 characters for spaces. But when saving to a directory on a pc - the %20 characters can be replaced with a space - without the need to wrap the path in quotations or to place backslashes before the spaces.

convert file type from "UTF-8 Unicode text" to "C source, ISO-8859 text"

I am a programmer. I write C code in Linux using GCC, and they can run correctly. Now, I want to run these codes in Windows system using Visual studio 2015. But it always show some errors and warnings as following:
1>f:\md\test_sm3_hmac_02\tools.h : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
1>f:\md\test_sm3_hmac_02\types.h : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss
1>f:\md\test_sm3_hmac_02\tools.h(13): error C2143: syntax error: missing ')' before '*'
1>f:\md\test_sm3_hmac_02\tools.h(13): error C2143: syntax error: missing '{' before '*'
when I open every file and copy they in new file that is created in windows and don't do any others change. It runs correctly. But my project contains many file and I don't do this to solve this problem.
I want to solve it by doing few work.
The format of file created by VS2015 in windows is:
$ file testtypes.h
testtypes.h: C source, ISO-8859 text
The format of file created by touch in linux is:
$ file filetest.c
filetest.c: UTF-8 Unicode text
How can i do ?

ParserError: Error tokenizing data. C error

i'm using a script ScriptGlobal.py that will call and execute 2 other scripts script1.py and script2.py exec(open("./script2.py").read()) AND exec(open("./script1.py").read())
The output of my script1 is the creation of csv file.
df1.to_csv('file1.csv',index=False)
The output of my script2 is the creation of another csv file.
df2.to_csv('file2.csv',index=False)
In my ScriptGlobal.py i want to read the 2 files file1.csv and file2.csv and then i got this error.
ParserError: Error tokenizing data. C error: Expected 1 fields in line 16, saw 3
Is there solution to do it without doing manuallyu the manipulation in EXCEL ?
Thank you
Did you try save these two .csv files as ANSI? I had problem with .csv when they were saved as UTF-8.

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\mswitajski\\Desktop\\alice.txt'

I'm trying to read in a text file to work with Word Clouds. Here is the syntax I'm trying:
# Read the whole text.
text = open(r'C:\Users\mswitajski\Desktop\alice.txt').read()
But I keep getting the following error:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\mswitajski\\Desktop\\alice.txt'
I've triple checked the file name, tried reading it as a raw file, changed the slashes and everything but I continue to get the same error.
Well, if someone reaches up to here and still could not find the solution then here is the more pythonic way of doing the absolute path in windows.
Instead of using:
text = open(r'C:\Users\mswitajski\Desktop\alice.txt').read()
use os.sep, in conjunction of os.path.join like the following:
import os
text = open(os.path.join('C:', os.sep, 'Users', 'mswitajski', 'Desktop', 'alice.txt')).read()
Try changin the path to this"
'C:\Users\mswitajski\Desktop/alice.txt'
Sometimes windows won't find/recognize the file path when the file is specified like this
'C:\Users\mswitajski\Desktop\alice.txt'
In the answer it shows up as only one \ but you still need 2 like your previous path. The only difference is the last slash /. Hope that works.
At your text raw file (alice.txt) try delete the .txt.
The file probably is named alice.txt.txt
I face the same issue and solve it by deleted the .txt.
I had to use double slashes instead of one, because python interpreted it as a escape sequence. My final string was:
C:\\Users\\ArpitChinmay's\\AppData\\Roaming\\Code\\User\\globalStorage\\moocfi.test-my-
code\\tmcdata\\TMC workspace\\Exercises\\hy\\hy-data-analysis-with-python-
2020\\part02-e04_word_frequencies\\src\\alice.txt
However, it worked this way too,
C:\\Users\\Arpit Chinmay's\\AppData\\Roaming\\Code\\User\\globalStorage\\moocfi.test-
my-code\\tmcdata\\TMC workspace\\Exercises\\hy\\hy-data-analysis-with-python-
2020\\part02-e04_word_frequencies\\src/alice.txt

Octave. dlmread: unable to open file 'myfile.txt'

I have a txt file with data in form: 2104,3,399900 i_e int1,int2,int3 I have 50 rows in the same format.
Now I can want to put the data into variable, say, a.
I am using the the command :
a = csvread('ex1data2.txt');
%I have tried a = dlmread('ex1data2.txt'); it too does't work
it produces an error :
error: dlmread: unable to open file 'ex1data2.txt'.
I have added the path of the directory that have file to the octave search paths.
How can I read the text file?
Thanks.

Resources