Làm cách nào để ghi vào Google Trang tính bằng Java?

Google Trang tính, một phần của Google Workspace, cho phép các nhóm tạo và chia sẻ bảng tính trực tuyến, đồng thời đã phát triển thành một công cụ kinh doanh được sử dụng rộng rãi. Đối với nhiều quy trình, tất cả những gì bạn cần là một bảng tính được chia sẻ và rô-bốt sử dụng nó

Bạn nên sử dụng thư viện tự động hóa nào?

RPA. Đám mây. Thư viện Google, một phần của RPA Framework, cho phép tương tác với Google Trang tính

Cài đặt và thiết lập

Rô-bốt của bạn sẽ cần xác thực với Google để có thể tương tác với bảng tính Google Trang tính, sử dụng khái niệm tài khoản dịch vụ. Sau đó, tài khoản được sử dụng bởi robot sẽ cần được thêm làm cộng tác viên vào (các) trang tính bạn muốn truy cập

Tạo tài khoản dịch vụ của Google

Để truy cập dữ liệu được lưu trữ trong Google Trang tính, bạn sẽ cần tạo một tài khoản dịch vụ và nhận một bộ thông tin đăng nhập OAuth2 từ Bảng điều khiển API của Google

  1. Truy cập Google APIs Console khi đã đăng nhập vào tài khoản Google của bạn
  2. Tạo một dự án mới và đặt tên cho nó

    Làm cách nào để ghi vào Google Trang tính bằng Java?

  3. Nhấp vào ENABLE APIS AND SERVICES
  4. Tìm và kích hoạt Google Sheet API

    Làm cách nào để ghi vào Google Trang tính bằng Java?

  5. Tạo thông tin đăng nhập mới cho Google Sheets API. Chọn
    *** Settings ***
    Documentation       An example robot that reads and writes data
    ..                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    
    Suite Setup         Init Sheets    service_account.json
    
    
    *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    
    *** Tasks ***
    Read values from the Google Sheet
        ${spreadsheet_content}=    Get Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        IF    "values" in ${spreadsheet_content}
            Log Many    ${spreadsheet_content["values"]}
        END
    
    Add values to the Google Sheet
        ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
        Insert Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        ..    ${values}
        ..    ROWS
    
    0 từ danh sách thả xuống và chọn
    *** Settings ***
    Documentation       An example robot that reads and writes data
    ..                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    
    Suite Setup         Init Sheets    service_account.json
    
    
    *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    
    *** Tasks ***
    Read values from the Google Sheet
        ${spreadsheet_content}=    Get Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        IF    "values" in ${spreadsheet_content}
            Log Many    ${spreadsheet_content["values"]}
        END
    
    Add values to the Google Sheet
        ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
        Insert Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        ..    ${values}
        ..    ROWS
    
    1. Sau đó bấm vào nút
    *** Settings ***
    Documentation       An example robot that reads and writes data
    ..                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    
    Suite Setup         Init Sheets    service_account.json
    
    
    *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    
    *** Tasks ***
    Read values from the Google Sheet
        ${spreadsheet_content}=    Get Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        IF    "values" in ${spreadsheet_content}
            Log Many    ${spreadsheet_content["values"]}
        END
    
    Add values to the Google Sheet
        ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
        Insert Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        ..    ${values}
        ..    ROWS
    
    2

    Làm cách nào để ghi vào Google Trang tính bằng Java?

  6. Trên màn hình tiếp theo, hãy chọn tên cho tài khoản dịch vụ của bạn, chỉ định vai trò của nó là
    *** Settings ***
    Documentation       An example robot that reads and writes data
    ..                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    
    Suite Setup         Init Sheets    service_account.json
    
    
    *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    
    *** Tasks ***
    Read values from the Google Sheet
        ${spreadsheet_content}=    Get Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        IF    "values" in ${spreadsheet_content}
            Log Many    ${spreadsheet_content["values"]}
        END
    
    Add values to the Google Sheet
        ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
        Insert Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        ..    ${values}
        ..    ROWS
    
    3->
    *** Settings ***
    Documentation       An example robot that reads and writes data
    ..                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    
    Suite Setup         Init Sheets    service_account.json
    
    
    *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    
    *** Tasks ***
    Read values from the Google Sheet
        ${spreadsheet_content}=    Get Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        IF    "values" in ${spreadsheet_content}
            Log Many    ${spreadsheet_content["values"]}
        END
    
    Add values to the Google Sheet
        ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
        Insert Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        ..    ${values}
        ..    ROWS
    
    4 và nhấp vào
    *** Settings ***
    Documentation       An example robot that reads and writes data
    ..                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    
    Suite Setup         Init Sheets    service_account.json
    
    
    *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    
    *** Tasks ***
    Read values from the Google Sheet
        ${spreadsheet_content}=    Get Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        IF    "values" in ${spreadsheet_content}
            Log Many    ${spreadsheet_content["values"]}
        END
    
    Add values to the Google Sheet
        ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
        Insert Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        ..    ${values}
        ..    ROWS
    
    5

    Làm cách nào để ghi vào Google Trang tính bằng Java?

  7. Tệp JSON thông tin đăng nhập sẽ được trình duyệt của bạn tải xuống

    Tệp thông tin xác thực cho phép mọi người truy cập tài nguyên đám mây của bạn, vì vậy bạn nên lưu trữ tệp này một cách an toàn.

  8. Tìm tệp đã tải xuống và đổi tên thành
    *** Settings ***
    Documentation       An example robot that reads and writes data
    ..                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    
    Suite Setup         Init Sheets    service_account.json
    
    
    *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    
    *** Tasks ***
    Read values from the Google Sheet
        ${spreadsheet_content}=    Get Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        IF    "values" in ${spreadsheet_content}
            Log Many    ${spreadsheet_content["values"]}
        END
    
    Add values to the Google Sheet
        ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
        Insert Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        ..    ${values}
        ..    ROWS
    
    6

