Solved how to echo variables into .csv file with colors?

November 14, 2016 at 03:14:39
Specs: Windows 64, Core i7 2GHz/16GB
Hi all,

I have the following line in my batch file:

echo.%%a;%%b;%%c>>D:\output.csv

which will import my variables into a .csv file . Is it possible to set the color of these variables in .csv in the batch file?

Thanks for any help!
Ela


See More: how to echo variables into .csv file with colors?

Reply ↓  Report •


✔ Best Answer
November 14, 2016 at 05:51:06
Then i suggest you to do the following:

echo.%%a;%RED%;%GREEN%;%BLUE%;%%b;%RED%;%GREEN%;%BLUE%;%%c;%RED%;%GREEN%;%BLUE%;>>D:\output.csv

R,G, B all got a value range of 0-255

Put the variables into an argument/var in an VBA Marco, then write them to your worksheet, while setting the RGB colour.

I must say though, I do not have much experience with VBA or vbs.



#1
November 14, 2016 at 03:40:59
Could you please explain:

1: What program you are trying to extract the .csv data with?
2: In what format you are trying to store the data?

With 2 i mean:
var1,var2,var3,color1,color2,color3

or:
var1,color1
var2,color2
var3,color3

or maby:
var1,color1,var2,color2,var3,color3

message edited by hidde663


Reply ↓  Report •

#2
November 14, 2016 at 04:12:53
@hidde663
for your second question I mean
var1,color1,var2,color2,var3,color3
because %%a, %%b and %%c will be my .csv file columns and I want these 3 columns have ยด3 different colors.I did not get your first question!

Reply ↓  Report •

#3
November 14, 2016 at 04:40:37
You can use .csv files with a lot of applications/scripts.

I'm guessing you are trying to import "output.csv" into EXCEL, right?


Reply ↓  Report •

Related Solutions

#4
November 14, 2016 at 04:54:27
A text file, including a csv, HAS NO color

=====================

M2 Get custom script or take private lessons


Reply ↓  Report •

#5
November 14, 2016 at 04:56:04
If you mean coloring the actual values in the csv files, that'd be impossible as it is a plain-text file.

However, if you mean displaying the values with the colors specified in the csv, you can use this (Given you only have three variables with their colors on each line):

@echo off
:: You need this loop at the beginning in order for :ColorText to work
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do set "DEL=%%a"


for /f "tokens=1-6 delims=," %%A in (input.csv) do (
	call :ColorText %%B "%%A" n
	call :ColorText %%D "%%C" n
	call :ColorText %%F "%%E" n
)
pause
goto :eof


:ColorText
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1
if /i "%~3"=="n" echo.
goto :eof

The color echoing is a slightly modified version of the answer found here. To use it, you use this:
call :ColorText <color> <text> [n]

The "n" is for echoing a newline after the text, if the n is not provided, you'll get the text like this: var1var2var3 instead of
var1
var2
var3

Valid colors can be found in color /?

When you copy this into your script remember to copy the top FOR loop. You can put :ColorTxt in the bottom of your script, or anywhere else as long as it doesn't run without being called.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)

message edited by RainBawZ


Reply ↓  Report •

#6
November 14, 2016 at 05:29:32
@ hidde663 yes

Reply ↓  Report •

#7
November 14, 2016 at 05:51:06
✔ Best Answer
Then i suggest you to do the following:

echo.%%a;%RED%;%GREEN%;%BLUE%;%%b;%RED%;%GREEN%;%BLUE%;%%c;%RED%;%GREEN%;%BLUE%;>>D:\output.csv

R,G, B all got a value range of 0-255

Put the variables into an argument/var in an VBA Marco, then write them to your worksheet, while setting the RGB colour.

I must say though, I do not have much experience with VBA or vbs.


Reply ↓  Report •

Ask Question