第一步:選中項(xiàng)目;

成都創(chuàng)新互聯(lián)堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都做網(wǎng)站、網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時(shí)代的海西網(wǎng)站設(shè)計(jì)、移動媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
第二步:右擊鼠標(biāo),選中“export”,之后選擇需要的導(dǎo)出類型;
第三步:選擇“Browse”,選擇導(dǎo)出路徑;
第四步:選擇“Finsh”即可完成導(dǎo)出。
備注:第二步中的導(dǎo)出類型根據(jù)實(shí)際需要選擇即可,如war(web項(xiàng)目,部署到tomcat等容器運(yùn)行,)、runnable jar(可運(yùn)行jar包),JarFile(作為單獨(dú)的jar包,之后放到需要的項(xiàng)目的lib下)等,這個(gè)根據(jù)實(shí)際需要選擇即可。
excel工具類
package com.ohd.ie.product.action;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import org.apache.commons.io.output.ByteArrayOutputStream;
import jxl.Workbook;
import jxl.format.Alignment;
import jxl.format.VerticalAlignment;
import jxl.write.*;
import jxl.write.Number;
import jxl.write.biff.RowsExceededException;
public class Excel {
private OutputStream os;
private WritableWorkbook wwb = null;
private WritableSheet ws = null;
private WritableCellFormat titleCellFormat = null;
private WritableCellFormat noBorderCellFormat = null;
private WritableCellFormat hasBorderCellFormat = null;
private WritableCellFormat hasBorderCellNumberFormat = null;
private WritableCellFormat hasBorderCellNumberFormat2 = null;
private WritableImage writableImage=null;
private int r;
public Excel(OutputStream os){
this.os = os;
r = -1;
try {
wwb = Workbook.createWorkbook(os);
//創(chuàng)建工作表
ws = wwb.createSheet("sheet1",0);
//設(shè)置表頭字體,大小,加粗
titleCellFormat = new WritableCellFormat();
titleCellFormat.setAlignment(Alignment.CENTRE);
titleCellFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
//自動換行
titleCellFormat.setWrap(true);
titleCellFormat.setFont(new WritableFont(WritableFont.createFont("宋體"),12,WritableFont.BOLD));
titleCellFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
//設(shè)置表格字體,大小----無邊框
noBorderCellFormat = new WritableCellFormat();
noBorderCellFormat.setAlignment(Alignment.CENTRE);
noBorderCellFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
noBorderCellFormat.setFont(new WritableFont(WritableFont.createFont("宋體"),12));
//設(shè)置表格字體,大小----有邊框
hasBorderCellFormat = new WritableCellFormat();
hasBorderCellFormat.setAlignment(Alignment.CENTRE);
hasBorderCellFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
hasBorderCellFormat.setFont(new WritableFont(WritableFont.createFont("宋體"),12));
hasBorderCellFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
//設(shè)置表格字體,大小----有邊框(小數(shù))
NumberFormat nf = new NumberFormat("#0.00");
hasBorderCellNumberFormat = new WritableCellFormat(nf);
hasBorderCellNumberFormat.setAlignment(Alignment.CENTRE);
hasBorderCellNumberFormat.setVerticalAlignment(VerticalAlignment.CENTRE);
hasBorderCellNumberFormat.setFont(new WritableFont(WritableFont.createFont("宋體"),12));
hasBorderCellNumberFormat.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
//設(shè)置表格字體,大小----有邊框(整數(shù))
NumberFormat nf2 = new NumberFormat("#0");
hasBorderCellNumberFormat2 = new WritableCellFormat(nf2);
hasBorderCellNumberFormat2.setAlignment(Alignment.CENTRE);
hasBorderCellNumberFormat2.setVerticalAlignment(VerticalAlignment.CENTRE);
hasBorderCellNumberFormat2.setFont(new WritableFont(WritableFont.createFont("宋體"),12));
hasBorderCellNumberFormat2.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
*
* @param content 內(nèi)容
* @param c 列
* @param style 樣式
* @param isNewLine 是否換行
* @param mergeType 合并類型
* @param mergeCount 合并個(gè)數(shù)
* @param width 單元格寬
*/
public void setExcelCell(String content,int c,int style,boolean isNewLine,int mergeType,int mergeCount,int width){
try {
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////報(bào)表內(nèi)容////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
if(isNewLine){
r++;
}
WritableCell l = null;
if(style == 1){
l = new Label(c,r,content,titleCellFormat);
}
else if(style == 2){
l = new Label(c,r,content,noBorderCellFormat);
}
else if(style == 3){
l = new Label(c,r,content,hasBorderCellFormat);
}
else if(style == 4){
l = new Number(c,r,Double.parseDouble(content),hasBorderCellNumberFormat);
}
else if(style == 5){
l = new Number(c,r,Integer.parseInt(content),hasBorderCellNumberFormat2);
}
ws.addCell(l);
if(width != 0){
ws.setColumnView(c,width);
}
//veryhuo,com
if(mergeType == 1){
//x 軸方向
ws.mergeCells(c, r, c+mergeCount-1 , r);
}
else if(mergeType == 2){
//y 軸方向
ws.mergeCells(c, r, c, r+mergeCount-1);
}
if(isNewLine){
ws.setRowView(r, 350);
if(style == 1 r != 0){
ws.setRowView(r, 900);
}
else{
ws.setRowView(r, 350);
}
}
//
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
} catch (Exception e) {
System.out.println(e.toString());
}
}
public void setExcelCellEx(String content,int c,int style,boolean isNewLine,int mergeType,int mergeCount,int width,int row){
try {
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////報(bào)表內(nèi)容////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
if(isNewLine){
r++;
}
WritableCell l = null;
if(style == 1){
l = new Label(c,r,content,titleCellFormat);
}
else if(style == 2){
l = new Label(c,r,content,noBorderCellFormat);
}
else if(style == 3){
if(content.indexOf(".jpg")!=-1 ||content.indexOf(".JPG")!=-1){
File outputFile=null;
File imgFile =new File(content);
if(imgFile.exists()imgFile.length()0){
BufferedImage input=null;
try {
input = ImageIO.read(imgFile);
} catch (Exception e) {
e.printStackTrace();
}
if(input!=null){
String path=imgFile.getAbsolutePath();
outputFile = new File(path.substring(0,path.lastIndexOf('.')+1)+"png");
ImageIO.write(input, "PNG", outputFile);
if(outputFile.exists()outputFile.length()0){
ws.setRowView(row,2000);
//ws.setColumnView(8, 10);
writableImage = new WritableImage(c+0.1, row+0.1, 0.8, 0.8, outputFile);
ws.addImage(writableImage);
l = new Label(c,r,"",hasBorderCellFormat);
}
}
}
}else{
l = new Label(c,r,content,hasBorderCellFormat);
}
}
else if(style == 4){
l = new Number(c,r,Double.parseDouble(content),hasBorderCellNumberFormat);
}
else if(style == 5){
l = new Number(c,r,Integer.parseInt(content),hasBorderCellNumberFormat2);
}
ws.addCell(l);
if(width != 0){
ws.setColumnView(c,width);
}
if(mergeType == 1){
//x 軸方向
ws.mergeCells(c, r, c+mergeCount-1 , r);
}
else if(mergeType == 2){
//y 軸方向
ws.mergeCells(c, r, c, r+mergeCount-1);
}
if(isNewLine){
ws.setRowView(r, 350);
if(style == 1 r != 0){
ws.setRowView(r, 900);
}
else{
ws.setRowView(r, 350);
}
}
} catch (Exception e) {
System.out.println(e.toString());
}
}
public void setRowHeight(int val){
try {
ws.setRowView(r, val);
} catch (RowsExceededException e) {
e.printStackTrace();
}
}
public void getExcelResult(){
try {
wwb.write();
} catch (Exception e) {
System.out.println(e.toString());
}
finally{
if(wwb != null){
try {
wwb.close();
if(os != null){
os.close();
}
} catch (WriteException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
需要的jar包:jxl.jar
用eclipse轉(zhuǎn)換成pdf的方法是用第三方j(luò)ar包,比如itext實(shí)現(xiàn)的。
環(huán)境準(zhǔn)備:
1、JDK 6
2、itext-5.1.2.jar in classpath
創(chuàng)建轉(zhuǎn)換程序:
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Date;
import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;
// Java PDF Generation With Itext
public class CreatePDFWithItext{
public static void main(String[] args) {
try {
OutputStream file = new FileOutputStream(new File("C:\\example.pdf"));
Document document = new Document();
PdfWriter.getInstance(document, file);
document.open();
document.add(new Paragraph("Hello World"));
document.add(new Paragraph(""));
document.add(new Paragraph(new Date().toString()));
document.close();
file.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
3、輸出:
拓展:
PDF是Portable Document Format的簡稱,意為“可攜帶文檔格式”,是由Adobe Systems用于與應(yīng)用程序、操作系統(tǒng)、硬件無關(guān)的方式進(jìn)行文件交換所發(fā)展出的文件格式。PDF文件以PostScript語言圖象模型為基礎(chǔ),無論在哪種打印機(jī)上都可保證精確的顏色和準(zhǔn)確的打印效果,即PDF會忠實(shí)地再現(xiàn)原稿的每一個(gè)字符、顏色以及圖象。可移植文檔格式是一種電子文件格式。這種文件格式與操作系統(tǒng)平臺無關(guān),也就是說,PDF文件不管是在Windows,Unix還是在蘋果公司的Mac OS操作系統(tǒng)中都是通用的。這一特點(diǎn)使它成為在Internet上進(jìn)行電子文檔發(fā)行和數(shù)字化信息傳播的理想文檔格式。越來越多的電子圖書、產(chǎn)品說明、公司文告、網(wǎng)絡(luò)資料、電子郵件在開始使用PDF格式文件。
如果自己的java project中需要引用額外的jar包作為資源文件,那么需要自定義配置文件MANIFEST.MF ,例如:
Manifest-Version: 1.0
Class-Path: lib\crimson.jar lib\jbcl.jar lib\junit.jar lib\log4j-1.2.13.jar lib\mysql-connector-java-3.1.13-bin.jar
Main-Class: src.YourMainClassName
其中的Class-Path就指定了外來jar包的位置。請注意假設(shè)我們的項(xiàng)目打包后為project.jar,那么按照上面的定義,應(yīng)該在 project.jar的同層目錄下建立一個(gè)lib文件夾,并將相關(guān)的jar包放在里面。否則將會出現(xiàn)Exception in thread "main" java.lang.NoClassDefFoundError的錯(cuò)誤。
如果想在所導(dǎo)出的jar包中包含第三方j(luò)ar包,可以如下操作:
在工程目錄下放入第三方j(luò)ar包
2.Class-Path: name.jar
上訴兩個(gè)步驟就可以成功導(dǎo)出引用了jar包的java工程,并將第三方j(luò)ar包放在導(dǎo)出的工程中
注意:如果在Class-Path 中引入比較多的jar包,不要寫成一行,不然會報(bào):java.io.IOException : line too long ,需要分多行寫,第二行以及下面的第三行、第四行寫的時(shí)候需要在前面空兩格(敲兩下空格鍵)即可
最后介紹一下使用Eclipse制作jar包的過程吧:
1. 首先在Eclipse中打開項(xiàng)目, 右鍵點(diǎn)擊項(xiàng)目,選擇“Export”;
2. 選擇Java/JAR file,Next;
3. Select the resources to export中可以選擇你想要包含的項(xiàng)目文件夾,一些不必要的文件夾就無需放進(jìn)去了,免得增大空間;
這里有幾個(gè)選項(xiàng):
* Export generated class files and resources 表示只導(dǎo)出生成的.class文件和其他資源文件
* Export all output folders for checked projects 表示導(dǎo)出選中項(xiàng)目的所有文件夾
* Export java source file and resouces 表示導(dǎo)出的jar包中將包含你的源代碼*.java,如果你不想泄漏源代碼,那么就不要選這項(xiàng)了
* Export refactorings for checked projects 把一些重構(gòu)的信息文件也包含進(jìn)去
在Select the export destination中選擇導(dǎo)出的jar的路徑,Next
4. 下一頁可以選擇是否導(dǎo)出那些含有警告warning或者錯(cuò)誤errors的*.class文件。一般不用理他,Next
5. 下一個(gè)頁面里可以對項(xiàng)目做一些配置。
* Generate the manifest file是系統(tǒng)幫我們自動生成MANIFEST.MF文件,如果你的項(xiàng)目沒有引用其他class-path,那可以選擇這一項(xiàng)。
* Use existing mainfest from workspace。這是可以選擇我們自定義的.MF文件,格式如上所寫。
* Seal content。要封裝整個(gè)jar或者指定的包packet
* Main class。這里可以選擇你的程序入口,將來打包出來的jar就是你這個(gè)入口類的執(zhí)行結(jié)果。
最后Finish 完成
新聞標(biāo)題:java代碼怎樣導(dǎo)出,java如何導(dǎo)出
文章位置:http://chinadenli.net/article16/dsegigg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、網(wǎng)站排名、動態(tài)網(wǎng)站、Google、ChatGPT、
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)