Tạo một Google Sheet mới và thêm Tài khoản dịch vụ làm trình chỉnh sửa cho nó

  1. Tạo hoặc chọn Google Trang tính hiện có
  2. Mở tệp
    *** Settings ***
    Documentation       An example robot that reads and writes data
    ..                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    
    Suite Setup         Init Sheets    service_account.json
    
    
    *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    
    *** Tasks ***
    Read values from the Google Sheet
        ${spreadsheet_content}=    Get Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        IF    "values" in ${spreadsheet_content}
            Log Many    ${spreadsheet_content["values"]}
        END
    
    Add values to the Google Sheet
        ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
        Insert Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        ..    ${values}
        ..    ROWS
    
    6 và tìm thuộc tính
    *** Settings ***
    Documentation       An example robot that reads and writes data
    ..                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    
    Suite Setup         Init Sheets    service_account.json
    
    
    *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    
    *** Tasks ***
    Read values from the Google Sheet
        ${spreadsheet_content}=    Get Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        IF    "values" in ${spreadsheet_content}
            Log Many    ${spreadsheet_content["values"]}
        END
    
    Add values to the Google Sheet
        ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
        Insert Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        ..    ${values}
        ..    ROWS
    
    8
  3. Nhấp vào nút
    *** Settings ***
    Documentation       An example robot that reads and writes data
    ..                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    
    Suite Setup         Init Sheets    service_account.json
    
    
    *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    
    *** Tasks ***
    Read values from the Google Sheet
        ${spreadsheet_content}=    Get Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        IF    "values" in ${spreadsheet_content}
            Log Many    ${spreadsheet_content["values"]}
        END
    
    Add values to the Google Sheet
        ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
        Insert Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        ..    ${values}
        ..    ROWS
    
    9 ở trên cùng bên phải và thêm địa chỉ email của tài khoản dịch vụ với tư cách là người chỉnh sửa

    Làm cách nào để ghi vào Google Trang tính bằng Java?

    Nếu bạn chỉ muốn cho phép tài khoản có quyền đọc bảng tính, hãy chỉ định cho tài khoản đó vai trò

    *** Settings ***
    Documentation       An example robot that reads and writes data
    ..                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    
    Suite Setup         Init Sheets    service_account.json
    
    0

  4. Lưu ý ID của tài liệu Google Trang tính, có trong URL của nó, sau phần tử
    *** Settings ***
    Documentation       An example robot that reads and writes data
    ..                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    
    Suite Setup         Init Sheets    service_account.json
    
    1. Vì vậy, ví dụ: nếu URL của tài liệu của bạn là
    *** Settings ***
    Documentation       An example robot that reads and writes data
    ..                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    
    Suite Setup         Init Sheets    service_account.json
    
    2, thì ID sẽ là
    *** Settings ***
    Documentation       An example robot that reads and writes data
    ..                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    
    Suite Setup         Init Sheets    service_account.json
    
    3

ví dụ rô bốt

