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!
  • You can edit the export translator. https://www.zotero.org/support/dev/translators

    But it might be easier to just delete the unwanted columns in excel or something similar.
  • Thanks aurimas for the quick response.

    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 ...
  • It may be easier to edit the translator than you think.

    (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.
  • Thank you so much aurimas for spelling out the steps for editing the translator. I think I followed all the steps, but I got an error message while trying to export using the customized translator.

    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"
    ];
  • delete the comma at the end, i.e. after "tags/automatic"
  • Also missing quote before abstractNote
  • Thank you Adam and Aurimas. I corrected the errors and now it runs smoothly. Thank you both, and zuphilip too!
  • Hey @yinbin @aurimas @adamsmith, thanks for this informative thread on editing the zotero csv translator.

    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);
    }
    }
  • Thank you aurimas and others for providing the explanation fo how to customize this!

    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!
  • If you know some javascript, this would be hard. It'd be along the lines of

    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.
Sign In or Register to comment.