mirror of
https://github.com/gnh1201/welsonjs.git
synced 2026-04-18 18:18:42 +00:00
Add fix_excel_format example script
Add examples/fix_excel_format.js which uses the WelsonJS msoffice Office.Excel API to read rows from data/fulllist.xlsx (worksheet 2), extract company, reservation time, resource, port and bandwidth, and log each row. For each entry it generates a per-company card Excel file by opening card_format.xlsx, populating template cells (with sensible defaults for missing resource/port/bandwidth), saving as data/{company}_card.xlsx, and exporting main.
This commit is contained in:
parent
bd8e2bad77
commit
272651f376
56
examples/fix_excel_format.js
Normal file
56
examples/fix_excel_format.js
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
// fix_excel_format.js
|
||||
// This script requires the WelsonJS framework.
|
||||
var Office = require("lib/msoffice");
|
||||
|
||||
function main(args) {
|
||||
var excel = new Office.Excel(); // Create a Excel instance
|
||||
excel.open("data\\fulllist.xlsx"); // Open a Excel window
|
||||
|
||||
// select the worksheet
|
||||
excel.selectWorksheet(2);
|
||||
|
||||
for (var i = 0; i < 34; i++) {
|
||||
var rownum = 2 + i;
|
||||
|
||||
var company_name = excel.getCellByPosition(rownum, 3).getValue();
|
||||
var reservation_time = excel.getCellByPosition(rownum, 7).getValue();
|
||||
var resource_name = excel.getCellByPosition(rownum, 8).getValue();
|
||||
var port_number = excel.getCellByPosition(rownum, 9).getValue();
|
||||
var bandwidth = excel.getCellByPosition(rownum, 10).getValue();
|
||||
|
||||
console.log("================");
|
||||
console.log("Company Name: " + company_name);
|
||||
console.log("Reservation Time: " + reservation_time);
|
||||
console.log("Resource Name: " + resource_name);
|
||||
console.log("Port Number: " + port_number);
|
||||
console.log("Bandwidth: " + bandwidth);
|
||||
console.log("================");
|
||||
|
||||
make_card_file({
|
||||
"company_name": company_name,
|
||||
"reservation_time": reservation_time,
|
||||
"resource_name": resource_name,
|
||||
"port_number": port_number,
|
||||
"bandwidth": bandwidth
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function make_card_file(data) {
|
||||
var excel = new Office.Excel();
|
||||
|
||||
excel.open("card_format.xlsx");
|
||||
|
||||
excel.getCellByPosition(2, 1).setValue(data.company_name);
|
||||
excel.getCellByPosition(2, 2).setValue(!data.resource_name ? "127.0.0.1" : data.resource_name);
|
||||
excel.getCellByPosition(2, 3).setValue(!data.port_number ? "80" : data.port_number);
|
||||
excel.getCellByPosition(2, 4).setValue(!data.bandwidth ? "100M" : data.bandwidth);
|
||||
excel.getCellByPosition(2, 5).setValue(data.reservation_time);
|
||||
|
||||
var file_name = String(data.company_name) + "_card.xlsx";
|
||||
excel.saveAs("data\\" + file_name);
|
||||
|
||||
excel.close();
|
||||
}
|
||||
|
||||
exports.main = main;
|
||||
Loading…
Reference in New Issue
Block a user