Hướng dẫn is excel api free? - api excel có miễn phí không?

Bỏ qua nội dung chính

Show

Trình duyệt này không còn được hỗ trợ.

Nội dung chính ShowShow

  • Tổng quan về API JavaScript Excel
  • Trong bài viết này
  • Tìm hiểu các khái niệm mô hình đối tượng
  • Tìm hiểu khả năng API
  • Thử các mẫu mã trong phòng thí nghiệm tập lệnh
  • Nhận xét
  • Làm việc với bảng tính bằng cách sử dụng API JavaScript Excel
  • Trong bài viết này
  • Tìm hiểu các khái niệm mô hình đối tượng
  • Tìm hiểu khả năng API
  • Thử các mẫu mã trong phòng thí nghiệm tập lệnh
  • Nhận xét
  • Làm việc với bảng tính bằng cách sử dụng API JavaScript Excel
  • Nhận bảng tính
  • Nhận bảng tính tích cực
  • Đặt bảng tính hoạt động
  • Bảng tính tham chiếu theo vị trí tương đối
  • Nhận bảng tính đầu tiên
  • Nhận bảng tính cuối cùng
  • Nhận bảng tính tiếp theo
  • Nhận bảng tính trước đó
  • Thêm một bảng tính
  • Sao chép một bảng tính hiện có
  • Xóa một bảng tính
  • Đổi tên một bảng tính
  • Di chuyển một bảng tính
  • Đặt khả năng hiển thị bảng tính
  • Ẩn một bảng tính
  • Xé một bảng tính
  • Nhận một ô duy nhất trong một bảng tính
  • Phát hiện thay đổi dữ liệu
  • Phát hiện thay đổi công thức
  • Xử lý các sự kiện sắp xếp
  • Nhận xét
  • Làm việc với bảng tính bằng cách sử dụng API JavaScript Excel
  • Nhận bảng tính
  • Nhận bảng tính tích cực
  • Đặt bảng tính hoạt động

Bảng tính tham chiếu theo vị trí tương đối

Tổng quan về API JavaScript Excel

  • Nhận bảng tính đầu tiên
  • Nhận bảng tính cuối cùng
  • Nhận bảng tính tiếp theo

Trong bài viết này

Nhận bảng tính trước đó

  • Thêm một bảng tính: These are the application-specific APIs for Excel. Introduced with Office 2016, the Excel JavaScript API provides strongly-typed objects that you can use to access worksheets, ranges, tables, charts, and more.

  • Sao chép một bảng tính hiện có: Introduced with Office 2013, the Common API can be used to access features such as UI, dialogs, and client settings that are common across multiple types of Office applications.

Xóa một bảng tính

Tìm hiểu các khái niệm mô hình đối tượng

Tìm hiểu khả năng API

Thử các mẫu mã trong phòng thí nghiệm tập lệnh

Tìm hiểu khả năng API

Thử các mẫu mã trong phòng thí nghiệm tập lệnh

  • Nhận xét
  • Làm việc với bảng tính bằng cách sử dụng API JavaScript Excel
  • Nhận bảng tính
  • Nhận bảng tính tích cực
  • Đặt bảng tính hoạt động
  • Bảng tính tham chiếu theo vị trí tương đối
  • Nhận bảng tính đầu tiên
  • Nhận bảng tính cuối cùng
  • Nhận bảng tính tiếp theo
  • Nhận bảng tính trước đó
  • Thêm một bảng tính
  • Sao chép một bảng tính hiện có
  • Xóa một bảng tính
  • Đổi tên một bảng tính

Di chuyển một bảng tính

Thử các mẫu mã trong phòng thí nghiệm tập lệnh

Nhận xét

Làm việc với bảng tính bằng cách sử dụng API JavaScript Excel

  • Nhận bảng tính
  • Nhận bảng tính tích cực
  • Đặt bảng tính hoạt động
  • Bảng tính tham chiếu theo vị trí tương đối
  • Nhận bảng tính đầu tiên

Nhận xét

Làm việc với bảng tính bằng cách sử dụng API JavaScript Excel

Nhận bảng tính

Trình duyệt này không còn được hỗ trợ.

Bảng tính tham chiếu theo vị trí tương đối

Làm việc với bảng tính bằng cách sử dụng API JavaScript Excel

  • Bài báo
  • 07/21/2022
  • 15 phút để đọc

Trong bài viết này

