WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 131afb5

Browse files
committed
Client Side custom Excel export using ExcelJS Framework
1 parent e33c87f commit 131afb5

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ExcelJS is a powerful JavaScript library for working with Excel spreadsheets. It allows developers to read, write, and manipulate Excel files programmatically, using a simple and intuitive API.
2+
3+
ExcelJS can also be used to build custom reports and dashboards within ServiceNow. By using ExcelJS to generate dynamic Excel spreadsheets, developers can create sophisticated reports that can be easily shared with other users. For example, a developer might build a custom dashboard that allows users to view real-time data on service requests, incidents, or other IT service management metrics.
4+
5+
Reference: https://www.servicenow.com/community/developer-articles/custom-excel-export-or-import-in-client-side-using-exceljs/ta-p/2519012.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
3+
<script src="https://unpkg.com/exceljs/dist/exceljs.min.js"></script>
4+
<button onclick="generateExcel()">Generate Excel</button>
5+
6+
<script>
7+
function generateExcel() {
8+
var workbook = new ExcelJS.Workbook();
9+
var worksheet = workbook.addWorksheet('My Sheet');
10+
11+
// Sample JSON data
12+
var jsonData = {
13+
"employees": [
14+
{
15+
"name": "John Doe",
16+
"age": 30,
17+
"position": "Manager"
18+
},
19+
{
20+
"name": "Jane Smith",
21+
"age": 25,
22+
"position": "Developer"
23+
},
24+
{
25+
"name": "Bob Johnson",
26+
"age": 45,
27+
"position": "Salesperson"
28+
}
29+
]
30+
};
31+
worksheet.addRow(['Name', 'Age', 'Position']);
32+
jsonData.employees.forEach(function(employee) {
33+
worksheet.addRow([employee.name, employee.age, employee.position]);
34+
});
35+
36+
37+
// Set cell colors
38+
worksheet.getCell('A1').font = {
39+
color:{argb: 'FFFF0000'} // red
40+
};
41+
worksheet.getCell('B1').fill = {
42+
type: 'pattern',
43+
pattern: 'solid',
44+
fgColor: {argb: 'FF00FF00'} // green
45+
};
46+
worksheet.getCell('C1').fill = {
47+
type: 'pattern',
48+
pattern: 'solid',
49+
fgColor: {argb: 'FF0000FF'} // blue
50+
};
51+
52+
// Generate Excel file and download it
53+
workbook.xlsx.writeBuffer().then(function(buffer) {
54+
var blob = new Blob([buffer], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'});
55+
var url = URL.createObjectURL(blob);
56+
var link = document.createElement('a');
57+
link.href = url;
58+
link.download = 'my_file.xlsx';
59+
link.click();
60+
});
61+
}
62+
</script>
63+
64+
65+
</j:jelly>

0 commit comments

Comments
 (0)