Bây giờ, việc thiết lập tài khoản của chúng ta đã hoàn tất, chúng ta sẽ xây dựng một rô-bốt

  1. Đọc dữ liệu hiện có từ Bảng tính Google và ghi lại dữ liệu đó
  2. Thêm nhiều dữ liệu hơn vào Google Sheet

Đây là bảng tính mẫu của chúng tôi với một số dữ liệu thử nghiệm

Làm cách nào để ghi vào Google Trang tính bằng Java?

Tạo một robot mới và thêm RPA. Đám mây. thư viện Google

  1. Tạo rô bốt mới bằng tiện ích mở rộng VS Code Robocorp
  2. Chỉnh sửa tệp trong robot của bạn như thế này
channels:
  - conda-forge
dependencies:
  - python=3.9.13
  - pip=22.1.2
  - pip:
      - rpaframework-google==6.0.0

Theo mặc định, gói

*** Settings ***
Documentation       An example robot that reads and writes data
..                 into a Google Sheet document.

Library             RPA.Cloud.Google

Suite Setup         Init Sheets    service_account.json
5 trong RPA Framework không được bao gồm do kích thước của các thành phần phụ thuộc. Bằng cách thêm dòng
*** Settings ***
Documentation       An example robot that reads and writes data
..                 into a Google Sheet document.

Library             RPA.Cloud.Google

Suite Setup         Init Sheets    service_account.json
6, bạn đang thêm nó một cách rõ ràng vào rô-bốt của mình

kịch bản robot

Quan trọng. Hãy nhớ thêm tệp

*** Settings ***
Documentation       An example robot that reads and writes data
..                 into a Google Sheet document.

Library             RPA.Cloud.Google

Suite Setup         Init Sheets    service_account.json


*** Variables ***
${SHEET_ID}         1234567890123abcf
${SHEET_RANGE}      Sheet1!A2:D10


*** Tasks ***
Read values from the Google Sheet
    ${spreadsheet_content}=    Get Sheet Values
    ..    ${SHEET_ID}
    ..    ${SHEET_RANGE}
    IF    "values" in ${spreadsheet_content}
        Log Many    ${spreadsheet_content["values"]}
    END

Add values to the Google Sheet
    ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
    Insert Sheet Values
    ..    ${SHEET_ID}
    ..    ${SHEET_RANGE}
    ..    ${values}
    ..    ROWS
6 vào thư mục gốc của rô-bốt của bạn

*** Settings ***
Documentation       An example robot that reads and writes data
..                 into a Google Sheet document.

Library             RPA.Cloud.Google

Suite Setup         Init Sheets    service_account.json


*** Variables ***
${SHEET_ID}         1234567890123abcf
${SHEET_RANGE}      Sheet1!A2:D10


*** Tasks ***
Read values from the Google Sheet
    ${spreadsheet_content}=    Get Sheet Values
    ..    ${SHEET_ID}
    ..    ${SHEET_RANGE}
    IF    "values" in ${spreadsheet_content}
        Log Many    ${spreadsheet_content["values"]}
    END

Add values to the Google Sheet
    ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
    Insert Sheet Values
    ..    ${SHEET_ID}
    ..    ${SHEET_RANGE}
    ..    ${values}
    ..    ROWS

Kịch bản robot giải thích

*** Settings ***
Documentation       An example robot that reads and writes data
..                 into a Google Sheet document.

Library             RPA.Cloud.Google

Suite Setup         Init Sheets    service_account.json

Trong phần

*** Settings ***
Documentation       An example robot that reads and writes data
..                 into a Google Sheet document.

Library             RPA.Cloud.Google

Suite Setup         Init Sheets    service_account.json
8, cài đặt
*** Settings ***
Documentation       An example robot that reads and writes data
..                 into a Google Sheet document.

Library             RPA.Cloud.Google

Suite Setup         Init Sheets    service_account.json
9 giải thích những gì rô-bốt của chúng tôi làm. Sau đó, chúng tôi thêm thư viện
*** Variables ***
${SHEET_ID}         1234567890123abcf
${SHEET_RANGE}      Sheet1!A2:D10
0. Cuối cùng, chúng tôi sử dụng cài đặt
*** Variables ***
${SHEET_ID}         1234567890123abcf
${SHEET_RANGE}      Sheet1!A2:D10
1 để khởi tạo ứng dụng khách Google Trang tính. Bằng cách này, nó sẽ chỉ được khởi tạo một lần, ngay cả khi robot của chúng tôi có nhiều nhiệm vụ

Bạn có thể tìm hiểu thêm về Thiết lập Suite và Teardown trong phần

