js实现操作excel类:exceljs
exceljs实现java风格用javascript读写操作excel文件,实现了读取sheet工作表,创建列、插入行数据、行格式化输出、行验证表达、设置字体样式、设置单元格边框大小。
Interface
var Excel = require("exceljs");
Create a Workbook
var workbook = new Excel.Workbook();
Set Workbook Properties workbook.creator = "Me"; workbook.lastModifiedBy = "Her"; workbook.created = new Date(1985, 8, 30); workbook.modified = new Date();
Add a Worksheet
var sheet = workbook.addWorksheet("My Sheet");
Access Worksheets // Iterate over all sheets // Note: workbook.worksheets.forEach will still work but this is better workbook.eachSheet(function(worksheet, sheetId) { // ... }); // fetch sheet by name var worksheet = workbook.getWorksheet("My Sheet"); // fetch sheet by id var worksheet = workbook.getWorksheet(1);
Columns // Add column headers and define column keys and widths // Note: these column structures are a workbook-building convenience only, // apart from the column width, they will not be fully persisted. worksheet.columns = [ { header: "Id", key: "id", width: 10 }, { header: "Name", key: "name", width: 32 }, { header: "D.O.B.", key: "DOB", width: 10 } ]; // Access an individual columns by key, letter and 1-based column number var idCol = worksheet.getColumn("id"); var nameCol = worksheet.getColumn("B"); var dobCol = worksheet.getColumn(3); // set column properties // Note: will overwrite cell value C1 dobCol.header = "Date of Birth"; // Note: this will overwrite cell values C1:C2 dobCol.header = ["Date of Birth", "A.K.A. D.O.B."]; // from this point on, this column will be indexed by "dob" and not "DOB" dobCol.key = "dob"; dobCol.width = 15;
本文由用户 f663x 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
转载本站原创文章,请注明出处,并保留原始链接、图片水印。
本站是一个以用户分享为主的开源技术平台,欢迎各类分享!