Bài viết này cung cấp các mẫu mã cho thấy cách thực hiện các tác vụ phổ biến với bảng tính bằng cách sử dụng API JavaScript Excel. Để biết danh sách đầy đủ các thuộc tính và phương thức mà các đối tượng

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
7 và
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
8 hỗ trợ, hãy xem đối tượng bảng tính (API JavaScript cho Excel) và đối tượng bảng tính (API JavaScript cho Excel).

Ghi chú

Thông tin trong bài viết này chỉ áp dụng cho bảng tính thông thường; Nó không áp dụng cho các tấm "biểu đồ" hoặc các tấm "macro".

Nhận bảng tính

Mẫu mã sau đây nhận được bộ sưu tập các bảng tính, tải thuộc tính

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
9 của mỗi bảng tính và viết một tin nhắn vào bảng điều khiển.
await Excel.run(async (context) => {
    let sheets = context.workbook.worksheets;
    sheets.load("items/name");

    await context.sync();
    
    if (sheets.items.length > 1) {
        console.log(`There are ${sheets.items.length} worksheets in the workbook:`);
    } else {
        console.log(`There is one worksheet in the workbook:`);
    }

    sheets.items.forEach(function (sheet) {
        console.log(sheet.name);
    });
});

Ghi chú

Thông tin trong bài viết này chỉ áp dụng cho bảng tính thông thường; Nó không áp dụng cho các tấm "biểu đồ" hoặc các tấm "macro".

Nhận bảng tính

Mẫu mã sau đây nhận được bộ sưu tập các bảng tính, tải thuộc tính

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
9 của mỗi bảng tính và viết một tin nhắn vào bảng điều khiển.
await Excel.run(async (context) => {
    let sheets = context.workbook.worksheets;
    sheets.load("items/name");

    await context.sync();
    
    if (sheets.items.length > 1) {
        console.log(`There are ${sheets.items.length} worksheets in the workbook:`);
    } else {
        console.log(`There is one worksheet in the workbook:`);
    }

    sheets.items.forEach(function (sheet) {
        console.log(sheet.name);
    });
});

Thuộc tính

await Excel.run(async (context) => { let firstSheet = context.workbook.worksheets.getFirst(); firstSheet.load("name"); await context.sync(); console.log(`The name of the first worksheet is "${firstSheet.name}"`); }); 0 của bảng tính xác định duy nhất bảng tính trong một sổ làm việc nhất định và giá trị của nó sẽ vẫn giữ nguyên ngay cả khi bảng tính được đổi tên hoặc di chuyển. Khi một bảng tính bị xóa khỏi sổ làm việc ở Excel trên Mac, await Excel.run(async (context) => { let firstSheet = context.workbook.worksheets.getFirst(); firstSheet.load("name"); await context.sync(); console.log(`The name of the first worksheet is "${firstSheet.name}"`); }); 0 của bảng tính bị xóa có thể được chỉ định lại vào một bảng tính mới được tạo sau đó.

Nhận bảng tính tích cực

Mẫu mã sau đây nhận được bảng tính hoạt động, tải thuộc tính Sample, loads its
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
9 property, and writes a message to the console. If there is no worksheet with that name, the
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
4 method throws an
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
5 error.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});

await Excel.run(async (context) => { let sheet = context.workbook.worksheets.getItem("Sample"); sheet.activate(); sheet.load("name"); await context.sync(); console.log(`The active worksheet is "${sheet.name}"`); }); 9 của nó và ghi một thông báo vào bảng điều khiển.await Excel.run(async (context) => { let sheet = context.workbook.worksheets.getActiveWorksheet(); sheet.load("name"); await context.sync(); console.log(`The active worksheet is "${sheet.name}"`); });

Đặt bảng tính hoạt động

Mẫu mã sau đây đặt bảng tính hoạt động vào bảng tính có tên mẫu, tải thuộc tính

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
9 của nó và ghi tin nhắn vào bảng điều khiển. Nếu không có bảng tính với tên đó, phương thức
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
4 đã gây ra lỗi
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
5.Sample, loads its
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
9 property, and writes a message to the console. If there is no worksheet with that name, the
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
4 method throws an
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
5 error.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});

Bảng tính tham chiếu theo vị trí tương đối

Những ví dụ này cho thấy cách tham khảo một bảng tính theo vị trí tương đối của nó.

Nhận bảng tính đầu tiên

Mẫu mã sau đây nhận được bảng tính đầu tiên trong sổ làm việc, tải thuộc tính

await Excel.run(async (context) => { let sheet = context.workbook.worksheets.getItem("Sample"); sheet.activate(); sheet.load("name"); await context.sync(); console.log(`The active worksheet is "${sheet.name}"`); }); 9 của nó và viết một tin nhắn vào bảng điều khiển.await Excel.run(async (context) => { let firstSheet = context.workbook.worksheets.getFirst(); firstSheet.load("name"); await context.sync(); console.log(`The name of the first worksheet is "${firstSheet.name}"`); });

