Hướng dẫn how do you insert data into excel using javascript? - làm thế nào để bạn chèn dữ liệu vào excel bằng cách sử dụng javascript?
Bỏ qua nội dung chính Trình duyệt này không còn được hỗ trợ. Show
Nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, cập nhật bảo mật và hỗ trợ kỹ thuật. Chèn một loạt các ô bằng cách sử dụng API JavaScript Excel
Trong bài viết nàyBài viết này cung cấp một mẫu mã chèn một loạt các ô với API JavaScript Excel. Để biết danh sách đầy đủ các thuộc tính và phương thức mà đối tượng 7 hỗ trợ, hãy xem lớp excel.range.Ghi chú API JavaScript Excel không có đối tượng hoặc lớp "ô". Thay vào đó, API JavaScript Excel xác định tất cả các ô Excel là đối tượng 7. Một ô riêng lẻ trong UI Excel chuyển thành đối tượng 7 với một ô trong API JavaScript Excel. Một đối tượng 7 cũng có thể chứa nhiều ô tiếp giáp. Xem công việc với các ô bằng API JavaScript Excel để tìm hiểu thêm.Chèn một loạt các ôMẫu mã sau đây chèn một loạt các ô ở vị trí B4: E4 và chuyển các ô khác xuống để cung cấp không gian cho các ô mới.B4:E4 and shifts other cells down to provide space for the new cells.
Dữ liệu trước phạm vi được chènDữ liệu sau phạm vi được chènXem thêm
Nhận xét
Gửi và xem phản hồi cho Bỏ qua nội dung chính Trình duyệt này không còn được hỗ trợ. Nâng cấp lên Microsoft Edge để tận dụng các tính năng mới nhất, cập nhật bảo mật và hỗ trợ kỹ thuật. Làm việc với các bảng bằng API JavaScript Excel
Trong bài viết nàyBà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 các bảng bằ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 1 và 2 hỗ trợ, hãy xem đối tượng bảng (API JavaScript cho Excel) và đối tượng TableCollection (API JavaScript cho Excel).Tạo một bảngMẫu mã sau đây tạo ra một bảng trong bảng tính có tên mẫu. Bảng có các tiêu đề và chứa bốn cột và bảy hàng dữ liệu. Nếu ứng dụng Excel trong đó mã đang chạy hỗ trợ yêu cầu, đặt Excelapi 1.2, chiều rộng của các cột và chiều cao của các hàng được đặt để phù hợp nhất với dữ liệu hiện tại trong bảng.Sample. The table has headers and contains four columns and seven rows of data. If the Excel application where the code is running supports requirement set ExcelApi 1.2, the width of the columns and height of the rows are set to best fit the current data in the table. Ghi chú Để chỉ định tên cho một bảng, trước tiên bạn phải tạo bảng và sau đó đặt thuộc tính 3 của nó, như trong ví dụ sau.
Bảng mớiThêm hàng vào bảngMẫu mã sau đây thêm bảy hàng mới vào bảng có tên là ExpenseStable trong bảng tính có tên mẫu. Tham số 4 của phương thức 5 được đặt thành 6, trong đó chỉ định rằng các hàng được thêm vào sau các hàng hiện có trong bảng. Tham số 7 được đặt thành 8, chỉ ra rằng các hàng mới được chèn vào bảng, không phải bên dưới bảng. Chiều rộng của các cột và chiều cao của các hàng sau đó được đặt để phù hợp nhất với dữ liệu hiện tại trong bảng.ExpensesTable within the worksheet named Sample. The 4 parameter of the
5 method is set to 6, which specifies that the rows be added after the existing rows in the table. The 7 parameter is set to 8, which indicates that the new rows be inserted into the table, not below the table. The width of the columns and height of the rows are then set to best fit the
current data in the table.Ghi chú Để chỉ định tên cho một bảng, trước tiên bạn phải tạo bảng và sau đó đặt thuộc tính 3 của nó, như trong ví dụ sau.
Bảng mớiThêm hàng vào bảngMẫu mã sau đây thêm bảy hàng mới vào bảng có tên là ExpenseStable trong bảng tính có tên mẫu. Tham số 4 của phương thức 5 được đặt thành 6, trong đó chỉ định rằng các hàng được thêm vào sau các hàng hiện có trong bảng. Tham số 7 được đặt thành 8, chỉ ra rằng các hàng mới được chèn vào bảng, không phải bên dưới bảng. Chiều rộng của các cột và chiều cao của các hàng sau đó được đặt để phù hợp nhất với dữ liệu hiện tại trong bảng.Ghi chú Để chỉ định tên cho một bảng, trước tiên bạn phải tạo bảng và sau đó đặt thuộc tính 3 của nó, như trong ví dụ sau.index property of a
TableColumn object indicates the index number of the column within the columns collection of the table. The id property of a TableColumn object contains a unique key that identifies the column.Bảng mớiThêm hàng vào bảngExpensesTable within the worksheet named Sample. The new column is added after all existing columns in the table and contains a header ("Day of the Week") as well as data to populate the cells in the column. The width of the columns and height of the rows are then set to best fit the current data in the table.
Mẫu mã sau đây thêm bảy hàng mới vào bảng có tên là ExpenseStable trong bảng tính có tên mẫu. Tham số // This code sample shows how to add rows to a table that already exists
// on a worksheet named Sample.
await Excel.run(async (context) => {
let sheet = context.workbook.worksheets.getItem("Sample");
let expensesTable = sheet.tables.getItem("ExpensesTable");
expensesTable.rows.add(
null, // index, Adds rows to the end of the table.
[
["1/16/2017", "THE PHONE COMPANY", "Communications", "$120"],
["1/20/2017", "NORTHWIND ELECTRIC CARS", "Transportation", "$142"],
["1/20/2017", "BEST FOR YOU ORGANICS COMPANY", "Groceries", "$27"],
["1/21/2017", "COHO VINEYARD", "Restaurant", "$33"],
["1/25/2017", "BELLOWS COLLEGE", "Education", "$350"],
["1/28/2017", "TREY RESEARCH", "Other", "$135"],
["1/31/2017", "BEST FOR YOU ORGANICS COMPANY", "Groceries", "$97"]
],
true, // alwaysInsert, Specifies that the new rows be inserted into the table.
);
sheet.getUsedRange().format.autofitColumns();
sheet.getUsedRange().format.autofitRows();
await context.sync();
});
// This code sample shows how to add rows to a table that already exists
// on a worksheet named Sample.
await Excel.run(async (context) => {
let sheet = context.workbook.worksheets.getItem("Sample");
let expensesTable = sheet.tables.getItem("ExpensesTable");
expensesTable.rows.add(
null, // index, Adds rows to the end of the table.
[
["1/16/2017", "THE PHONE COMPANY", "Communications", "$120"],
["1/20/2017", "NORTHWIND ELECTRIC CARS", "Transportation", "$142"],
["1/20/2017", "BEST FOR YOU ORGANICS COMPANY", "Groceries", "$27"],
["1/21/2017", "COHO VINEYARD", "Restaurant", "$33"],
["1/25/2017", "BELLOWS COLLEGE", "Education", "$350"],
["1/28/2017", "TREY RESEARCH", "Other", "$135"],
["1/31/2017", "BEST FOR YOU ORGANICS COMPANY", "Groceries", "$97"]
],
true, // alwaysInsert, Specifies that the new rows be inserted into the table.
);
sheet.getUsedRange().format.autofitColumns();
sheet.getUsedRange().format.autofitRows();
await context.sync();
});
// This code sample shows how to add rows to a table that already exists
// on a worksheet named Sample.
await Excel.run(async (context) => {
let sheet = context.workbook.worksheets.getItem("Sample");
let expensesTable = sheet.tables.getItem("ExpensesTable");
expensesTable.rows.add(
null, // index, Adds rows to the end of the table.
[
["1/16/2017", "THE PHONE COMPANY", "Communications", "$120"],
["1/20/2017", "NORTHWIND ELECTRIC CARS", "Transportation", "$142"],
["1/20/2017", "BEST FOR YOU ORGANICS COMPANY", "Groceries", "$27"],
["1/21/2017", "COHO VINEYARD", "Restaurant", "$33"],
["1/25/2017", "BELLOWS COLLEGE", "Education", "$350"],
["1/28/2017", "TREY RESEARCH", "Other", "$135"],
["1/31/2017", "BEST FOR YOU ORGANICS COMPANY", "Groceries", "$97"]
],
true, // alwaysInsert, Specifies that the new rows be inserted into the table.
);
sheet.getUsedRange().format.autofitColumns();
sheet.getUsedRange().format.autofitRows();
await context.sync();
});
// This code sample shows how to add rows to a table that already exists
// on a worksheet named Sample.
await Excel.run(async (context) => {
let sheet = context.workbook.worksheets.getItem("Sample");
let expensesTable = sheet.tables.getItem("ExpensesTable");
expensesTable.rows.add(
null, // index, Adds rows to the end of the table.
[
["1/16/2017", "THE PHONE COMPANY", "Communications", "$120"],
["1/20/2017", "NORTHWIND ELECTRIC CARS", "Transportation", "$142"],
["1/20/2017", "BEST FOR YOU ORGANICS COMPANY", "Groceries", "$27"],
["1/21/2017", "COHO VINEYARD", "Restaurant", "$33"],
["1/25/2017", "BELLOWS COLLEGE", "Education", "$350"],
["1/28/2017", "TREY RESEARCH", "Other", "$135"],
["1/31/2017", "BEST FOR YOU ORGANICS COMPANY", "Groceries", "$97"]
],
true, // alwaysInsert, Specifies that the new rows be inserted into the table.
);
sheet.getUsedRange().format.autofitColumns();
sheet.getUsedRange().format.autofitRows();
await context.sync();
});
// This code sample shows how to add rows to a table that already exists
// on a worksheet named Sample.
await Excel.run(async (context) => {
let sheet = context.workbook.worksheets.getItem("Sample");
let expensesTable = sheet.tables.getItem("ExpensesTable");
expensesTable.rows.add(
null, // index, Adds rows to the end of the table.
[
["1/16/2017", "THE PHONE COMPANY", "Communications", "$120"],
["1/20/2017", "NORTHWIND ELECTRIC CARS", "Transportation", "$142"],
["1/20/2017", "BEST FOR YOU ORGANICS COMPANY", "Groceries", "$27"],
["1/21/2017", "COHO VINEYARD", "Restaurant", "$33"],
["1/25/2017", "BELLOWS COLLEGE", "Education", "$350"],
["1/28/2017", "TREY RESEARCH", "Other", "$135"],
["1/31/2017", "BEST FOR YOU ORGANICS COMPANY", "Groceries", "$97"]
],
true, // alwaysInsert, Specifies that the new rows be inserted into the table.
);
sheet.getUsedRange().format.autofitColumns();
sheet.getUsedRange().format.autofitRows();
await context.sync();
});
|