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);</pre>
</h2>
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;</pre></h2>
// fetch sheet by name var worksheet = workbook.getWorksheet("My Sheet");
// fetch sheet by id
var worksheet = workbook.getWorksheet(1);</pre>
</h2>
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;</pre></h2>
// 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;</pre></h2>
本文由用戶 f663x 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!