Copy link to clipboard
Copied
hi,
is there any possibility to show an alert box in photoshop with the information taken excel sheet values
for example in my active document there is an layer group named [Coffee] using this name as reference the script should go to excel worksheet by using vlookup function and search for coffee in column B2 and return with price value of the product mention in excel sheet.
so the alerbox will provide information of the product price in photoshop itself
please help me in this
Copy link to clipboard
Copied
I don't know if you would be able to read a excel file directly, but you could save out the file as either a CSV or XML and then you could read the file and get the values.
Copy link to clipboard
Copied
thanks for the reply how to do with .csv file because i am having that version of my file also
Copy link to clipboard
Copied
But How to Reference the values of .CSV file into .jsx to get values
Copy link to clipboard
Copied
I'm not sure how you're cvs file is set up, but I made one like this"
I set up a PS file like this:
The csv file is called script-test.csv and is on my desktop. I selected the group coffee and ran this script
#target photoshop
var doc = activeDocument
var gp = doc.activeLayer
var csvFile = new File('~/desktop/script-test.csv')
var fileInfo = readTextFile (csvFile)
var foods = fileInfo.split('\n')[0].split(',')
var price = fileInfo.split('\n')[1].split(',')
for (var i=0;i<foods.length;i++){
if(foods==gp.name){
doc.activeLayer = gp.layers[0]
doc.activeLayer.textItem.contents = price
}
}
function readTextFile(textFile){
textFile.encoding = "UTF8";
textFile.lineFeed = "unix";
textFile.open("r", "TEXT", "????");
var str = textFile.read();
textFile.close();
return str
}
I then got this result:
Copy link to clipboard
Copied
I don't know what exactly should be result of your work, but seem to that you could be insterested in bult-in Photoshop function which can generate images from CSV files:
Tutorial : : Creating Data-Driven Graphics in Photoshop - YouTube
Copy link to clipboard
Copied
i am getting error on the variable price line and how to implement the alert method to popup the details in the .csv file and display it in alertbox
Copy link to clipboard
Copied
If you want just an alert box, replace lines 12 and 13 in my above code with:
alert(price)
Copy link to clipboard
Copied
it does nothing can you just tell me how should the .csv excel file need to be or what are all order elements should place in excel file
Copy link to clipboard
Copied
It would be better for you to show how your csv file is set up. I just did one as an example, as I wasn't sure what you're was like.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
the alert box is the thing i needed but its not reading the text file anyone tell me how to read the text file values.
Copy link to clipboard
Copied
In my first script I posted, I had the values in my excel file going the other direction that you have in yours. So I changed that and created a cvs file from this:
I made a PSD file with those three foods as layer names:
Then I modified the script to read the values in that direction:
#target photoshop
var doc = activeDocument
var gp = doc.activeLayer
var csvFile = new File('~/desktop/script-test.csv')
var fileInfo = readTextFile (csvFile)
var foods = fileInfo.split('\n')
for (var i=0;i<foods.length;i++){
if(foods.split(',')[0]==gp.name){
alert(foods.split(',')[1])
}
}
function readTextFile(textFile){
textFile.encoding = "UTF8";
textFile.lineFeed = "unix";
textFile.open("r", "TEXT", "????");
var str = textFile.read();
textFile.close();
return str
}
This is what I get with the almond layer selected and running the script:
Copy link to clipboard
Copied
Hi Vfxvenkat98,
the answer is given in the post #5 by Chuck Uebele
But your own csv is not consistent or a wrong example
Copy link to clipboard
Copied
Thank you very much Chuck Uebele
But one more thing just want to know if the script will work in on a .csv file like this setup
because in future my setup file will be like this
The script should take Values only with PRODUCT in A1, and TYPE in C1 and show the rest of the details as above.
thanks a lot
Copy link to clipboard
Copied
Copy link to clipboard
Copied
In line 11 of the code I just posted that is the line for the alert and contains the info on what to display:
alert(foods.split(',')[1])
The array "foods" contains the entire line in the cvs file. each entry is separated by the comma. So when you use split using the comma, it splits that array entry into another array of just that line. So you can get each column by changing the number at the end. Arrays are numbered starting at 0. So in the above line, there is a 1, which denotes the second column. In your example, you would use 1 for the stock entries, 2 for the type, and 3 for the price. How you want to display that is up to you.
Copy link to clipboard
Copied
that worked but what if no data found in the text file or .csv i wanted it to show an alert of no data found and even i tried
else loop to show another alert box of "No data Found" but it iterates through the Whole sheet and continuously showing the error at multiple times.
Is there any solution for that.
Copy link to clipboard
Copied
put the code in a try/catch block, so it doesn't throw an error and allows you to control what happens:
try{alert(foods.split(',')[1]) }
catch(e){alert('There is no data')}
Copy link to clipboard
Copied
i tried these block with in for loop but not working for me
Copy link to clipboard
Copied
You're going to have to post some of your code, so we can see what is going wrong.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
and also i want to i know how to attach the .csv file from a network share drive.
Copy link to clipboard
Copied
You have an issue with your splitting the csv file. You're adding spaces around the comma, there shouldn't be any spaces:
.split(',')
NOT
.split(' , ')
As far as using a CSV file from a network drive, you just need to enter the full path to the file on the network. Don't used a mapped path, but the actual path.