Nhận bảng tính cuối cùng

Mẫu mã sau đây nhận được bảng tính cuối cùng trong sổ làm việc, tải thuộc tính

await Excel.run(async (context) => { let sheet = context.workbook.worksheets.getItem("Sample"); sheet.activate(); sheet.load("name"); await context.sync(); console.log(`The active worksheet is "${sheet.name}"`); }); 9 của nó và viết một tin nhắn vào bảng điều khiển.await Excel.run(async (context) => { let sheet = context.workbook.worksheets.getItem("Sample"); sheet.activate(); sheet.load("name"); await context.sync(); console.log(`The active worksheet is "${sheet.name}"`); }); 8

Nhận bảng tính tiếp theo

Mẫu mã sau đây nhận được bảng tính theo bảng tính hoạt động trong sổ làm việc, tải thuộc tính

await Excel.run(async (context) => { let sheet = context.workbook.worksheets.getItem("Sample"); sheet.activate(); sheet.load("name"); await context.sync(); console.log(`The active worksheet is "${sheet.name}"`); }); 9 của nó và viết một thông báo vào bảng điều khiển. Nếu không có bảng tính sau bảng tính đang hoạt động, phương thức await Excel.run(async (context) => { let firstSheet = context.workbook.worksheets.getFirst(); firstSheet.load("name"); await context.sync(); console.log(`The name of the first worksheet is "${firstSheet.name}"`); }); 9 đã gây ra lỗi await Excel.run(async (context) => { let firstSheet = context.workbook.worksheets.getFirst(); firstSheet.load("name"); await context.sync(); console.log(`The name of the first worksheet is "${firstSheet.name}"`); }); 5.await Excel.run(async (context) => { let sheet = context.workbook.worksheets.getItem("Sample"); sheet.activate(); sheet.load("name"); await context.sync(); console.log(`The active worksheet is "${sheet.name}"`); }); 2

Nhận bảng tính trước đó

Mẫu mã sau đây nhận được bảng tính trước bảng tính hoạt động trong sổ làm việc, tải thuộc tính Sample to the workbook, loads its
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
9 and
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
85 properties, and writes a message to the console. The new worksheet is added after all existing worksheets.
await Excel.run(async (context) => {
    let sheets = context.workbook.worksheets;
    sheets.load("items/name");

    await context.sync();
    
    if (sheets.items.length > 1) {
        console.log(`There are ${sheets.items.length} worksheets in the workbook:`);
    } else {
        console.log(`There is one worksheet in the workbook:`);
    }

    sheets.items.forEach(function (sheet) {
        console.log(sheet.name);
    });
});
1

await Excel.run(async (context) => { let sheet = context.workbook.worksheets.getItem("Sample"); sheet.activate(); sheet.load("name"); await context.sync(); console.log(`The active worksheet is "${sheet.name}"`); }); 9 của nó và viết một thông báo vào bảng điều khiển. Nếu không có bảng tính trước bảng tính hoạt động, phương thức await Excel.run(async (context) => { let sheet = context.workbook.worksheets.getItem("Sample"); sheet.activate(); sheet.load("name"); await context.sync(); console.log(`The active worksheet is "${sheet.name}"`); }); 82 đã gây ra lỗi await Excel.run(async (context) => { let firstSheet = context.workbook.worksheets.getFirst(); firstSheet.load("name"); await context.sync(); console.log(`The name of the first worksheet is "${firstSheet.name}"`); }); 5.await Excel.run(async (context) => { let sheet = context.workbook.worksheets.getItem("Sample"); sheet.activate(); sheet.load("name"); await context.sync(); console.log(`The active worksheet is "${sheet.name}"`); }); 6

