79115738

Date: 2024-10-22 21:15:33
Score: 1.5
Natty:
Report link

But the method seems to not run when applied to specific cells The following returns "API call to docs.documents.batchUpdate failed with error" Is it an API limitation or a wrong way to use it ?

function myFunction2() {
  const doc = DocumentApp.getActiveDocument();
  const documentId = doc.getId();
  const body = doc.getBody();
  const table = body.getTables()[0]; // Utiliser le premier tableau
  const index = body.getChildIndex(table);
  const tableStart = Docs.Documents.get(documentId).body.content[index + 1].startIndex;

  const numRows = table.getNumRows(); // Nombre de lignes dans le tableau

  const resource = {
    requests: []
  };

  // Créer des requêtes pour chaque cellule à partir de la colonne 2
  for (let rowIndex = 0; rowIndex < numRows; rowIndex++) {
    resource.requests.push({
      updateTableCellStyle: {
        tableCellLocation: {
          tableStartLocation: { index: tableStart },
          rowIndex: rowIndex,
          columnIndex: 1 // Commence à partir de la colonne 2 (index 1)
        },
        tableCellStyle: {
          borderBottom: {
            dashStyle: "DASH",
            width: { magnitude: 1, unit: "PT" },
            color: { color: { rgbColor: { blue: 1 } } }
          },
          borderLeft: {
            dashStyle: "SOLID",
            width: { magnitude: 1, unit: "PT" },
            color: { color: { rgbColor: { red: 1 } } }
          },
          borderRight: {
            dashStyle: "SOLID",
            width: { magnitude: 1, unit: "PT" },
            color: { color: { rgbColor: { red: 1 } } }
          }
        },
        fields: "borderBottom,borderLeft,borderRight"
      }
    });
  }

  try {
    Docs.Documents.batchUpdate(resource, documentId);
    Logger.log("Bordures mises à jour avec succès");
  } catch (e) {
    Logger.log("Erreur lors de la mise à jour : " + e.message);
  }
}
Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (1):
Posted by: Antoine Carimalo