package com.embraiz.web;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.*;
import java.io.*;
import jxl.*;
import jxl.write.*;
import com.embraiz.bo.sales.ObjClientCompany;
import com.embraiz.common.util.SmartDate;
import java.sql.SQLException;
import java.util.*;
import com.embraiz.bo.core.ObjUser;
import com.embraiz.common.sql.SQLBridge;
public class ExcelForClientCompany extends HttpServlet {
/**
* Constructor of the object.
*/
private SQLBridge sqlBridge;
public ExcelForClientCompany() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try
{
sqlBridge = new SQLBridge();
sqlBridge.setConnectionName("proxool.erppool");
sqlBridge.setConnectionSwitch("on");
response.setContentType("text/html");
String userId=request.getParameter("userId");
String objKeyword=request.getParameter("objKeyword");
String clientCompanyName=request.getParameter("clientCompanyName");
String assignedTo=request.getParameter("assignedTo");
String generalLine=request.getParameter("generalLine");
String fax=request.getParameter("fax");
String brand=request.getParameter("brand");
String filterLetter=request.getParameter("filterLetter");
ObjClientCompany searchPO=new ObjClientCompany();
searchPO.setObjTitle(clientCompanyName);
searchPO.setBrandName(brand);
searchPO.setTelephone(generalLine);
searchPO.setFax(fax);
if(assignedTo!=null)
{
searchPO.setAllocation(new Integer(assignedTo));
}
searchPO.setObjKeyword(objKeyword);
searchPO.setFilterLetter(filterLetter);
List<ObjClientCompany> list=searchPO.list(sqlBridge,userId);
response.setContentType("application/vnd.ms-excel;charset=gb2312");
response.setHeader("Content-disposition", "attachment; filename=\"ClientCompany_Form.xls\"");
OutputStream os = response.getOutputStream();
WritableWorkbook wwb = Workbook.createWorkbook(os);
WritableCellFormat bColor = new WritableCellFormat();
bColor.setBackground(jxl.format.Colour.ICE_BLUE);
try
{
WritableSheet wsheet = wwb.createSheet("page1",0);
Label label=new Label(0,0,"Client company",bColor);
wsheet.addCell(label);
label=new Label(1,0,"Assigned to",bColor);
wsheet.addCell(label);
label=new Label(2,0,"Brand",bColor);
wsheet.addCell(label);
label=new Label(3,0,"General Line",bColor);
wsheet.addCell(label);
label=new Label(4,0,"Create Date",bColor);
wsheet.addCell(label);
int i;
int j;
for(i=1;i<=list.size();i++){
j=0;
label=new Label(j,i,list.get(i-1).getObjTitle());
wsheet.addCell(label);
j++;
label=new Label(j,i,list.get(i-1).getAssignUserName());
wsheet.addCell(label);
j++;
label=new Label(j,i,list.get(i-1).getBrandName());
wsheet.addCell(label);
j++;
label=new Label(j,i,list.get(i-1).getTelephone());
wsheet.addCell(label);
j++;
label=new Label(j,i,SmartDate.DateToStr(list.get(i-1).getCreateDate(),"yyyy-MM-dd HH:mm").toString());
wsheet.addCell(label);
j++;
}
wsheet.setRowView(0,400);
wsheet.setColumnView(0,20);//设置列宽
wsheet.setColumnView(1,20);
wsheet.setColumnView(2,20);
wsheet.setColumnView(3,20);
wsheet.setColumnView(4,20);
wwb.write();
wwb.close();
os.close();
response.flushBuffer();
}catch(Exception e){
System.out.println(e);
}}catch(Exception e)
{
}finally
{
try {
sqlBridge.setConnectionSwitch("off");
} catch (Exception e) {
e.printStackTrace();
}
}
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
}
}
分享到:
相关推荐
export excel mvc3 razor
GridView Export Excel2003-2007(同时支持Excel2003与2007) C#代码 解决同时在Excel2003/2007下汉字乱码问题。
VB export Excel and OpenOffice
自从上次用bootstrap table就一直没有解决导出excel的关题,网上找到的那更改tableExport.js和jquery.base64.js的方法虽然可以正常导出,但中文依旧乱码... 解决方法终归是有的....现将文件分享给大家. 里面有table...
Export Excel vs VB_copysx5_vb.net_VB_源码
flash export excel 简单汇出flash datagrid 资料到excel
ls_ruta, named, "XLS","Libros Excel (*.xls),*.xls" ) uf_save_dw_as_excel(dw_preview,ls_ruta) Nota: La libreria pb2xls.dll, debe estar en la misma ruta donde estan las fuentes, y el pbl(dw2xls_...
Ansoft_Maxwell_12_用户手册_从RMxprt中导出模型
Export2Excel.js,进行表格导出时,需要的文件依赖表格数据导出excel 在项目中创建一个文件夹 把Blob.js和 Export2Excel.js这两个文件夹放到新建的文件夹 链接: ...
java导入导出excel文件,使用jsp,struts等技术,实现excel文件的导入导出。
包含Blob.js和Export2Excel.js文件,支持导出excel内容的宽度自适应,在vue项目中实现前端导出Excel文件
文件名:Export2Excel.js,Export2Excel.js免费下载,可以使用此js在前端导出xlsx表格数据
vue导出excel表格Blob,Export2Excel
Export to Excel using VB.NET.Exporting data to Excel of Microsoft Office is currently needed. But many of them used very complicated coding for simple export either from Datagrid or DataTable. I used ...
将Trello卡从板上导出到包含以下字段的Excel xlsx文件:卡ID,编号,卡名称,板,说明,列表,标签,成员,到期日,完成,创建日期,上次更新时间,通过以下方式访问卡URL菜单>共享,打印和导出>导出Excel Suite中的...
用Export2Excel将table导出成excel,需要-Blob.js和 Export2Excel.js两个js文件
简单的列表数据导出示例代码,直接将需要导出的数据填入参数中,快速方便。
NULL 博文链接:https://zhizizhishou0104.iteye.com/blog/2198729