我尝试了不同的风格,这很有效。
使用这种风格
xmlStr += "<Styles>";
xmlStr += '<Style ss:ID="cellWithBorders">';
xmlStr += "<Borders>";
xmlStr += '<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>';
xmlStr += '<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>';
xmlStr += '<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>';
xmlStr += '<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>';
xmlStr += "</Borders>";
xmlStr += "</Style>";
xmlStr += "</Styles>";
full code you can use below reference ,
var xmlStr = '';
xmlStr += '<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" ';
xmlStr += 'xmlns:o="urn:schemas-microsoft-com:office:office" ';
xmlStr += 'xmlns:x="urn:schemas-microsoft-com:office:excel" ';
xmlStr += 'xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" ';
xmlStr += 'xmlns:html="http://www.w3.org/TR/REC-html40">';
xmlStr += "<Styles>";
xmlStr += '<Style ss:ID="cellWithBorders">';
xmlStr += "<Borders>";
xmlStr += '<Border ss:Position="Top" ss:LineStyle="Continuous" ss:Weight="1"/>';
xmlStr += '<Border ss:Position="Bottom" ss:LineStyle="Continuous" ss:Weight="1"/>';
xmlStr += '<Border ss:Position="Left" ss:LineStyle="Continuous" ss:Weight="1"/>';
xmlStr += '<Border ss:Position="Right" ss:LineStyle="Continuous" ss:Weight="1"/>';
xmlStr += "</Borders>";
xmlStr += "</Style>";
xmlStr += "</Styles>";
xmlStr += '<Worksheet ss:Name="Sheet1">';
xmlStr += "<Table>";
xmlStr += "<Row>";
xmlStr += '<Cell ss:StyleID="cellWithBorders"><Data ss:Type="String">Client Name</Data></Cell>';
xmlStr += '<Cell ss:StyleID="cellWithBorders"><Data ss:Type="String">Entity</Data></Cell>';
xmlStr += '<Cell ss:StyleID="cellWithBorders"><Data ss:Type="String">Country</Data></Cell>';
xmlStr += "</Row>";