Excel - Photoshop Integration
Hello everyone,
I have a PSD file for a Business Card template, and I want to write a code that can get into Excel, replace Text Layers in the PSD file with data from Excel columns, export the result as a PNG file, and save it with the Full Name from Excel, and then iterate this as many rows as there are in the Excel file.
I am trying out with the code below but unfortunately I am getting

Can anyone help me please?
Thank you so much in advance.
Here's the code that I have now:
// Prompt the user to enter the path to the PSD file
var psdFilePath = prompt("Enter the path to the PSD file:");
// Open the PSD file
var docRef = app.open(new File(psdFilePath));
// Prompt the user to enter the path to the Excel sheet
var excelFilePath = prompt("Enter the path to the Excel sheet:");
// Prompt the user to enter the output folder path
var outputFolderPath = prompt("Enter the path to the output folder:");
// Open the Excel sheet
var excelFile = new File(excelFilePath);
var excelApp = new BridgeTalk();
excelApp.target = "excel";
excelApp.body = "var app = new ActiveXObject('Excel.Application'); app.Visible = false; app;";
excelApp.send(30000);
// Define the text layers to be replaced
var textLayers = [ { name: "Full Name", columnName: "Name" }, { name: "Job Title", columnName: "Job Title" }, { name: "Email Address", columnName: "E-Mail" }, { name: "Phone Number", columnName: "Phone Number" }];
// Loop through the Excel sheet rows and replace the text layers with data from the Excel sheet
var sheet = workbook.Sheets("Data");
var lastRow = sheet.Cells(sheet.Rows.Count, 1).End(-4162).Row; // Get last row of data
for (var i = 2; i <= lastRow; i++) { // Start at row 2, assuming first row is header row
var name = sheet.Cells(i, 1).Value;
// Loop through the text layers and replace the text with data from the Excel sheet
for (var j = 0; j < textLayers.length; j++) {
var layer = docRef.layers.getByName(textLayers[j].name);
var columnName = textLayers[j].columnName;
var cellValue = sheet.Cells(i, sheet.Range(columnName + "1").Column).Value;
layer.textItem.contents = cellValue;
}
// Save the resulting image as a PNG file with the name from Excel
var savePath = outputFolderPath + "\\" + name + ".png";
docRef.saveAs(new File(savePath), new PNGSaveOptions());
}
// Close the PSD file and Excel sheet
docRef.close(SaveOptions.DONOTSAVECHANGES);
workbook.close();
excelApp.quit();