*** Variables ***
${SHEET_ID}         1234567890123abcf
${SHEET_RANGE}      Sheet1!A2:D10

Trong phần

*** Variables ***
${SHEET_ID}         1234567890123abcf
${SHEET_RANGE}      Sheet1!A2:D10
2, chúng tôi đặt hai biến

  • *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    3 sẽ giữ id của tài liệu Google Trang tính của chúng tôi
  • *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    4 là phạm vi ô mà chúng tôi muốn làm việc, được viết bằng. Trong trường hợp của chúng tôi, khu vực chúng tôi quan tâm trong bảng tính của chúng tôi bắt đầu từ ô
    *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    5 và kết thúc bằng ô
    *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    6 của trang tính đầu tiên, vì vậy giá trị của chúng tôi sẽ là
    *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    7
*** Tasks ***
Read values from the Google Sheet
    ${spreadsheet_content}=    Get Sheet Values
    ..    ${SHEET_ID}
    ..    ${SHEET_RANGE}
    IF    "values" in ${spreadsheet_content}
        Log Many    ${spreadsheet_content["values"]}
    END

Trong nhiệm vụ này, chúng tôi đang đọc các hàng được chỉ định bởi

*** Variables ***
${SHEET_ID}         1234567890123abcf
${SHEET_RANGE}      Sheet1!A2:D10
4 của Google Trang tính của chúng tôi, được xác định bởi
*** Variables ***
${SHEET_ID}         1234567890123abcf
${SHEET_RANGE}      Sheet1!A2:D10
3, vào biến
*** Tasks ***
Read values from the Google Sheet
    ${spreadsheet_content}=    Get Sheet Values
    ..    ${SHEET_ID}
    ..    ${SHEET_RANGE}
    IF    "values" in ${spreadsheet_content}
        Log Many    ${spreadsheet_content["values"]}
    END
0

Từ khóa

*** Tasks ***
Read values from the Google Sheet
    ${spreadsheet_content}=    Get Sheet Values
    ..    ${SHEET_ID}
    ..    ${SHEET_RANGE}
    IF    "values" in ${spreadsheet_content}
        Log Many    ${spreadsheet_content["values"]}
    END
1 trả về một từ điển có mục
*** Tasks ***
Read values from the Google Sheet
    ${spreadsheet_content}=    Get Sheet Values
    ..    ${SHEET_ID}
    ..    ${SHEET_RANGE}
    IF    "values" in ${spreadsheet_content}
        Log Many    ${spreadsheet_content["values"]}
    END
2 chứa danh sách các hàng. Để làm cho rô-bốt mạnh mẽ hơn, chúng tôi kiểm tra sự tồn tại của khóa
*** Tasks ***
Read values from the Google Sheet
    ${spreadsheet_content}=    Get Sheet Values
    ..    ${SHEET_ID}
    ..    ${SHEET_RANGE}
    IF    "values" in ${spreadsheet_content}
        Log Many    ${spreadsheet_content["values"]}
    END
2 trước khi truy cập nó (một trang tính trống sẽ khiến các giá trị bị thiếu). Sử dụng từ khóa
*** Tasks ***
Read values from the Google Sheet
    ${spreadsheet_content}=    Get Sheet Values
    ..    ${SHEET_ID}
    ..    ${SHEET_RANGE}
    IF    "values" in ${spreadsheet_content}
        Log Many    ${spreadsheet_content["values"]}
    END
4, chúng tôi có thể ghi dữ liệu hàng đó

Làm cách nào để ghi vào Google Trang tính bằng Java?

*** Tasks ***
Add values to the Google Sheet
    ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
    Insert Sheet Values
    ..    ${SHEET_ID}
    ..    ${SHEET_RANGE}
    ..    ${values}
    ..    ROWS

Trong tác vụ này, chúng tôi thêm một số dữ liệu tùy ý vào một hàng mới trong bảng tính

  1. Sử dụng từ khóa
    *** Tasks ***
    Read values from the Google Sheet
        ${spreadsheet_content}=    Get Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        IF    "values" in ${spreadsheet_content}
            Log Many    ${spreadsheet_content["values"]}
        END
    
    5, chúng tôi tạo một biến có các giá trị cho hàng
  2. Chúng tôi chuyển các giá trị, id trang tính và phạm vi cho từ khóa
    *** Tasks ***
    Read values from the Google Sheet
        ${spreadsheet_content}=    Get Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        IF    "values" in ${spreadsheet_content}
            Log Many    ${spreadsheet_content["values"]}
        END
    
    6. Các giá trị sẽ được thêm vào hàng có sẵn đầu tiên bằng cách sử dụng tùy chọn thứ nguyên chính
    *** Tasks ***
    Read values from the Google Sheet
        ${spreadsheet_content}=    Get Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        IF    "values" in ${spreadsheet_content}
            Log Many    ${spreadsheet_content["values"]}
        END
    
    7