Thêm một bảng tínhMySheet (2)).
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
86 can take two parameters, both of which are optional:
  • Mẫu mã sau đây thêm một bảng tính mới có tên mẫu vào sổ làm việc, tải các thuộc tính
  • await Excel.run(async (context) => {
        let sheet = context.workbook.worksheets.getItem("Sample");
        sheet.activate();
        sheet.load("name");
    
        await context.sync();
        console.log(`The active worksheet is "${sheet.name}"`);
    });
    
    9 và
    await Excel.run(async (context) => {
        let sheet = context.workbook.worksheets.getItem("Sample");
        sheet.activate();
        sheet.load("name");
    
        await context.sync();
        console.log(`The active worksheet is "${sheet.name}"`);
    });
    
    85 của nó và ghi một thông báo vào bảng điều khiển. Bảng tính mới được thêm vào sau tất cả các bảng tính hiện có.Sample to the workbook, loads its
    await Excel.run(async (context) => {
        let sheet = context.workbook.worksheets.getItem("Sample");
        sheet.activate();
        sheet.load("name");
    
        await context.sync();
        console.log(`The active worksheet is "${sheet.name}"`);
    });
    
    9 and
    await Excel.run(async (context) => {
        let sheet = context.workbook.worksheets.getItem("Sample");
        sheet.activate();
        sheet.load("name");
    
        await context.sync();
        console.log(`The active worksheet is "${sheet.name}"`);
    });
    
    85 properties, and writes a message to the console. The new worksheet is added after all existing worksheets.
    await Excel.run(async (context) => {
        let sheets = context.workbook.worksheets;
        sheets.load("items/name");
    
        await context.sync();
        
        if (sheets.items.length > 1) {
            console.log(`There are ${sheets.items.length} worksheets in the workbook:`);
        } else {
            console.log(`There is one worksheet in the workbook:`);
        }
    
        sheets.items.forEach(function (sheet) {
            console.log(sheet.name);
        });
    });
    
    1

Sao chép một bảng tính hiện có

await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
0

await Excel.run(async (context) => { let sheet = context.workbook.worksheets.getItem("Sample"); sheet.activate(); sheet.load("name"); await context.sync(); console.log(`The active worksheet is "${sheet.name}"`); }); 86 thêm một bảng tính mới là bản sao của một bảng tính hiện có. Tên của bảng tính mới sẽ có một số được thêm vào cuối, theo cách phù hợp với việc sao chép bảng tính thông qua UI Excel (ví dụ: MySheet (2)). await Excel.run(async (context) => { let sheet = context.workbook.worksheets.getItem("Sample"); sheet.activate(); sheet.load("name"); await context.sync(); console.log(`The active worksheet is "${sheet.name}"`); }); 86 có thể lấy hai tham số, cả hai đều là tùy chọn:MySheet (2)). await Excel.run(async (context) => { let sheet = context.workbook.worksheets.getItem("Sample"); sheet.activate(); sheet.load("name"); await context.sync(); console.log(`The active worksheet is "${sheet.name}"`); }); 86 can take two parameters, both of which are optional:

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
88 - Một bảng tính enum chỉ định nơi trong sổ làm việc mà bảng tính mới sẽ được thêm vào.

await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
1

Ghi chú

Thông tin trong bài viết này chỉ áp dụng cho bảng tính thông thường; Nó không áp dụng cho các tấm "biểu đồ" hoặc các tấm "macro".

Nhận bảng tính

Mẫu mã sau đây nhận được bộ sưu tập các bảng tính, tải thuộc tính

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
9 của mỗi bảng tính và viết một tin nhắn vào bảng điều khiển.
await Excel.run(async (context) => {
    let sheets = context.workbook.worksheets;
    sheets.load("items/name");

    await context.sync();
    
    if (sheets.items.length > 1) {
        console.log(`There are ${sheets.items.length} worksheets in the workbook:`);
    } else {
        console.log(`There is one worksheet in the workbook:`);
    }

    sheets.items.forEach(function (sheet) {
        console.log(sheet.name);
    });
});
New Name.

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
0

Thuộc tính

await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
0 của bảng tính xác định duy nhất bảng tính trong một sổ làm việc nhất định và giá trị của nó sẽ vẫn giữ nguyên ngay cả khi bảng tính được đổi tên hoặc di chuyển. Khi một bảng tính bị xóa khỏi sổ làm việc ở Excel trên Mac,
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
0 của bảng tính bị xóa có thể được chỉ định lại vào một bảng tính mới được tạo sau đó.

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
1

Đặt khả năng hiển thị bảng tính

Những ví dụ này cho thấy cách đặt tầm nhìn của một bảng tính.

Ẩn một bảng tính

Mẫu mã sau đây đặt khả năng hiển thị của bảng tính được đặt tên là ẩn, tải thuộc tính

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
9 của nó và ghi một thông báo vào bảng điều khiển.Sample to hidden, loads its
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
9 property, and writes a message to the console.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
2Sample to hidden, loads its
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
9 property, and writes a message to the console.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
2

Xé một bảng tính

Mẫu mã sau đây đặt khả năng hiển thị của bảng tính được đặt tên là hiển thị, tải thuộc tính

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
9 của nó và ghi một thông báo vào bảng điều khiển.Sample to visible, loads its
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
9 property, and writes a message to the console.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
3Sample to visible, loads its
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
9 property, and writes a message to the console.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
3

