python win32com to trim excel cell value with leading spaces - trim

Code syntax for win32com to trim excel cell value with leading spaces?
In VBA is trim(cells(1,1).value)

Related

Formatting of Excel cells in R: combination of thousand separators und two signs after decimal comma

i am formatting cells of created Excel document with R-package openxlsx.
The required format of cells in Excel output-file is: "10.000,02" - i.e. with:
point as thousand separator;
comma as decimal separator;
two signs after comma.
If i apply the code:
cell_style <- createStyle(numFmt = "#.##0,00")
the number in Excel file seems as "10000,02111" - only with comma as decimal separator, but without thousand separators and with more than two signs after comma.
If the following code is applied:
cell_style <- createStyle(numFmt = "COMMA")
the number in Excel file is "10.000" - with point as thousand separator (despite that function containts "comma"...) but without decimal ceparator and signs after it.
After application the code:
cell_style <- createStyle(numFmt = "NUMBER")
the number in Excel file seems as "10000,02" - with comma as decimal separator and two signs after, but without point as thousand separator.
What should i apply to receive "10.000,02"?

read.csv Fails Due to Rows With A Trailing Comma

I am reading from an API into a CSV file.
I then use R to perform calculations on that data. I am using read.csv to read the data into R.
In a few cases, the last column of a row has a blank value so the row ends in a comma.
This causes read.csv to fail.
Short of writing a script to fix the file, is there any way to read the CSV with a row or rows ending with a trailing comma?
I see what I did wrong. Some of my CSV fields are enclosed in double quotes, however I failed to define a quote character in my read.csv statement.
Here is my corrected statement:
MyData <<- read.csv(file=“myfile.csv”, header=TRUE, stringsAsFactors=FALSE, sep=“,”, quote=“\””)
Note that the quote parameter is escaped with a backslash.
Thanks to all.

Quotes not around values in CSV

I'm using ToCsv() on a collection to convert it to CSV text.
None of the values have quotes around them - even when there are spaces in them.
How do I switch quotes on?
CSV fields only need to be quoted if they contain delimiters, line breaks or quotes themselves.

CSV file is not recognized

Im exporting an excel file into a .csv file (cause I want to import it into R) but R doesn't recognize it.
I think this is because when I open it in notepad I get:
Item;Description
1;ja
2;ne
While a file which does not have any import issues is structured like this in notepad:
"Item","Description"
"1","ja"
"2","ne"
Does anybody know how I can either export it from excel in the right format or import a csv file with ";" seperator into R.
It's easy to deal with semicolon-delimited files; you can use read.csv2() instead of read.csv() (although be aware this will also use comma as the decimal separator character!), or specify sep=";".
Sorry to ask, but did you try reading ?read.csv ? The relevant information is in there, although it might admittedly be a little overwhelming/hard to sort out if you're new to R:
sep: the field separator character. Values on each line of the
file are separated by this character. If ‘sep = ""’ (the
default for ‘read.table’) the separator is ‘white space’,
that is one or more spaces, tabs, newlines or carriage
returns.

Ignoring ascii carriage return characters in R

I've a dataset in tab delimited text file. The data have been exported from an old-school relational database software 4D. Most of the lines seems to be well formated but some lines include an ASCII carriage return character (^M in Emacs or Ascii code 13). I would like to read the data in R using a function such as read.table() and to find a way to ignore those ascii carriage return symbols. Does anyone have a solution ?
In Vim you can create the ^M character by typing control-v control-m
So you could replace every occurence of ^M with:
:%s/<c-v><c-m>//g

Resources