1.输出excel表格
1 package servlet_pack; 2 3 import java.io.IOException; 4 import java.io.PrintWriter; 5 6 import javax.servlet.ServletException; 7 import javax.servlet.annotation.WebServlet; 8 import javax.servlet.http.HttpServlet; 9 import javax.servlet.http.HttpServletRequest; 10 import javax.servlet.http.HttpServletResponse; 11 12 /** 13 * Servlet implementation class PrintExcel 14 */ 15 @WebServlet("/PrintExcel") 16 public class PrintExcel extends HttpServlet { 17 private static final long serialVersionUID = 1L; 18 19 /** 20 * @see HttpServlet#HttpServlet() 21 */ 22 public PrintExcel() { 23 super(); 24 } 25 26 /** 27 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) 28 */ 29 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 30 response.setContentType("application/vnd.ms-excel"); 31 PrintWriter out = response.getWriter(); 32 out.println("\tQ1\tQ2\tQ3\tQ4\ttotal"); 33 out.println("apple\t10\t20\t30\t40\t=sum(B2:E2)"); 34 out.println("orange\t11\t22\t33\t44\t=sum(B3:E3)"); 35 } 36 37 /** 38 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) 39 */ 40 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 41 doGet(request, response); 42 } 43 44 }
运行结果:
原文地址:https://www.cnblogs.com/ACGame/p/8452225.html
时间: 2024-11-02 16:50:15