Nhận một ô duy nhất trong một bảng tính

Mẫu mã sau đây có được ô nằm trong hàng 2, cột 5 của bảng tính có tên mẫu, tải các thuộc tính

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
26 và
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
27 của nó và ghi một thông báo vào bảng điều khiển. Các giá trị được truyền vào phương thức
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
28 là số hàng và số cột được chỉ số bằng không cho ô đang được truy xuất.Sample, loads its
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
26 and
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
27 properties, and writes a message to the console. The values that are passed into the
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
28 method are the zero-indexed row number and column number for the cell that is being retrieved.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
4Sample, loads its
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
26 and
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
27 properties, and writes a message to the console. The values that are passed into the
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
28 method are the zero-indexed row number and column number for the cell that is being retrieved.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
4

Phát hiện thay đổi dữ liệu

Bổ trợ của bạn có thể cần phản ứng với người dùng thay đổi dữ liệu trong bảng tính. Để phát hiện những thay đổi này, bạn có thể đăng ký một trình xử lý sự kiện cho sự kiện

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
29 của bảng tính. Trình xử lý sự kiện cho sự kiện
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
29 nhận được một đối tượng WorkSheetchangedEventArgs khi sự kiện bị bắn.

Đối tượng

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
61 cung cấp thông tin về các thay đổi và nguồn. Vì
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
29 bắn khi định dạng hoặc giá trị của các thay đổi dữ liệu, nên có thể hữu ích khi kiểm tra bổ trợ của bạn nếu các giá trị đã thực sự thay đổi. Tài sản
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
63 gói gọn thông tin này như một thay đổi. Mẫu mã sau đây cho thấy cách hiển thị các giá trị trước và sau và các loại ô đã được thay đổi.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
5

Phát hiện thay đổi công thức

Bổ trợ của bạn có thể theo dõi các thay đổi thành công thức trong bảng tính. Điều này rất hữu ích khi một bảng tính được kết nối với cơ sở dữ liệu bên ngoài. Khi công thức thay đổi trong bảng tính, sự kiện trong kịch bản này kích hoạt các bản cập nhật tương ứng trong cơ sở dữ liệu bên ngoài.

Để phát hiện các thay đổi đối với các công thức, hãy đăng ký một trình xử lý sự kiện cho sự kiện onformulachanged của một bảng tính. Trình xử lý sự kiện cho sự kiện

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
64 nhận được một đối tượng WorkSheetFormulachangedEventArgs khi sự kiện nổ ra.

Quan trọng

Sự kiện

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
64 phát hiện khi một công thức tự thay đổi, không phải giá trị dữ liệu do tính toán của công thức.

Mẫu mã sau đây cho thấy cách đăng ký trình xử lý sự kiện

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
64, sử dụng đối tượng
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
67 để truy xuất mảng formulAdetails của công thức đã thay đổi và sau đó in ra chi tiết về công thức đã thay đổi với các thuộc tính FormulachAchAtedEventDetail.

Ghi chú

Mẫu mã này chỉ hoạt động khi một công thức duy nhất được thay đổi.

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
6

Xử lý các sự kiện sắp xếp

Các sự kiện

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
68 và
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
69 cho biết khi nào bất kỳ dữ liệu bảng tính nào được sắp xếp. Các sự kiện này được kết nối với các đối tượng
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
7 riêng lẻ và với
await Excel.run(async (context) => {
    let sheets = context.workbook.worksheets;
    sheets.load("items/name");

    await context.sync();
    
    if (sheets.items.length > 1) {
        console.log(`There are ${sheets.items.length} worksheets in the workbook:`);
    } else {
        console.log(`There is one worksheet in the workbook:`);
    }

    sheets.items.forEach(function (sheet) {
        console.log(sheet.name);
    });
});
11 của sổ làm việc. Họ bắn cho dù việc sắp xếp được thực hiện theo chương trình hoặc thủ công thông qua giao diện người dùng Excel.

Ghi chú

Mẫu mã này chỉ hoạt động khi một công thức duy nhất được thay đổi.

Xử lý các sự kiện sắp xếp

