Force a column to format as text when exporting to Excel from Datatables.net


JavaScript • Microsoft Excel

Add the exportOptions and customizeData options below to your buttons array group for the excel export.

		buttons: [
			{ 
				text: 'Download Excel', 
				extend: 'excel', 
				title:'', 
				className: 'btn btn-sm btn-success', 
				exportOptions: { columns: ':visible' }, 
				extension: '.xlsx', 
				
				exportOptions: { orthogonal: 'sort' },
				customizeData: function ( data ) {
					for (var i=0; i<data.body.length; i++){
						for (var j=0; j<data.body[i].length; j++ ){
							if (j==2 || j==16 || j==21){          //this line only applies it to 3 specific columns
								data.body[i][j] = '\u200C' + data.body[i][j];
							}
						}
					}
				}

			}

Written by fbrefere001

Posted by fbrefere001 on Wednesday January 14, 2026