First method :user-defined
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!-- 命名x空间即调用excel里的属性--> <html xmlns:x="urn:schemas-microsoft-com:office:excel"> <head> <!-- 显示网格线 --> <xml> <x:ExcelWorkbook> <x:ExcelWorksheets> <x:ExcelWorksheet> <x:Name></x:Name> <x:WorksheetOptions> <x:Print> <x:ValidPrinterInfo /> </x:Print> </x:WorksheetOptions> </x:ExcelWorksheet> </x:ExcelWorksheets> </x:ExcelWorkbook> </xml> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>导出excel文档</title> </head> <body> <% String exportToExcel = request.getParameter("exportToExcel"); String fileName = request.getParameter("fileName")==""?"excel":request.getParameter("fileName"); if (exportToExcel != null && exportToExcel.toString().equalsIgnoreCase("YES")) { //设置内容和