Các sự kiện

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
68 và
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
69 cho biết khi nào bất kỳ dữ liệu bảng tính nào được sắp xếp. Các sự kiện này được kết nối với các đối tượng
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
7 riêng lẻ và với
await Excel.run(async (context) => {
    let sheets = context.workbook.worksheets;
    sheets.load("items/name");

    await context.sync();
    
    if (sheets.items.length > 1) {
        console.log(`There are ${sheets.items.length} worksheets in the workbook:`);
    } else {
        console.log(`There is one worksheet in the workbook:`);
    }

    sheets.items.forEach(function (sheet) {
        console.log(sheet.name);
    });
});
11 của sổ làm việc. Họ bắn cho dù việc sắp xếp được thực hiện theo chương trình hoặc thủ công thông qua giao diện người dùng Excel.

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
68 Hỏa hoạn khi các cột được sắp xếp là kết quả của hoạt động sắp xếp từ trái sang phải.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
69 Hỏa hoạn khi các hàng được sắp xếp là kết quả của hoạt động sắp xếp từ trên xuống dưới. Sắp xếp một bảng bằng menu thả xuống trên tiêu đề cột dẫn đến một sự kiện
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
69. Sự kiện tương ứng với những gì đang di chuyển, không phải là những gì đang được coi là tiêu chí sắp xếp.Q1" (the values in "B"), the following highlighted rows are returned by
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
00.Q1" (the values in "B"), the following highlighted rows are returned by
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
00.

Các sự kiện

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
68 và
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
69 cho biết khi nào bất kỳ dữ liệu bảng tính nào được sắp xếp. Các sự kiện này được kết nối với các đối tượng
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
7 riêng lẻ và với
await Excel.run(async (context) => {
    let sheets = context.workbook.worksheets;
    sheets.load("items/name");

    await context.sync();
    
    if (sheets.items.length > 1) {
        console.log(`There are ${sheets.items.length} worksheets in the workbook:`);
    } else {
        console.log(`There is one worksheet in the workbook:`);
    }

    sheets.items.forEach(function (sheet) {
        console.log(sheet.name);
    });
});
11 của sổ làm việc. Họ bắn cho dù việc sắp xếp được thực hiện theo chương trình hoặc thủ công thông qua giao diện người dùng Excel.Quinces" (the values in "4") on the original data, the following highlighted columns are returned by
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
01.

Các hình ảnh sau đây cho thấy các phạm vi được trả về bởi thuộc tính

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
26 cho các sự kiện sắp xếp. Đầu tiên, đây là dữ liệu mẫu trước khi sắp xếp:
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
7

Nếu một loại từ trên xuống dưới được thực hiện trên "Q1" (các giá trị trong "B"), các hàng được tô sáng sau đây được trả về bởi await Excel.run(async (context) => { let myWorkbook = context.workbook; let sampleSheet = myWorkbook.worksheets.getActiveWorksheet(); let copiedSheet = sampleSheet.copy(Excel.WorksheetPositionType.after, sampleSheet); await context.sync(); }); 0.

Nếu một loại từ trái sang phải được thực hiện trên "Quinces" (các giá trị trong "4") trên dữ liệu gốc, các cột được tô sáng sau đây sẽ được trả về bởi

await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
01.

Mẫu mã sau đây cho thấy cách đăng ký trình xử lý sự kiện cho sự kiện

await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
02. Cuộc gọi lại của người xử lý xóa màu lấp đầy cho phạm vi, sau đó lấp đầy các ô của các hàng di chuyển.Complete and colors them green. Note that
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
04 throws an
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
5 error if the specified string doesn't exist in the worksheet. If you're uncertain whether the specified string exists in the worksheet, use the findAllOrNullObject method to gracefully handle that scenario.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
8Complete and colors them green. Note that
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
04 throws an
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
5 error if the specified string doesn't exist in the worksheet. If you're uncertain whether the specified string exists in the worksheet, use the findAllOrNullObject method to gracefully handle that scenario.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
8

Tìm tất cả các ô với văn bản phù hợp

