- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2025 09:41 PM
Hi ServiceNow Community,
I have a task to generate an Excel file via script with a specific format. The file should contain 5 columns, and within those, 3 columns need to be merged.
I've already researched on the Community and consulted ChatGPT, and I found the following script:
Script to generate Excel file:
Could you please help me review the code to identify what might be wrong and how I can fix it?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2025 01:49 AM
Hi @Dung Hoang
You’re generating an Excel XML Spreadsheet 2003 (SpreadsheetML), not a .xlsx file. That means:
- Your Content-Type and file extension must match: use .xls with
"application/vnd.ms-excel". - In the XML, one of your headers has a missing quotation mark:
- <Cell ss:StyleID='BoldHeader'><Data ss:Type='String'>Number</Data></Cell>
If you want merged columns, you need to add ss:MergeAcross="N" on the <Cell> tag. For example, to merge 3 columns starting from this cell:- <Cell ss:MergeAcross="2"><Data ss:Type="String">Merged Header</Data></Cell>
But i have a doubt… Why are you build this script if is more easy export the data to xlsx?
See the reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2025 01:49 AM
Hi @Dung Hoang
You’re generating an Excel XML Spreadsheet 2003 (SpreadsheetML), not a .xlsx file. That means:
- Your Content-Type and file extension must match: use .xls with
"application/vnd.ms-excel". - In the XML, one of your headers has a missing quotation mark:
- <Cell ss:StyleID='BoldHeader'><Data ss:Type='String'>Number</Data></Cell>
If you want merged columns, you need to add ss:MergeAcross="N" on the <Cell> tag. For example, to merge 3 columns starting from this cell:- <Cell ss:MergeAcross="2"><Data ss:Type="String">Merged Header</Data></Cell>
But i have a doubt… Why are you build this script if is more easy export the data to xlsx?
See the reference
