Export collection in CSV format - how to get rid of superfluous columns
Hello,
I am trying to export Zotero collections in CSV format. However, I notice that the resulting file contains a lot of fields/columns that I do not need. I just want the essential information such as author names, article titles, journal titles, abstract, year, etc.
Is there anything I can do so that the exported file only contains the fields I need (apart from manually deleting the unnecessary ones)?
thank you!
I am trying to export Zotero collections in CSV format. However, I notice that the resulting file contains a lot of fields/columns that I do not need. I just want the essential information such as author names, article titles, journal titles, abstract, year, etc.
Is there anything I can do so that the exported file only contains the fields I need (apart from manually deleting the unnecessary ones)?
thank you!
But it might be easier to just delete the unwanted columns in excel or something similar.
Unfortunately I have no ability to edit the translators.
The reason why I would prefer not to manually delete the unwanted columns is this: Suppose I exported the collection at Time 1, and manually deleted those columns. When the collection expands, and the additional items in the collection are exported at Time 2, and if I want to copy and paste those additional rows into the previous excel file, then I would have to be very careful to delete from the Time 2 file precisely the same columns that were deleted at Time 1. And then Time 3, 4, etc. Too much trouble for me.
On second thought, I think it might be worth looking into a macro that can delete multiple columns at one go ...
(1) Find the translator in your <zotero data directory>/translators. It should be named CSV.js.
(2) Close Zotero/Firefox, make a copy of the CSV.js file, rename it to something like "CSV (custom).js".
(3) Open the file in a proper text editor, like Notepad++
(4) At the top of the translator, change translatorID to another value. Change the label to whatever you want it to appear as, like "CSV (custom)"
(5) Scroll down to the section towards the top that says "var exportedFields = [" and comment out or delete the columns you don't want exported. Make sure you don't mess up any of the commas (there should be one separating all columns)
(6) Save the file, fire up Zotero, export, enjoy, buy zuphilip (Philipp Zumstein) a beer for making this easy.
I am suspecting that I might have messed up step (5). I am pasting below my edited part, and the original part. If you could take a quick look to see if I made any mistakes, I'd really appreciate it. Thanks a lot! (I also saw that you were one of the creators of the translator. That's so great!!)
=================
MINE:
// Exported columns in order of export
var exportedFields = [
// "Important" metadata
"itemType","publicationYear","creators/author","title",
"publicationTitle",abstractNote",
// Other common fields
"tags/own","tags/automatic",
];
-------
ORIGINAL:
// Exported columns in order of export
var exportedFields = [
// "Important" metadata
"key","itemType","publicationYear","creators/author","title",
"publicationTitle","ISBN","ISSN","DOI","url","abstractNote","date",
"dateAdded","dateModified",
// Other common fields
"accessDate","pages","numPages","issue","volume","numberOfVolumes",
"journalAbbreviation","shortTitle","series","seriesNumber","seriesText",
"seriesTitle","publisher","place","language","rights","type","archive",
"archiveLocation","libraryCatalog","callNumber","extra","notes",
"attachments/path","attachments/url","tags/own","tags/automatic",
// Creators
"creators/editor","creators/seriesEditor","creators/translator",
"creators/contributor","creators/attorneyAgent","creators/bookAuthor",
"creators/castMember","creators/commenter","creators/composer",
"creators/cosponsor","creators/counsel","creators/interviewer",
"creators/producer","creators/recipient","creators/reviewedAuthor",
"creators/scriptwriter","creators/wordsBy","creators/guest",
// Other fields
"number","edition","runningTime","scale","medium","artworkSize",
"filingDate","applicationNumber","assignee","issuingAuthority","country",
"meetingName","conferenceName","court","references","reporter",
"legalStatus","priorityNumbers","programmingLanguage","version","system",
"code","codeNumber","section","session","committee","history",
"legislativeBody"
];
In addition to the discussion above, I want to remove the headers and make sure that, when pasted, the references start from the first line.
I managed to (1) edit the columns to include (as described above), (2) remove the headers by:
a. Removing writeColumnHeaders in function exportNotes (line 109)
Now I want to make sure it pastes to the first line, but I don't manage to make it happen. I suspect I should change something in the 'doExport' function (lines 105-120). Any suggestion how to proceed?
I created a Gist with an overview of the edits I made for clarification: https://gist.github.com/floriandierickx/b70c26d0300f73b8b9cf0f55d4260323/revisions
----
var exportNotes;
function doExport() {
exportNotes = Zotero.getOption("exportNotes");
// Until we fix UTF-8xBOM export, we'll write the BOM manually
Zotero.write("\uFEFF");
// column header writing disabled
// writeColumnHeaders();
var item, line;
while (item = Zotero.nextItem()) {
if (item.itemType == "note" || item.itemType == "attachment") continue;
line = '';
for (var i=0; i<exportedFields.length; i++) {
line += (i ? fieldDelimiter : recordDelimiter)
+ getValue(item, exportedFields[i]);
}
Zotero.write(line);
}
}
If I include additional data "fields" with the extra field in this format:
Design: Cross-sectional
Sample size: 400
Is there any way to have these broken out into separate fields/columns by the translator?
I could use a standard set/order of "fields", so it is not critical that the "field name" can be separated out. I'm also thinking that using some delimiter other than a line break may be useful. I know I could do this in Excel after exporting, but wondering if there is some way to have it be part of the export translator.
Thanks for any advice!
case 'design':
if (item.extra && item.extra.includes("Design:") {
value = item.extra.match(/Design:(.+)/)[1];
}
break;
And then include design in the exported fields.
Without some coding, there's no option other than splitting up Extra in Excel.
I mean who would want zillions of fields. It is just weird a program this powerful doesn't have this feature. A side note: I asked chatGPT and it said it was possible to customize it. Maybe it was possible in older versions?
And how do you tell zotero which translator to use after you create the new custom one? I think it wasn't mentioned here in the explanation.
Many thanks.
If you create a custom translator, you'd give it a separate title and that would be available in the export dialog after restarting Zotero. For a one-off, you can also just edit the existing CSV translator, though those changes would be overwritten after the next update of either Zotero or the CSV translator.
And FWIW, every time someone has mentioned chatGPT in a forum post here, they had been provided completely useless and false information by the LLM. This is true in your case as well. As you can tell by the posts in this thread going almost 10 years back, this has never been possible. Please don't use chatGPT for Zotero support.
Thanks