Đối tượng

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
7 có phương thức
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
04 để tìm kiếm một chuỗi được chỉ định trong bảng tính. Nó trả về một đối tượng
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
05, đây là một tập hợp các đối tượng
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
06 có thể được chỉnh sửa cùng một lúc.
  • Mẫu mã sau đây tìm thấy tất cả các ô có giá trị bằng chuỗi hoàn chỉnh và màu chúng xanh. Lưu ý rằng
    await Excel.run(async (context) => {
        let firstSheet = context.workbook.worksheets.getFirst();
        firstSheet.load("name");
    
        await context.sync();
        console.log(`The name of the first worksheet is "${firstSheet.name}"`);
    });
    
    04 đã ném lỗi
    await Excel.run(async (context) => {
        let firstSheet = context.workbook.worksheets.getFirst();
        firstSheet.load("name");
    
        await context.sync();
        console.log(`The name of the first worksheet is "${firstSheet.name}"`);
    });
    
    5 nếu chuỗi được chỉ định không tồn tại trong bảng tính. Nếu bạn không chắc chắn liệu chuỗi được chỉ định có tồn tại trong bảng tính hay không, hãy sử dụng phương thức FindallArnullObject để xử lý kịch bản đó một cách duyên dáng.
  • Dữ liệu lọc
  • Một bộ lọc tự động áp dụng các bộ lọc dữ liệu trên một phạm vi trong bảng tính. Điều này được tạo bằng
    await Excel.run(async (context) => {
        let firstSheet = context.workbook.worksheets.getFirst();
        firstSheet.load("name");
    
        await context.sync();
        console.log(`The name of the first worksheet is "${firstSheet.name}"`);
    });
    
    09, có các tham số sau.
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
10: Phạm vi mà bộ lọc được áp dụng, được chỉ định là đối tượng
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
06 hoặc chuỗi.3.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
9
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
12: Chỉ số cột dựa trên không theo tiêu chí bộ lọc được đánh giá.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
0
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
13: Một đối tượng FilterCriteria Xác định hàng nào nên được lọc dựa trên ô của cột.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
13.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
9
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
12: Chỉ số cột dựa trên không theo tiêu chí bộ lọc được đánh giá.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
0
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
13: Một đối tượng FilterCriteria Xác định hàng nào nên được lọc dựa trên ô của cột.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
1

Mẫu mã tự động cuối cùng cho thấy cách loại bỏ bộ lọc tự động khỏi bảng tính bằng phương pháp

await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
16.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
2

Một

await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
17 cũng có thể được áp dụng cho các bảng riêng lẻ. Xem công việc với các bảng bằng API Excel JavaScript để biết thêm thông tin.

Bảo vệ dữ liệu

Bổ trợ của bạn có thể kiểm soát khả năng chỉnh sửa dữ liệu của người dùng trong bảng tính. Thuộc tính

await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
18 của bảng tính là một đối tượng bảng tính với phương thức
await Excel.run(async (context) => {
    let firstSheet = context.workbook.worksheets.getFirst();
    firstSheet.load("name");

    await context.sync();
    console.log(`The name of the first worksheet is "${firstSheet.name}"`);
});
19. Ví dụ sau đây cho thấy một kịch bản cơ bản chuyển đổi sự bảo vệ hoàn toàn của bảng tính hoạt động.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
3

Phương thức

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
00 có hai tham số tùy chọn:
  • await Excel.run(async (context) => {
        let sheet = context.workbook.worksheets.getActiveWorksheet();
        sheet.load("name");
    
        await context.sync();
        console.log(`The active worksheet is "${sheet.name}"`);
    });
    
    01: Một bảng tính đối tượng Xác định các hạn chế chỉnh sửa cụ thể.
  • await Excel.run(async (context) => {
        let sheet = context.workbook.worksheets.getActiveWorksheet();
        sheet.load("name");
    
        await context.sync();
        console.log(`The active worksheet is "${sheet.name}"`);
    });
    
    02: Một chuỗi đại diện cho mật khẩu cần thiết cho người dùng để bỏ qua bảo vệ và chỉnh sửa bảng tính.

Bài viết bảo vệ một bảng tính có thêm thông tin về bảo vệ bảng tính và cách thay đổi nó thông qua UI Excel.

Phát hiện các thay đổi đối với trạng thái bảo vệ bảng tính

Trạng thái bảo vệ của một bảng tính có thể được thay đổi bởi một bổ trợ hoặc thông qua UI Excel. Để phát hiện các thay đổi đối với trạng thái bảo vệ, hãy đăng ký một trình xử lý sự kiện cho sự kiện ____103 của bảng tính. Trình xử lý sự kiện cho sự kiện

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
03 nhận được đối tượng
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
05 khi sự kiện bị bắn.

Mẫu mã sau đây cho thấy cách đăng ký trình xử lý sự kiện

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
03 và sử dụng đối tượng
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
05 để truy xuất các thuộc tính
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
08,
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
09 và
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
10 của sự kiện.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
4

Bố cục trang và cài đặt in

