Hiển thị thanh tiến trình trong bản trình bày trên Google Trang trình bày
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Cấp độ lập trình: Trung cấp Thời lượng: 15 phút Loại dự án: Tiện ích bổ sung cho trình chỉnh sửa
Mục tiêu
Tìm hiểu chức năng của giải pháp.
Tìm hiểu chức năng của các dịch vụ Apps Script trong giải pháp.
Thiết lập tập lệnh.
Chạy tập lệnh.
Giới thiệu về giải pháp này
Hãy sử dụng giải pháp này để thêm thanh tiến trình vào cuối các trang trình bày trong bản trình bày của bạn.
Cách hoạt động
Tập lệnh này tính số trang trình bày trong bản trình bày và thêm hình chữ nhật vào cuối mỗi trang trình bày. Tập lệnh này tăng chiều rộng cho mỗi hình chữ nhật để hiển thị tiến trình trong các trang trình bày.
Dịch vụ Apps Script
Giải pháp này sử dụng dịch vụ sau:
Dịch vụ Trang trình bày – Lấy trang trình bày của một bản trình bày và thêm hình chữ nhật vào từng trang trình bày.
Điều kiện tiên quyết
Để sử dụng mẫu này, bạn cần có các điều kiện tiên quyết sau:
Tài khoản Google (có thể cần có sự phê duyệt của quản trị viên đối với tài khoản Google Workspace).
Một trình duyệt web có quyền truy cập Internet.
Thiết lập tập lệnh
Nhấp vào nút sau để tạo bản sao của bản trình bày Thanh tiến trình trên Trang trình bày. Dự án Apps Script cho giải pháp này được đính kèm vào bản trình bày.
Tạo bản sao
Trong bản trình bày, hãy nhấp vào Extensions (Tiện ích)
>Progress bar (Thanh tiến trình) >Show progress bar (Hiện thanh tiến trình).
Khi được nhắc, hãy cho phép tập lệnh chạy.
Nếu màn hình đồng ý OAuth hiển thị cảnh báo Ứng dụng này chưa được xác minh, hãy tiếp tục bằng cách chọn Nâng cao>Chuyển đến {Project Name} (không an toàn).
Một lần nữa, hãy nhấp vào Extensions (Tiện ích) >Progress bar (Thanh tiến trình) >Show progress bar (Hiện thanh tiến trình).
Để xoá thanh tiến trình, hãy nhấp vào Extensions (Tiện ích)
>Progress bar (Thanh tiến trình) >Hide progress bar (Ẩn thanh tiến trình).
Xem lại mã
Để xem xét mã Apps Script cho giải pháp này, hãy nhấp vào Xem mã nguồn bên dưới:
/** * @OnlyCurrentDoc Adds progress bars to a presentation. */constBAR_ID='PROGRESS_BAR_ID';constBAR_HEIGHT=10;// px/** * Runs when the add-on is installed. * @param {object} e The event parameter for a simple onInstall trigger. To * determine which authorization mode (ScriptApp.AuthMode) the trigger is * running in, inspect e.authMode. (In practice, onInstall triggers always * run in AuthMode.FULL, but onOpen triggers may be AuthMode.LIMITED or * AuthMode.NONE.) */functiononInstall(e){onOpen();}/** * Trigger for opening a presentation. * @param {object} e The onOpen event. */functiononOpen(e){SlidesApp.getUi().createAddonMenu().addItem('Showprogressbar','createBars').addItem('Hideprogressbar','deleteBars').addToUi();}/** * Create a rectangle on every slide with different bar widths. */functioncreateBars(){deleteBars();// Delete any existing progress barsconstpresentation=SlidesApp.getActivePresentation();constslides=presentation.getSlides();for(leti=0;i < slides.length;++i){constratioComplete=(i/(slides.length-1));constx=0;consty=presentation.getPageHeight()-BAR_HEIGHT;constbarWidth=presentation.getPageWidth()*ratioComplete;if(barWidth > 0){constbar=slides[i].insertShape(SlidesApp.ShapeType.RECTANGLE,x,y,barWidth,BAR_HEIGHT);bar.getBorder().setTransparent();bar.setLinkUrl(BAR_ID);}}}/** * Deletes all progress bar rectangles. */functiondeleteBars(){constpresentation=SlidesApp.getActivePresentation();constslides=presentation.getSlides();for(leti=0;i < slides.length;++i){constelements=slides[i].getPageElements();for(constelofelements){if(el.getPageElementType()===SlidesApp.PageElementType.SHAPE&&
el.asShape().getLink()&&
el.asShape().getLink().getUrl()===BAR_ID){el.remove();}}}}
Người đóng góp
Mẫu này do Google duy trì với sự trợ giúp của Chuyên gia phát triển của Google.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-06-05 UTC."],[[["This Google Apps Script solution adds a progress bar to the bottom of Google Slides presentations to visually track progress through the slides."],["The script uses the Slides service to calculate the number of slides, add a rectangle shape to each slide, and dynamically adjust the rectangle's width to represent progress."],["Users can easily install the script by making a copy of the provided presentation and authorizing the script to access their Google Slides."],["The progress bar can be shown or hidden using the \"Progress bar\" menu found under \"Extensions\" in Google Slides after installation."],["Developers can review and modify the source code, which is publicly available on GitHub, for customization or further development."]]],["This solution adds a progress bar to Google Slides presentations using Apps Script. The script calculates the total slides and adds a rectangle to the bottom of each slide, increasing the rectangle's width to visually represent progress. Users copy a sample presentation, authorize the script, and then run it to create or remove the progress bars via the \"Extensions\" menu. It utilizes the Slides service to manipulate slides and shapes, adding and deleting these elements.\n"]]