i have an .js file in which Text contents have to replaced with the text content in excel
for example
var gCategory_CircuitDiagram = "Circuit Diagram";
var gCategory_HarnessLayout = "Harness Layout";
var gCategory_PowerSource_Grounding_SneakPath1 = "Power Source";
var gCategory_PowerSource_Grounding_SneakPath2 = "Power Source / Grounding / Sneak Path";
var gCategory_Connector = "Connector";
var gCategory_Junction = "Connection information";
in this textcontents("Circuit Diagram") inside the double quotes i have to replace with contents in excel can anybody tell me how to get JS file and xml data as input replace all the text contents , i will be very thankful to you if you help me in this case.
with regards,
karthik
I'm not sure to understand what process you're trying to develop here exactly.
From what I get you could write a script using nodeJS and 2 module, xlsx and xml2js.
The xlsx module would allow you to read your excel file and get a Object from it.
You can then edit this object with your list of changes ('circuit diagram', etc.).
When it's done you can generate an xml file with the xml2js module
https://www.npmjs.com/package/xlsx
https://www.npmjs.com/package/xml2js
Related
I'm trying to display the last updated time of a file (not my html file, another file).
HTML:
<p>Last updated: <span id="lastUpdate"></span></p>
JavaScript:
var file = 'data/myFile.csv';
var modifiedTime = new Date(file.lastModified);
document.getElementById('lastUpdate').innerHTML = modifiedTime;
When I run it, it just displays the following; (with no errors in the console)
Last updated: Invalid Date
I'm obviously missing something, probably something small.
Edit:
My files are setup like below:
site/index.html
site/data/myFile.csv
site/js/lastUpdate.js
Yes - when you declare variable
var file = 'data/myFile.csv'
in file variable you have only file path - not file content (to read it you can use fetch). The second thing- when you read file content - then you should parse it - to read proper csv column
I am trying to write a gmail add-on where I iterate over all emails and create a report based on their producers. Iterating over emails is the easiest part and I have done that, however I can't find any way to get producer line of each PDFs.
So far I tried
analyzing the blob, however this is something like writing a PDF library to parse all syntax. producer tag is not clearly present
adding pdf.js, which is a third party open source tool to extract such information. However, I couldn't add it due to ES3 - ES6 support issue.
What's the best way to get the producer line of a PDF in google app script?
Thank you
You want to retrieve the value of Producer from PDF file.
I could understand like above. If my understanding is correct, how about this sample script? In this sample script, from your shared PDF files, the value of Producer is retrieved by 2 regular expressions from the file content. Please think of this as one of several answers.
Sample script:
When you use this script, please set the folder ID of folder that PDF files are put. This script retrieves the value from all PDF files in a folder.
var folderId = "### folderId ###";
var files = DriveApp.getFolderById(folderId).getFilesByType(MimeType.PDF);
var regex = [/Producer\((\w.+)\)/i, /<pdf:Producer>(\w.+)<\/pdf:Producer>/i];
var result = [];
while (files.hasNext()) {
var file = files.next();
var content = file.getBlob().getDataAsString();
var r = regex.reduce(function(s, e) {
var m = content.match(e);
if (Array.isArray(m)) s = m[1];
return s;
}, "");
result.push({
fileName: file.getName(),
fileId: file.getId(),
vaueOfProducer: r,
});
}
Logger.log(result); // Result
Result:
This sample result was retrieved from a folder (my Google Drive) that the shared 3 PDF files were put.
[
{
"fileName": "2348706469653861032.pdf",
"fileId": "###",
"vaueOfProducer": "iText� 7.1.5 �2000-2019 iText Group NV \(iText; licensed version\)"
},
{
"fileName": "Getting started with OneDrive.pdf",
"fileId": "###",
"vaueOfProducer": "Adobe PDF library 15.00"
},
{
"fileName": "DITO-Salesflow-040419-1359-46.pdf",
"fileId": "###",
"vaueOfProducer": "iText 2.1.7 by 1T3XT"
}
]
Note:
About the file of 2348706469653861032.pdf, the characters which cannot be displayed are included in the value of Producer.
This is a sample script. So please modify this for your situation.
I want to get the content of a file (as string) with google script. It's a txt or html file which I want to edit as string after.
The file is stored on Google Drive and I know the ID.
What I know that you can access the file with:
var Template = DriveApp.getFileById('18DEuu91FJ4rhTYd-xrlNpP2U9jfyheEI');
But I can nothing find how to read the content of this file like "file_get_contents" in PHP.
According to Googles Reference on the Apps Script you can use the getAs() method to return the file contents. I haven't tested this myself, but you could try something like:
var Template = DriveApp.getFileById('18DEuu91FJ4rhTYd-xrlNpP2U9jfyheEI');
var contents = Template.getAs('text/plain');
I'm used to selecting, opening and reading a text file (CSV, JSON) from my local directory. I now have access to our data feeds online but don't know how to do the same thing with a URL instead of a local file.
For a local file I simply use something like this:
var myFile = File.openDialog();
myFile.open();
myFile.read();
Is there a way to do this with a feed from a URL in javascript for AE?
Here is one of the feeds: feeds.nfl.com/feeds-rs/schedules.json
No need to save file, just one line do the trick =)
data = JSON.parse(system.callSystem('curl -s "https://path_to_json"'));
I think in After Effects the easiest way is to do a system call.
The Socket object from ExtendScript is complicated. Look at GetURLs.jsx by Rorohiko.
You need to allow your script to access the network. See this stackoverflow
# Mac Osx
var curlcmd = "curl feeds.nfl.com/feeds-rs/schedules.json > ~/Desktop/test/schedules.json";
var stdout = system.callSystem(curlcmd);
$.writeln(stdout);
var file = File("~/Desktop/test/schedules.json");
file.open();
var content = file.read();
file.close();
$.writeln(content);
I am using acrobat XI to write some script. What I would like to do is 1) get the current processed pdf file name and 2) just simply output a text file
var textValue = "test";
var doc = this.createDataObject({cName: "test.txt", cValue: textValue});
this.exportDataObject({cName: "test.txt", nLaunch:0});
This is working , but I would like to provided a fixed path , I tried saveAs but it seems only for pdf , exportAsText not working as well.
Are there any way to fix it? thanks
Official documentation says:
Example: Save the current document in rich text format:
this.saveAs("/c/myDocs/myDoc.rtf", "com.adobe.acrobat.rtf");
I guess you can replace RTF format with TXT (com.adobe.acrobat.plain-text):
this.saveAs("test.txt", "com.adobe.acrobat.plain-text"); // try this