Làm cách nào để ghi vào Google Trang tính bằng Java?

Lưu trữ thông tin xác thực trong Control Room Vault

Bạn không bao giờ được đưa trực tiếp mật khẩu hoặc tệp thông tin xác thực vào mã rô-bốt của mình. Thay vì đọc thông tin đăng nhập từ tệp

*** Settings ***
Documentation       An example robot that reads and writes data
..                 into a Google Sheet document.

Library             RPA.Cloud.Google

Suite Setup         Init Sheets    service_account.json


*** Variables ***
${SHEET_ID}         1234567890123abcf
${SHEET_RANGE}      Sheet1!A2:D10


*** Tasks ***
Read values from the Google Sheet
    ${spreadsheet_content}=    Get Sheet Values
    ..    ${SHEET_ID}
    ..    ${SHEET_RANGE}
    IF    "values" in ${spreadsheet_content}
        Log Many    ${spreadsheet_content["values"]}
    END

Add values to the Google Sheet
    ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
    Insert Sheet Values
    ..    ${SHEET_ID}
    ..    ${SHEET_RANGE}
    ..    ${values}
    ..    ROWS
6, rô bốt của chúng tôi có thể sử dụng tính năng kho tiền của Phòng điều khiển

  1. Thiết lập rô-bốt của bạn để chạy trong Phòng điều khiển

  2. Tạo một kho tiền mới trong không gian làm việc của rô-bốt. Đặt tên cho nó là

    *** Tasks ***
    Read values from the Google Sheet
        ${spreadsheet_content}=    Get Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        IF    "values" in ${spreadsheet_content}
            Log Many    ${spreadsheet_content["values"]}
        END
    
    9

  3. Tạo một bí mật mới trong kho tiền. Cung cấp cho nó một khóa của

    *** Tasks ***
    Add values to the Google Sheet
        ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
        Insert Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        ..    ${values}
        ..    ROWS
    
    0 và dán nội dung của tệp
    *** Settings ***
    Documentation       An example robot that reads and writes data
    ..                 into a Google Sheet document.
    
    Library             RPA.Cloud.Google
    
    Suite Setup         Init Sheets    service_account.json
    
    
    *** Variables ***
    ${SHEET_ID}         1234567890123abcf
    ${SHEET_RANGE}      Sheet1!A2:D10
    
    
    *** Tasks ***
    Read values from the Google Sheet
        ${spreadsheet_content}=    Get Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        IF    "values" in ${spreadsheet_content}
            Log Many    ${spreadsheet_content["values"]}
        END
    
    Add values to the Google Sheet
        ${values}=    Evaluate    [["Mark", "The Monkey", 100000, 10000]]
        Insert Sheet Values
        ..    ${SHEET_ID}
        ..    ${SHEET_RANGE}
        ..    ${values}
        ..    ROWS
    
    6 vào trường giá trị

    Làm cách nào để viết vào trang tính Google bằng Java?

    Khởi động nhanh Java .
    Trên trang này
    mục tiêu
    điều kiện tiên quyết
    Thiết lập môi trường của bạn. Kích hoạt API. Ủy quyền thông tin đăng nhập cho một ứng dụng máy tính để bàn
    Chuẩn bị không gian làm việc
    thiết lập mẫu
    Chạy mẫu
    Bước tiếp theo

    Làm cách nào để chèn dữ liệu vào Google Sheets bằng JavaScript?

    $. ajax({ url. 'https. // bảng tính. Google. com/feeds/spreadsheets/private/full?alt=json-in-script&access_token=' + access_token, dataType. 'JSONP', thành công. function(data){ // sử dụng bảng tính } });

    Bạn có thể viết mã trong Google Trang tính không?

    Mặc dù Google Trang tính cung cấp nhiều chức năng cho mọi người, nhưng bạn cũng có thể viết mã gì đó phù hợp hơn với nhu cầu của mình . Và vì bạn có thể sử dụng lại mã nhiều lần, nó giúp bạn làm việc năng suất và hiệu quả hơn rất nhiều.