java数据导出代码,怎么导出java代码
如何用java实现mysql数据库的导入导出
MySql导出数据库的命令如下:
网站建设哪家好,找成都创新互联!专注于网页设计、网站建设、微信开发、小程序定制开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了莲都免费建站欢迎大家使用!
Sql代码
mysqldump -uusername -ppassword -hhost -Pport exportDatabaseName exportPath
mysqldump -uusername -ppassword -hhost -Pport exportDatabaseName exportPath
利用Java调用命令窗口执行命令来进行MySql导入数据库一般分三步走:
第一步:登录Mysql数据库,在登录数据库的时候也可以指定登录到哪个数据库,如果指定了则可以跳过第二步;
第二步:切换数据库到需要导入的目标数据库
第三步:利用命令开始导入
在进行导出的时候,需要注意命令语句的运行环境,如果已经将mysql安装路径下的bin加入到
系统的path变量中,那么在导出的时候可以直接使用命令语句,否则,就需要在执行命令语句的
时候加上命令所在位置的路径,即mysql安装路径想的bin下的mysqldump命令。
java导出excel
java导出Excel java 代码 /* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package com.axon.fable.sams.view.action; import java.io.IOException; import java.io.OutputStream; import java.util.List; import javax.serv ... java导出Excel例举方式 方法一:导出Excel数据的插件jexcelapi 程序实例如下: public void exportClassroom(OutputStream os) throws PaikeException { try { WritableWorkbook wbook = Workbook.createWorkbook(os); //建立excel文件 WritableSheet wsheet = wbook.createSheet("教室信息表", 0); //工作表名称 //设置Excel字体 WritableFont wfont = new WritableFont(WritableFont.ARIAL, 16, WritableFont.BOLD, false, jxl.format.UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK); WritableCellFormat titleFormat = new WritableCellFormat(wfont); String[] title = { "教室名", "容 量", "类 型", "其他说明" }; //设置Excel表头 for (int i = 0; i title.length; i++) { Label excelTitle = new Label(i, 0, title[i], titleFormat); wsheet.addCell(excelTitle); } int c = 1; //用于循环时Excel的行号 ClassroomService cs = new ClassroomService(); List list = cs.findAllClassroom(); //这个是从数据库中取得要导出的数据 Iterator it = list.iterator(); while (it.hasNext()) { ClassroomDTO crdto = (ClassroomDTO) it.next(); Label content1 = new Label(0, c, crdto.getRoomname()); Label content2 = new Label(1, c, crdto.getCapicity().toString()); Label content3 = new Label(2, c, crdto.getRoomTypeId() .toString()); Label content4 = new Label(3, c, crdto.getRemark()); wsheet.addCell(content1); wsheet.addCell(content2); wsheet.addCell(content3); wsheet.addCell(content4); c++; } wbook.write(); //写入文件 wbook.close(); os.close(); } catch (Exception e) { throw new PaikeException("导出文件出错"); } } 方法二:直接用Java代码实现导出Excel报表 /* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */
java里将从excel读到的数据用csv导出,代码怎么写
解释:csv文件实际上就是字符串,之间用“,”进行分割,之后进行的存储。
工具类如下:
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.List;
/**
*
* CSV文件导出工具类
*/
public class CSVUtils {
/**
* CSV文件生成方法
* @param head
* @param dataList
* @param outPutPath
* @param filename
* @return
*/
public static File createCSVFile(List head, ListList dataList,
String outPutPath, String filename) {
File csvFile = null;
BufferedWriter csvWtriter = null;
try {
csvFile = new File(outPutPath + File.separator + filename + ".csv");
File parent = csvFile.getParentFile();
if (parent != null !parent.exists()) {
parent.mkdirs();
}
csvFile.createNewFile();
// GB2312使正确读取分隔符","
csvWtriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(
csvFile), "GB2312"), 1024);
// 写入文件头部
writeRow(head, csvWtriter);
// 写入文件内容
for (List row : dataList) {
writeRow(row, csvWtriter);
}
csvWtriter.flush();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
csvWtriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return csvFile;
}
/**
* 写一行数据方法
* @param row
* @param csvWriter
* @throws IOException
*/
private static void writeRow(List row, BufferedWriter csvWriter) throws IOException {
// 写入文件头部
for (Object data : row) {
StringBuffer sb = new StringBuffer();
String rowStr = sb.append("\"").append(data).append("\",").toString();
csvWriter.write(rowStr);
}
csvWriter.newLine();
}
}
Object-Z
用java将数据导出到wps表格中,怎么实现
一:页面图片显示预览:
1)如下图:
2)点击导出按钮后预览:
3)最终生成的excel表格图片预览:
二:代码演示:
说明:执行操作时,请先引进导出excel表格的jar文件包。
找到导出按钮所执行的js方法,在java后天查看该方法的实现即可。
1)jsp代码:
[html] view plaincopyprint?
%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%
%@taglib prefix="s" uri="/struts-tags" %
%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%
html
head
base href="%=basePath%"
title驾校合格率排名/title
link href="jsp/commonstyle/css/tabStyle.css" rel="stylesheet" type="text/css"
link rel="STYLESHEET" type="text/css" href="%=basePath%jsp/hgltj/js/tablesort.css"
script type="text/javascript" src="%=basePath%jsp/system/common/js/publicColor.js"/script
script type="text/javascript" src="jsp/commonstyle/js/js/My97DatePicker/WdatePicker.js" defer="defer"/script
script type="text/javascript" src="%=basePath%jsp/hgltj/js/tablesort.js"/script
script language="JavaScript"
function load()
{
//根据分辨率设置表格大小
maxw=document.getElementById("maintb").offsetWidth;
if(maxw824){//1024分辨率未展开
mainbox.width="98%";
} else if(maxw1013){//1024分辨率展开
mainbox.width="98%";
} else if(maxw1081){//1280分辨率未展开
mainbox.width="95%";
} else if(maxw1270){//1280分辨未展开
mainbox.width="95%";
}else{//1280以上分辨展开
mainbox.width="98%";
}
}
/script
script
function overIt(){
var the_obj = event.srcElement;
if(the_obj.tagName.toLowerCase() == "td"){
the_obj=the_obj.parentElement;
the_obj.oBgc=the_obj.currentStyle.backgroundColor;
the_obj.oFc=the_obj.currentStyle.color;
the_obj.style.backgroundColor='#4073C4';
the_obj.style.color='#ffffff';
the_obj.style.textDecoration='underline';
}
}
function outIt(){
var the_obj = event.srcElement;
if(the_obj.tagName.toLowerCase() == "td"){
the_obj=the_obj.parentElement;
the_obj.style.backgroundColor=the_obj.oBgc;
the_obj.style.color=the_obj.oFc;
the_obj.style.textDecoration='';
}
}
function serch(){
document.getElementById("formName").action="%=basePath %hgltj.action?method=getHglpm";
document.getElementById("formName").submit();
}
function tbbt(){
var jzrq=document.getElementById("jzrqId").value;
//var jxmc=document.getElementById("jxmcId").value;
window.open('%=basePath %hgltj.action?method=getHglpmTbtjjxkshgl.jzrq='+jzrq+'tjjxkshgl.zt='+1,'','height=650,width=1250,top=150,left=200,toobar=no,menubar=no,scrollbars=yes,resizable=no,location=no,');
}
function openwd(){
document.getElementById("formName").action="%=basePath %hgltj.action?method=downJxhglPm";
document.getElementById("formName").submit();
}
/script
/head
BODY onLoad="load()" style="background: url(images/cont_bg.gif); background-repeat: repeat-y"
input type="hidden" name="method" value="getDriverInfoList"/
table border="0" width="100%" cellspacing="0" cellpadding="0" id="maintb"
tr
td align="center"
table width="90%" border="0" cellspacing="0" cellpadding="0" id="mainbox" style="background:url(jsp/commonstyle/images/usermessage_02.gif); background-repeat:repeat-x;"
!--宽度可变内容框--
tr
td width="33" height="27" style=" background:url(jsp/commonstyle/images/usermessage_01.gif); background-position:left; background-repeat:no-repeat;" /td
td width="965" class="style1"font color="black"驾校合格率排名/font/td
td width="14" height="27" style=" background:url(jsp/commonstyle/images/usermessage_03.gif); background-position:right; background-repeat:no-repeat;" /td
/tr
tr
td colspan="3"
!--页面主体内容开始--
!--查询条件--
form action="" name="formName" method="post" style="margin:0px" id="formName" theme="simple"
table width="100%" border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse;" id="tj" align="center"
tr align="left"
td class="tjbg1" style="text-align: left"
!-- input type="hidden" id="method" name="method" value="getHglpm"/ --
统计日期:
input type="text" name="tjjxkshgl.jzrq" id="jzrqId" value="s:property value="tjjxkshgl.jzrq"/" onclick="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM'})"/
!-- 驾校名称:
s:select id="jxmcId" name="tjjxkshgl.jxxh" value="tjjxkshgl.jxxh" list="schoolList" listKey="jxxh" listValue="jxmc" headerKey="" headerValue="--请选择--" theme="simple"/s:select --
input name="input" value=" 统 计 " type="button" class="normalbtn" onClick="serch()" style="margin-bottom: 5px" /
input name="input" type="button" value=" 合格率图表 " onclick="tbbt()" class="normalbtn" style="margin-bottom: 5px" /
input id="Button1" type="button" value=" 导 出 " onclick="openwd();" class="normalbtn" style="margin-bottom: 5px" /
/td
/tr
/table!--查询结果--
/form
!--查询结果--
table width="100%" border="0" cellpadding="4" cellspacing="1" bgcolor="#abcfff" id="cxjg" align="center"
thead
tr class="tbtitle"
td width="4%" align="center" class="t1"名次/td
td width="8%" align="center" class="t1"名称/td
td class="t1" width="5%" align="center"科目一/td
td class="t1" width="5%" align="center"科目二/td
td class="t1" width="5%" align="center"科目三/td
td class="t1" width="5%" align="center"平均合格率/td
td class="t1" width="5%" align="center"操作/td
/tr
/thead
s:iterator id="jxhgl" value="jxhelpmList" status="st"
tr class="changeColor" onMouseOver="overIt()" onMouseOut="outIt()" style="cursor: hand" align="center"
tds:property value="#st.index+1"//td
tds:property value="#jxhgl.jxmc"//td
tds:property value="#jxhgl.km1hgl"//td
tds:property value="#jxhgl.km2hgl"//td
tds:property value="#jxhgl.km3hgl"//td
tds:property value="#jxhgl.avghgl"/%/td
td
a href="javascript:" onclick="openWin('%=basePath %hgltj.action?method=getTbForJxxhtjjxkshgl.jxxh=s:property value="#jxhgl.jxxh"/tjjxkshgl.zt=1','',1250,750);"图表/a
/td
/tr
/s:iterator
/table
/table
/td
/tr
/table
/body
/html
2)java代码演示:
[java] view plaincopyprint?
/**
* 驾校合格率导出excel图表
*/
//response.getOutputStream();// 取得输出流
response.reset();// 清空输出流
String tmptitle = "驾校合格率排名"; // 标题
response.setHeader("Content-disposition", "attachment; filename="+new String(tmptitle.getBytes(),"iso8859-1")+".xls");// 设定输出文件头
response.setContentType("application/vnd.ms-excel");// 定义输出类型
wbook = Workbook.createWorkbook(os); // 建立excel文件
WritableSheet wsheet = wbook.createSheet(tmptitle, 0); // sheet名称
// 设置excel标题
//cellFormat.setBackground(Colour.AQUA);
cellFormat.setFont(wfont);
label.setCellFormat(cellFormat);
wsheet.addCell(label);
//wsheet.addCell(new Label(0, 0, tmptitle, wcfFC));
wsheet.setRowView(0,500); //第一行高度
wsheet.mergeCells(0, 0, 6, 1); //合并单元格(第一列的第一行和第七列的第二行合并)
//wsheet.mergeCells(0, 1, 9, 1);
// wsheet.mergeCells(0, 2, 0, 4);
// wsheet.mergeCells(1, 2, 3, 2);
// wsheet.mergeCells(4, 2, 6, 2);
// wsheet.mergeCells(7, 2, 9, 2);
wsheet.setColumnView(0,10); //宽度
wsheet.setColumnView(1,25); //宽度
wsheet.setColumnView(2,10); //宽度
wsheet.setColumnView(3,10); //宽度
wsheet.setColumnView(4,10); //宽度
wsheet.setColumnView(5,10); //宽度
// 开始生成主体内容
wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 14,WritableFont.BOLD,false, UnderlineStyle.NO_UNDERLINE,Colour.BLACK);
wcfFC = new WritableCellFormat(wfont);
wsheet.addCell(new Label(0, 2, "名次",wcfFC));
wsheet.addCell(new Label(1, 2, "驾校名称",wcfFC));
wsheet.addCell(new Label(2, 2, "科目一",wcfFC));
wsheet.addCell(new Label(3, 2, "科目二",wcfFC));
wsheet.addCell(new Label(4, 2, "科目三",wcfFC));
wsheet.addCell(new Label(5, 2, "合格率",wcfFC));
int count=jxhelpmList.size();
if(count0){ ////判断集合是否不为0
TjJxkshgl tjhgl=null;
for(int i=0;ijxhelpmList.size();i++){
tjhgl=(TjJxkshgl)jxhelpmList.get(i);
wsheet.addCell(new Label(0, i+3, (i+1)+""));
wsheet.addCell(new Label(1, i+3, tjhgl.getJxmc()));
wsheet.addCell(new Label(2, i+3, tjhgl.getKm1hgl()));
wsheet.addCell(new Label(3, i+3, tjhgl.getKm2hgl()));
wsheet.addCell(new Label(4, i+3, tjhgl.getKm3hgl()));
wsheet.addCell(new Label(5, i+3, tjhgl.getAvghgl()));
}
java怎样将网页上面的数据以pdf的格式导出,求代码
需要用到一个pdf的jar包,去网上下载一个itextpdf.jar。导出pdf的格式都是需要自己用代码实现的,每一行 ,每一个列是什么格式,都需要自己写出来,是不能够自动生成的,反正很麻烦。我做的一个导出成pdf特定格式的东西,写了好几千行代码。相当头痛。
package com.dw.mqs.export;
import java.awt.Color;
import java.io.ByteArrayOutputStream;
import java.math.BigDecimal;
import java.net.URL;
import java.util.Date;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.dw.file.WebHelper;
import com.dw.mqs.MqsManager;
import com.dw.mqs.MqsUtilNew;
import com.dw.mqs.ProductItem;
import com.dw.mqs.ProjectBasicItem;
import com.dw.mqs.ProjectConfDetailItem;
import com.dw.mqs.ProjectConfVerItem;
import com.dw.mqs.ProjectConfig;
import com.dw.mqs.ProjectService;
import com.dw.mqs.Util;
import com.dw.system.Convert;
import com.dw.system.gdb.DBResult;
import com.dw.system.gdb.DataRow;
import com.dw.system.gdb.GDB;
import com.dw.user.User;
import com.dw.user.UserManager;
import com.dw.user.UserProfile;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
public class PdfService
{
Document document = new Document(PageSize.A4.rotate(), 50, 50, 50, 50);
ByteArrayOutputStream os = new ByteArrayOutputStream();
PdfWriter pdf = PdfWriter.getInstance(document, os);
Rectangle rect = new Rectangle(36, 54, 559, 788);
pdf.setBoxSize("art", rect);
pdf.setPageEvent(new TableHeader());
document.open();
BaseFont baseArialuni = BaseFont.createFont("res/ARIALUNI.TTF",
BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); // Arial
// unicode字体
Font fontCN = new Font(baseArialuni, 9, Font.NORMAL, Color.BLACK);
Font fontCN8b = new Font(baseArialuni, 9, Font.BOLD, Color.BLACK);
Font fontCN12b = new Font(baseArialuni, 12, Font.BOLD, Color.BLACK);
Font fontCN9b = new Font(baseArialuni, 10, Font.BOLD, Color.BLACK);
Font fontCN9 = new Font(baseArialuni, 10, Font.NORMAL, Color.BLACK);
Font fontCN9b_blue = new Font(baseArialuni, 10, Font.BOLD, Color.BLUE);
PdfPTable table = null;
PdfPCell cell = null;
table = new PdfPTable(relativeWidths);
table.setWidthPercentage(100);
cell = new PdfPCell(new Paragraph(tit + "标题", fontCN12b));
cell.setColspan(root ? 12 : 10);
cell.setHorizontalAlignment(Element.ALIGN_CENTER); // 水平居中
cell.setVerticalAlignment(Element.ALIGN_MIDDLE); // 垂直居中
cell.setBorder(Rectangle.NO_BORDER);
table.addCell(cell);
}
分享文章:java数据导出代码,怎么导出java代码
分享链接:http://azwzsj.com/article/hcejhs.html