अपने Google Documents में तालिकाओं से Blank Rows को कैसे हटाएं

हेलो दोस्तों आज मैं आपको अपने Google Documents में Tables से Blank Rows Delete करना सिखाऊंगा। तो चलिए आज के कोड स्निपेट के साथ शुरुआत करते हैं। अलग-अलग समस्याओं को प्राप्त करना पूरी तरह से एक बहुत ही अलग अनुभव देता है। आज मैं आपके साथ जो कोड स्निपेट साझा करने जा रहा हूं, वह है अपने Google दस्तावेज़ों में तालिकाओं से रिक्त पंक्तियों को कैसे हटाएं।

अपने Google Documents में तालिकाओं से Blank Rows को कैसे हटाएं

दस्तावेज़ स्टूडियो ऐड-ऑन Google पत्रक और Google फ़ॉर्म प्रतिक्रियाओं में डेटा से Google डॉक्स बनाता है। आप Google डॉक्स में एक टेम्प्लेट बना सकते हैं, और ऐड-ऑन प्लेसहोल्डर्स को Google फ़ॉर्म से प्रतिक्रियाओं के साथ बदल देगा।

हालाँकि, इस पद्धति के परिणामस्वरूप उन उत्तरों के लिए तालिका में बड़ी संख्या में रिक्त पंक्तियाँ हो सकती हैं, जिनका Google फ़ॉर्म में कोई जवाब नहीं है। उदाहरण के लिए, यदि उपयोगकर्ता ने आयु प्रश्न का उत्तर नहीं दिया है, तो जेनरेट किए गए दस्तावेज़ में आयु प्रश्न के लिए एक पंक्ति शामिल होगी, लेकिन एक रिक्त मान के साथ।

आपको हमारे ट्रेंडिंग कोड स्निपेट भी पसंद आ सकते हैं

Remove Blank Rows in Google Docs

Google Apps स्क्रिप्ट की सहायता से, हम Google दस्तावेज़ के मुख्य भाग में शामिल सभी तालिकाओं को आसानी से खींच सकते हैं, तालिका में प्रत्येक पंक्ति के माध्यम से पुनरावृति कर सकते हैं और, यदि पंक्ति में कोई मान नहीं है, तो हम पंक्ति को सुरक्षित रूप से हटा सकते हैं टेबल।

अपने Google दस्तावेज़ के अंदर, टूल्स मेनू पर जाएं, स्क्रिप्ट संपादक चुनें और निम्न कोड पेस्ट करें। रन मेनू पर जाएं और स्क्रिप्ट चलाने के लिए ड्रॉपडाउन से RemoveBlankRows चुनें।

const removeBlankRows = () => {
  // Replace all whitespaces and check if the cell is blank
  const isBlankCell = (text = "") => !text.replace(/\s/g, "");

  // Does the row have any data other than in column 1 (header)
  const rowContainsData = (row) => {
    const columnCount = row.getNumCells();
    let rowHasFilledCell = false;
    for (
      let columnIndex = 1;
      columnIndex < columnCount && !rowHasFilledCell;
      columnIndex += 1
    ) {
      const cellValue = row.getCell(columnIndex).getText();
      if (!isBlankCell(cellValue)) {
        rowHasFilledCell = true;
      }
    }
    return rowHasFilledCell;
  };

  // Get the current document
  const document = DocumentApp.getActiveDocument();

  document
    .getBody()
    .getTables()
    .forEach((table) => {
      const rowCount = table.getNumRows();
      for (let rowIndex = rowCount - 1; rowIndex >= 0; rowIndex -= 1) {
        const row = table.getRow(rowIndex);
        if (isBlankCell(row.getText()) || !rowContainsData(row)) {
          // Remove the row from the Google Docs table
          table.removeRow(rowIndex);
        }
      }
    });

  // Flush and apply the changes
  document.saveAndClose();
};

Delete Blank Table Rows in Google Slides

आप अपनी Google स्लाइड प्रस्तुति में शामिल तालिकाओं से रिक्त पंक्तियों को निकालने के लिए उसी तकनीक का उपयोग कर सकते हैं।

If your Google Slides table uses merged cells, you may want to check merge status of a cell with the SlidesApp.CellMergeState.MERGED enum.

const removeBlankRows = () => {
  // Get the current document
  const presentation = SlidesApp.getActivePresentation();

  presentation.getSlides().forEach((slide) => {
    slide.getTables().forEach((table) => {
      const rowCount = table.getNumRows();
      for (let rowIndex = rowCount - 1; rowIndex >= 0; rowIndex -= 1) {
        const row = table.getRow(rowIndex);
        const cellCount = row.getNumCells();
        let rowHasFilledCell = false;
        for (
          let cellIndex = 1;
          cellIndex < cellCount && !rowHasFilledCell;
          cellIndex += 1
        ) {
          const cellValue = row.getCell(cellIndex).getText().asString();
          if (cellValue.trim() !== "") {
            rowHasFilledCell = true;
          }
        }

        if (!rowHasFilledCell) {
          row.remove();
        }
      }
    });
  });

  // Flush and apply the changes
  presentation.saveAndClose();
};

अगर आपको यह लेख पसंद आया हो तो कृपया कमेंट करें धन्यवाद

Leave a Comment