Hey everyone, I’m trying to figure out if there’s a way to count words for each section in a Google Docs document using an addon. I’m looking for something that can break down the word count by headings.
I’d love to have a feature that shows the word count for each section, maybe in a sidebar or somewhere easy to see. Has anyone come across an addon that can do this? Or is there a way to set it up?
It would be super helpful for organizing my writing and keeping track of section lengths. If anyone has experience with this or knows of a solution, I’d really appreciate the help!
// Example code snippet (not functional, just for illustration)
function countWordsByHeading() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var headings = body.getParagraphs().filter(p => p.getHeading() != DocumentApp.ParagraphHeading.NORMAL);
headings.forEach(heading => {
var sectionContent = getSectionContent(heading);
var wordCount = countWords(sectionContent);
Logger.log(heading.getText() + ': ' + wordCount + ' words');
});
}
Does anyone know if something like this is possible? Thanks in advance for any suggestions!
As someone who’s wrestled with this exact problem, I can share what worked for me. I ended up using a combination of Google Apps Script and a custom sidebar. It took some trial and error, but I managed to create a solution that counts words by heading.
The key was to iterate through the document, identify heading styles, and then count words until the next heading. I displayed the results in a custom sidebar, which updates when you click a button.
It’s not as straightforward as an off-the-shelf addon, but it gives you full control. The learning curve was steep, but now I can tweak it to fit different document structures. Plus, it’s satisfying to have a tailor-made tool.
If you’re comfortable with a bit of coding, I’d be happy to share more details on my implementation. It’s become an indispensable part of my writing workflow.
hey laura, i’ve used an addon called ‘Word Count Tool’ that kinda does what ur looking for. it doesn’t break it down by headings exactly, but it can count words in selected sections. might be worth checkin out? not perfect but could help u keep track of section lengths. hope that helps!
I’ve encountered a similar need in my work, and while I haven’t found an addon that does exactly what you’re looking for, I’ve developed a workaround using Google Apps Script. It involves creating a custom function that iterates through the document, identifying headings and calculating word counts for each section. The script can then display results in a sidebar.
Here’s a simplified version of the approach:
function countWordsByHeading() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();
var elements = body.getChildren();
var currentHeading = '';
var wordCount = 0;
var results = {};
for (var i = 0; i < elements.length; i++) {
var element = elements[i];
if (element.getType() == DocumentApp.ElementType.PARAGRAPH) {
var paragraph = element.asParagraph();
if (paragraph.getHeading() != DocumentApp.ParagraphHeading.NORMAL) {
if (currentHeading) {
results[currentHeading] = wordCount;
}
currentHeading = paragraph.getText();
wordCount = 0;
} else {
wordCount += paragraph.getText().split(' ').length;
}
}
}
results[currentHeading] = wordCount;
Logger.log(results);
}
This script isn’t perfect and might need some tweaking, but it could serve as a starting point. You’d need to create a custom menu or button to run the script and display the results. It’s a bit technical, but it might be a solution if you can’t find a suitable addon.