package com.util;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/*import dao.CommDAO;*/
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;
public class Info {
//public static String popheight = "alliframe.height=document.body.clientHeight+";
public static String popheight = "alliframe.style.height=document.body.scrollHeight+";
public static HashMap getUser(HttpServletRequest request)
{
HashMap map = (HashMap)(request.getSession().getAttribute("admin")==null?request.getSession().getAttribute("user"):request.getSession().getAttribute("admin"));
return map;
}
public static int getBetweenDayNumber(String dateA, String dateB) {
long dayNumber = 0;
//1小时=60分钟=3600秒=3600000
long mins = 60L * 1000L;
//long day= 24L * 60L * 60L * 1000L;计算天数之差
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm");
try {
java.util.Date d1 = df.parse(dateA);
java.util.Date d2 = df.parse(dateB);
dayNumber = (d2.getTime() - d1.getTime()) / mins;
} catch (Exception e) {
e.printStackTrace();
}
return (int) dayNumber;
}
public static void main(String[] g )
{
System.out.print(Info.getBetweenDayNumber("2012-11-11 11:19", "2012-11-11 11:11"));
}
public static String getselect(String name,String tablename,String zdname)
{
String select = "<select name=\""+name+"\" id=\""+name+"\" >";
/*for(HashMap permap:new CommDAO().select("select * from "+tablename+" order by id desc")){
select+="<option value=\""+permap.get(zdname)+"\">"+permap.get(zdname)+"</option>";
}
select+="</select>";*/
return select;
}
public static String getselect(String name,String tablename,String zdname,String where)
{
String select = "<select name=\""+name+"\" id=\""+name+"\" >";
select+="<option value=\"\">不限</option>";
/*for(HashMap permap:new CommDAO().select("select * from "+tablename+" where "+where+" order by id desc")){
String optionstr = "";
if(zdname.split(";").length==1){
optionstr=permap.get(zdname.split("~")[0]).toString();
}else{
for(String str:zdname.split(";"))
{
String zdstr = str.split("~")[0];
String zdnamestr = str.split("~")[1].equals("无名")?"":(str.split("~")[1]+":");
optionstr+=zdnamestr+permap.get(zdstr)+" - ";
}
}
if(optionstr.indexOf(" - ")>-1)optionstr=optionstr.substring(0,optionstr.length()-3);
select+="<option value=\""+optionstr+"\">"+optionstr+"</option>";
}
select+="</select>";*/
return select;
}
public static String getradio(String name,String tablename,String zdname,String where)
{
String radio="";
int dxii = 0;
/*for(HashMap permap:new CommDAO().select("select * from "+tablename+" where "+where+" order by id desc")){
String check="";
if(dxii==0)check="checked=checked";
String optionstr = "";
for(String str:zdname.split(";"))
{
String zdstr = str.split("~")[0];
String zdnamestr = str.split("~")[1].equals("无名")?"":(str.split("~")[1]+":");
optionstr+=zdnamestr+permap.get(zdstr)+" - ";
}
if(optionstr.length()>0)optionstr=optionstr.substring(0,optionstr.length()-3);
radio+="<label><input type='radio' name='"+name+"' "+check+" value=\""+optionstr+"\">"+optionstr+"</label>\n";
dxii++;
}*/
return radio;
}
public static void writeExcel(String fileName,String prosstr,java.util.List<List> plist,HttpServletRequest request, HttpServletResponse response){
WritableWorkbook wwb = null;
String cols = "";
for(String str:prosstr.split("@"))
{
cols+=str.split("-")[0]+",";
}
cols = cols.substring(0,cols.length()-1);
String where = request.getAttribute("where")==null?"":request.getAttribute("where").toString();
/* List<List> mlist = new CommDAO().selectforlist("select "+cols+" from "+fileName+" "+where+" order by id desc");*/
fileName = request.getRealPath("/")+"/upfile/"+Info.generalFileName("a.xls");
String[] pros = prosstr.split("@");
try {
//首先要使用Workbook类的工厂方法创建一个可写入的工作薄(Workbook)对象
wwb = Workbook.createWorkbook(new File(fileName));
} catch (IOException e) {
e.printStackTrace();
}
if(wwb!=null){
//创建一个可写入的工作表
//Workbook的createSheet方法有两个参数,第一个是工作表的名称,第二个是工作表在工作薄中的位置
WritableSheet ws = wwb.createSheet("sheet1", 0);
ws.setColumnView(0,20);
ws.setColumnView(1,20);
ws.setColumnView(2,20);
ws.setColumnView(3,20);
ws.setColumnView(4,20);
ws.setColumnView(5,20);
try {
for(int i=0;i<pros.length;i++)
{
Label label1 = new Label(i, 0,"");
label1.setString(pros[i]);
ws.addCell(label1);
}
} catch (RowsExceededException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (WriteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//下面开始添加单元格
/*int i=1;*/
/* for(List t:mlist){
try {
Iterator it = t.iterator();
int jj=0;
while(it.hasNext())
{
Label label1 = new Label(jj, i,"");
String a = it.next().toString();
label1.setString(a);
ws.addCell(label1);
jj++;
}
i++;
} catch (RowsExceededException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (WriteException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
try {
//从内存中写入文件中
wwb.write();
//关闭资源,释放内存
wwb.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
try {
response.sendRedirect("/pianotrainwebstie/upload?filename="+fileName.substring(fileName.lastIndexOf("/")+1));
} catch (IOException e) {
e.printStackTrace();*/
}
}
public static String getcheckbox(String name,String tablename,String zdname,String where)
{
String checkbox="";
/* f
码农飞哥
- 粉丝: 15w+
- 资源: 1914
最新资源
- 使用麻雀搜索算法SSA优化ELM实现多维输入回归预测模型,优化过程展示及性能评估代码,包含与ELM对比与全面的评价指标输出 ,利用麻雀搜索算法SSA优化ELM极限学习机实现多维输入的回归预测模型,代码
- Java毕设项目:基于SpringBoot+mybatis+maven+mysql实现的网上订餐管理系统【含源码+数据库+开题报告+答辩PPT+毕业论文】
- kde-l10n-Serbian-4.10.5-2.el7.x64-86.rpm.tar.gz
- kde-l10n-Sinhala-4.10.5-2.el7.x64-86.rpm.tar.gz
- 西门子S7-200电梯控制程序设计:涵盖定位、内外呼信号响应等核心功能,结合MCGS组态软件的仿真模拟监控界面开发,基于西门子的S7-200电梯控制程序(主要包括电梯定位程序,外呼内选信号的记忆、显示
- kde-l10n-Slovak-4.10.5-2.el7.x64-86.rpm.tar.gz
- MATLAB下的Stewart平台并联机器人仿真研究:运动学分析与Simulink Simscape应用,MATLAB并联机器人Stewart平台仿真simulink simscape 运动学 ,核
- Java毕设项目:基于SpringBoot+mybatis+maven+mysql实现的大学生租房平台管理系统【含源码+数据库+开题报告+毕业论文】
- kde-l10n-Slovenian-4.10.5-2.el7.x64-86.rpm.tar.gz
- C#工业自动化控制链接库:涵盖PLC通信、Modbus、Socket、OPC、数据库、MQTT、消息队列及Mes系统等功能支持串口与Can总线协议开发库,c#工业自动化控制链接开发库(注意是DLL文件
- kde-l10n-Spanish-4.10.5-2.el7.x64-86.rpm.tar.gz
- kde-l10n-Swedish-4.10.5-2.el7.x64-86.rpm.tar.gz
- "带流量控制的交通灯PLC程序:三菱FX系列工作周期60秒,灯时变化随车流数量调整",带流量控制的交通灯三菱FX系列PLC程序3 有io分配表和PLC原理图 工作周期60秒,若两个方向车辆不同时,是在
- kde-l10n-Tajik-4.10.5-2.el7.x64-86.rpm.tar.gz
- 基于Matlab的永磁同步电机MRAS模型参考自适应控制算法仿真研究,永磁同步电机的MRAS模型参考自适应控制算法,matlab,仿真模型 ,核心关键词:永磁同步电机; MRAS模型参考自适应控制算
- Java毕设项目:基于SpringBoot+mybatis+maven+mysql实现的房屋租赁管理系统【含源码+数据库+答辩PPT+毕业论文】
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