giả định. Cells cho Node. js qua Java cung cấp hỗ trợ đầy đủ cho việc thiết lập biểu đồ. Người ta có thể dễ dàng thêm các biểu đồ tiêu chuẩn hoặc tùy chỉnh bằng cách sử dụng API và đặt dữ liệu động để làm mới các biểu đồ
Bản trình diễn này tập trung vào API JavaScript có trong Excel. Để đọc và ghi các tệp Excel, các bản trình diễn khác bao gồm nhiều trường hợp sử dụng khác nhau
Office 2016 đã giới thiệu API JavaScript để tương tác với ứng dụng. Nó cung cấp các giải pháp cho các chức năng tùy chỉnh cũng như các bảng tác vụ
Excel hiện không cung cấp hỗ trợ để làm việc với các tệp Apple Numbers và một số định dạng tệp cũ. SheetJS lấp đầy khoảng trống
Bản trình diễn này tạo một chức năng tùy chỉnh mới để thêm chức năng rất cần thiết
3 cố gắng tìm nạp một bảng tính bên ngoài và chèn dữ liệu vào trang tính? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
Bản demo này tập trung vào các cơ chế cơ bản. Các chủ đề nâng cao như tham số Hàm tùy chỉnh Excel được đề cập trong tài liệu API JavaScript chính thức của Office. Siêu dữ liệu trang tính SheetJS và các thuộc tính khác được đề cập trong trang tài liệu này
Tạo một bổ trợ mới
Thiết lập nền tảng ban đầu [bấm để hiển thị]Công cụ tạo Office Add-in sử dụng NodeJS và các thư viện khác nhau. Cài đặt NodeJS LTS. Sau khi cài đặt NodeJS, hãy cài đặt các phụ thuộc trong cửa sổ PowerShell mới
npm install -g yo bower generator-office
Tạo Project mới [click để hiện]
Chạy
? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
4 từ dòng lệnh. Nó sẽ hỏi một số câu hỏi"Chọn loại dự án". "Dự án bổ trợ chức năng tùy chỉnh Excel"
"Chọn loại kịch bản". "JavaScript",
"Bạn muốn đặt tên cho phần bổ trợ của mình là gì?". "SheetJSImport"
Bạn sẽ thấy một màn hình như
? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
Nó in ra các bước tiếp theo một cách hữu ích
cd SheetJSImport
npm run build
npm start
Chạy
? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
5 sẽ mở ra một cửa sổ đầu cuối và một cửa sổ Excel mới với phần bổ trợ đã tải. Giữ cửa sổ đầu cuối mở [có thể thu nhỏ]. Khi bạn thực hiện thay đổi, hãy đóng cả cửa sổ Excel và cửa sổ đầu cuối trước khi chạy lại ? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
5Tích hợp thư viện SheetJS
Thư viện có thể được cài đặt giống như bất kỳ mô-đun NodeJS nào khác
npm i --save //cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz
Để đảm bảo thư viện đã được tải, hãy xóa tất cả các chức năng hiện có khỏi
? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
7. Các nội dung mới nên đượcvar XLSX = require["xlsx"];
/**
* Print SheetJS Library Version
* @customfunction
* @returns {string[][]} The SheetJS Library Version.
*/
function version[] {
return [[XLSX.version]];
}
? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
8 cũng nên được cập nhật để phản ánh không gian tên hàmnpm install -g yo bower generator-office
1Sau khi thực hiện thay đổi, hãy lưu các tệp. Đóng cửa sổ terminal và cửa sổ Excel [không lưu file Excel]. Chạy lại
? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
5Trong cửa sổ Excel mới, nhập công thức
cd SheetJSImport
npm run build
npm start
0 vào ô cd SheetJSImport
npm run build
npm start
1. Bạn sẽ thấy một cái gì đó tương tự như ảnh chụp màn hình sauĐiều này chỉ ra rằng thư viện SheetJS đã được tải
Mảng động và Mảng SheetJS của mảng
Hàm trợ giúp
cd SheetJSImport
npm run build
npm start
2 có thể tạo mảng gồm các mảng giá trị dựa trên dữ liệu trang tính. Các hàm tùy chỉnh của Excel coi chúng là Mảng động một cách rõ ràngTìm nạp tập tin từ Internet
Đối với bước tiếp theo, chúng tôi sẽ cố gắng tìm nạp dữ liệu từ một tài nguyên bên ngoài. https. //sheetjs. com/pres. số là tệp Apple Numbers. Excel không hiểu tệp Numbers và nó sẽ không mở chúng
Lỗi Excel liên quan đến `tìm nạp` [bấm để hiển thị]cd SheetJSImport
npm run build
npm start
3 có sẵn cho các chức năng tùy chỉnhnpm install -g yo bower generator-office
7Khi tìm nạp dữ liệu, các chức năng thường nhận một
cd SheetJSImport
npm run build
npm start
4 lưu trữ dữ liệu tệp. Điều này dễ dàng được phân tích cú pháp với cd SheetJSImport
npm run build
npm start
5? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
0Đây là cách nó nên hoạt động
Tại thời điểm viết bài, có những lỗi nổi bật trong Excel với dữ liệu thô
Đối với mục đích của bản trình diễn này, tệp được mã hóa Base64 sẽ được sử dụng. Giải pháp thay thế liên quan đến việc tìm nạp tệp Base64 đó, lấy văn bản và phân tích cú pháp bằng loại
cd SheetJSImport
npm run build
npm start
6? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
2Các tệp được mã hóa Base64 có thể được tạo bằng PowerShell
? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
3Thuộc tính
cd SheetJSImport
npm run build
npm start
7 của đối tượng sổ làm việc chứa tất cả các trang tính và thuộc tính cd SheetJSImport
npm run build
npm start
8 là một mảng tên trang tính. Chọn trang tính đầu tiên khá đơn giản? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
0Dữ liệu này có thể được chuyển đổi thành Mảng của Mảng trong một dòng
? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
1Để chứng minh khả năng phân tích cú pháp, phiên bản tệp được mã hóa Base64 sẽ được sử dụng. Tệp này không chứa ký tự nhị phân và chỉ nên "hoạt động". Khi lỗi Excel đã nói ở trên được sửa, các tệp nhị phân thô có thể được sử dụng
Chức năng mới này nên được thêm vào
? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
7? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
2Sau khi thực hiện thay đổi, hãy lưu các tệp. Đóng cửa sổ terminal và cửa sổ Excel [không lưu file Excel]. Chạy lại
? Choose a project type: Excel Custom Functions Add-in project
? Choose a script type: JavaScript
? What do you want to name your add-in? SheetJSImport
----------------------------------------------------------------------------------
Creating SheetJSImport add-in for Excel using JavaScript and Excel-functions
at C:\Users\SheetJS\Documents\SheetJSImport
----------------------------------------------------------------------------------
5Nhập công thức
npm i --save //cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz
1 vào ô npm i --save //cdn.sheetjs.com/xlsx-latest/xlsx-latest.tgz
2 và nhấn Enter. Excel sẽ lấy dữ liệu và tạo một mảng động