Articles

LibreOffice and Google Sheets: headless conversion, transposing and bulk delete

· 1 min readlibreofficesoftdevel

LibreOffice: ODT to PDF conversion hangs in parallel

Converting documents from a PHP script with headless LibreOffice:

<?php
$cmd = 'export HOME=/tmp && cd /tmp && libreoffice --headless --convert-to pdf ~/16c6801746f3e924b254abb0089f0a0f.odt';
exec($cmd, $output, $retCode);

sometimes hangs when several conversions run at the same time. The problem is shared access to /tmp/.config and /tmp/.cache by the same user (apache) from different processes.

The solution: create a separate temporary subdirectory for every conversion and pass it as HOME.

LibreOffice Calc: transpose rows to columns

  1. Copy the cell range you want to transpose.
  2. Use Paste Special, and in the dialog check Paste all and Transpose.

Reference: Rotating Tables (Transposing) — LibreOffice Help

Google Sheets: delete many sheets at once

Open Tools > Script editor and run the function below. It deletes every sheet except the one named 21-01. To check what will be deleted, set a breakpoint at the console.log line and run it in debug mode first.

function DeleteAllSheets() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  console.log("Doc: " + ss.getName());
  var sheets = ss.getSheets();
  for (i = 0; i < sheets.length; i++) {
    switch (sheets[i].getSheetName()) {
      case "21-01":
        break;
      default:
        console.log("Delete: " + sheets[i].getSheetName());
        ss.deleteSheet(sheets[i]);
    }
  }
}

Source: spreadsheetpoint.com

All articles

See also

softdevelPL

Notuj swobodnie, niech AI zadba o resztę

Od zawsze, im więcej notowałem, tym mniej użyteczny stawał się mój notes, czy to papierowy, czy elektroniczny.

linuxsoftdevel

Linux server administration: a practical cheatsheet

Security checks, certificates, scheduled jobs, disks and backups, network diagnostics and basic system configuration — commands I use on Linux servers.

ovhlinuxsoftdevel

OVH Public Cloud: moving instances, adding disks and swapping the gateway

Moving virtual servers with the OpenStack client, attaching a new block storage disk, and replacing the private network gateway when the public IP is blacklisted.