Bổ trợ có quyền truy cập vào cài đặt bố cục trang ở cấp bảng tính. Những điều khiển này làm thế nào trang tính được in. Một đối tượng

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
7 có ba thuộc tính liên quan đến bố cục:
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
12,
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
13,
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
14.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
15 và
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
16 là PageBreakCollections. Đây là các bộ sưu tập của các trang phá vỡ, trong đó chỉ định các phạm vi mà các lần ngắt trang thủ công được chèn. Mẫu mã sau đây thêm một lần ngắt trang ngang trên hàng 21.21.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
5
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
17 là một đối tượng Pagelayout. Đối tượng này chứa các cài đặt bố cục và in không phụ thuộc vào bất kỳ triển khai cụ thể của máy in. Các cài đặt này bao gồm lề, định hướng, đánh số trang, hàng tiêu đề và khu vực in.21.
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
5
await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getActiveWorksheet();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
17 là một đối tượng Pagelayout. Đối tượng này chứa các cài đặt bố cục và in không phụ thuộc vào bất kỳ triển khai cụ thể của máy in. Các cài đặt này bao gồm lề, định hướng, đánh số trang, hàng tiêu đề và khu vực in.

Mẫu mã sau tập trung vào trang (cả theo chiều dọc và chiều ngang), đặt một hàng tiêu đề sẽ được in ở đầu mỗi trang và đặt khu vực in thành phần phụ của bảng tính.

await Excel.run(async (context) => {
    let sheet = context.workbook.worksheets.getItem("Sample");
    sheet.activate();
    sheet.load("name");

    await context.sync();
    console.log(`The active worksheet is "${sheet.name}"`);
});
6

Xem thêm

  • Mô hình đối tượng JavaScript Excel trong các tiện ích bổ sung văn phòng

Nhận xét

Gửi và xem phản hồi cho

Bạn có thể chạy API trong Excel không?

Về cơ bản, bạn có ba tùy chọn để liên kết API với Excel: Truy vấn sức mạnh: Bạn có thể truy vấn dữ liệu từ API bằng công cụ tích hợp của Excel. Coupler.io: Nhà nhập khẩu của bên thứ ba này sẽ cho phép bạn tự động xuất dữ liệu qua API để vượt trội theo lịch trình tùy chỉnh. VBA: Đây là một tùy chọn dựa trên mã phù hợp với người dùng Excel am hiểu công nghệ.Power Query: You can query data from APIs using Excel's built-in tool. Coupler.io: This third-party importer will let you automate data exports via APIs to Excel on a custom schedule. VBA: This is a code-based option that is suitable for tech-savvy Excel users.Power Query: You can query data from APIs using Excel's built-in tool. Coupler.io: This third-party importer will let you automate data exports via APIs to Excel on a custom schedule. VBA: This is a code-based option that is suitable for tech-savvy Excel users.

Chúng ta có thể sử dụng JavaScript trong Excel không?

Một bổ trợ Excel tương tác với các đối tượng trong Excel bằng cách sử dụng API JavaScript Office, bao gồm hai mô hình đối tượng JavaScript: API JavaScript Excel: Được giới thiệu với Office 2016, API JavaScript Excel cung cấp các đối tượng được gõ mạnh mà bạn có thể sử dụng để truy cập bảng tính,Phạm vi, bảng, biểu đồ, và nhiều hơn nữa., which includes two JavaScript object models: Excel JavaScript API: Introduced with Office 2016, the Excel JavaScript API provides strongly-typed objects that you can use to access worksheets, ranges, tables, charts, and more., which includes two JavaScript object models: Excel JavaScript API: Introduced with Office 2016, the Excel JavaScript API provides strongly-typed objects that you can use to access worksheets, ranges, tables, charts, and more.

Excel có thể sử dụng API REST không?

API REST cho Dịch vụ Excel cho phép các hoạt động chống lại Excel Workbooks bằng cách sử dụng các hoạt động được chỉ định trong tiêu chuẩn HTTP.Điều này cho phép một cơ chế linh hoạt, an toàn và đơn giản hơn để truy cập và thao tác nội dung dịch vụ Excel.. This allows for a flexible, secure, and simpler mechanism to access and manipulate Excel Services content.. This allows for a flexible, secure, and simpler mechanism to access and manipulate Excel Services content.

API Excel có miễn phí không?

Có ví dụ về API Excel miễn phí không?Không chỉ có hàng chục API Excel miễn phí có sẵn từ các trang web như Rapidapi, Microsoft có một thư viện API lớn để sử dụng với phần mềm của nó, bao gồm không chỉ Excel mà cả Microsoft Graphs và Visual Basic.Not only are there dozens of free Excel APIs available from sites like RapidAPI, Microsoft has a large library of APIs for use with its software, which includes not only Excel but Microsoft Graphs and Visual Basic as well.Not only are there dozens of free Excel APIs available from sites like RapidAPI, Microsoft has a large library of APIs for use with its software, which includes not only Excel but Microsoft Graphs and Visual Basic as well.