欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

java數(shù)據(jù)導出代碼 java 導出

java怎樣將網(wǎng)頁上面的數(shù)據(jù)以pdf的格式導出,求代碼

需要用到一個pdf的jar包,去網(wǎng)上下載一個itextpdf.jar。導出pdf的格式都是需要自己用代碼實現(xiàn)的,每一行 ,每一個列是什么格式,都需要自己寫出來,是不能夠自動生成的,反正很麻煩。我做的一個導出成pdf特定格式的東西,寫了好幾千行代碼。相當頭痛。

我們提供的服務有:成都網(wǎng)站制作、成都做網(wǎng)站、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認證、新民ssl等。為超過千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務,是有科學管理、有技術(shù)的新民網(wǎng)站制作公司

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里將從excel讀到的數(shù)據(jù)用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);

// 寫入文件內(nèi)容

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;

}

/**

* 寫一行數(shù)據(jù)方法

* @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

JSP頁面將數(shù)據(jù)從mysql導出到excel的Java代碼

jsp要從mysql導出數(shù)據(jù)到excel分兩步操作:

后臺查詢mysql符合條件的數(shù)據(jù),放在session中。

頁面展示數(shù)據(jù),并且控制導出,添加一個按鈕,調(diào)用導出方法執(zhí)行。/ol舉例說明:Java代碼sql = "select * from tablename";rs = stmt.executeQuery(sql);//新建Excel文件String filePath=request.getRealPath("aaa.xls");File myFilePath=new File(filePath);if(!myFilePath.exists())myFilePath.createNewFile();FileWriter resultFile=new FileWriter(myFilePath);PrintWriter myFile=new PrintWriter(resultFile);resultFile.close();//用JXL向新建的文件中添加內(nèi)容OutputStream outf = new FileOutputStream(filePath);jxl.write.WritableWorkbook wwb = Workbook.createWorkbook(outf);jxl.write.WritableSheet ws = wwb.createSheet("sheettest", 0);int i=0;int j=0;for (int k = 0; k rs.getMetaData().getColumnCount(); k++) {ws.addCell(new Label(k,0,rs.getMetaData().getColumnName(k+1)));}while(rs.next()){out.println(rs.getMetaData().getColumnCount());for (int k = 0; k rs.getMetaData().getColumnCount(); k++) {ws.addCell(new Label(k,j+i+1,rs.getString(k+1)));}i++;}wwb.write();wwb.close();}catch(Exception e){e.printStackTrace();}finally{rs.close();conn.close();}response.sendRedirect("aaa.xls");

java中輸入輸出流如何把數(shù)據(jù)輸出為Excel表格形式

實現(xiàn)代碼如下:

import org.apache.poi.hssf.usermodel.*;

import java.io.FileOutputStream;

import java.io.IOException;

publicclass CreateCells

{

publicstaticvoid main(String[] args)

throws IOException

{

HSSFWorkbook wb = new HSSFWorkbook();//建立新HSSFWorkbook對象

HSSFSheet sheet = wb.createSheet("new sheet");//建立新的sheet對象

// Create a row and put some cells in it. Rows are 0 based.

HSSFRow row = sheet.createRow((short)0);//建立新行

// Create a cell and put a value in it.

HSSFCell cell = row.createCell((short)0);//建立新cell

cell.setCellValue(1);//設(shè)置cell的整數(shù)類型的值

// Or do it on one line.

row.createCell((short)1).setCellValue(1.2);//設(shè)置cell浮點類型的值

row.createCell((short)2).setCellValue("test");//設(shè)置cell字符類型的值

row.createCell((short)3).setCellValue(true);//設(shè)置cell布爾類型的值

HSSFCellStyle cellStyle = wb.createCellStyle();//建立新的cell樣式

cellStyle.setDataFormat(HSSFDataFormat.getFormat("m/d/yy h:mm"));//設(shè)置cell樣式為定制的日期格式

HSSFCell dCell =row.createCell((short)4);

dCell.setCellValue(new Date());//設(shè)置cell為日期類型的值

dCell.setCellStyle(cellStyle); //設(shè)置該cell日期的顯示格式

HSSFCell csCell =row.createCell((short)5);

csCell.setEncoding(HSSFCell.ENCODING_UTF_16);//設(shè)置cell編碼解決中文高位字節(jié)截斷

csCell.setCellValue("中文測試_Chinese Words Test");//設(shè)置中西文結(jié)合字符串

row.createCell((short)6).setCellType(HSSFCell.CELL_TYPE_ERROR);//建立錯誤cell

// Write the output to a file

FileOutputStream fileOut = new FileOutputStream("workbook.xls");

wb.write(fileOut);

fileOut.close();

}

}

Java是由Sun Microsystems公司推出的Java面向?qū)ο蟪绦蛟O(shè)計語言(以下簡稱Java語言)和Java平臺的總稱。由James Gosling和同事們共同研發(fā),并在1995年正式推出。Java最初被稱為Oak,是1991年為消費類電子產(chǎn)品的嵌入式芯片而設(shè)計的。1995年更名為Java,并重新設(shè)計用于開發(fā)Internet應用程序。

用Java實現(xiàn)的HotJava瀏覽器(支持Java applet)顯示了Java的魅力:跨平臺、動態(tài)Web、Internet計算。從此,Java被廣泛接受并推動了Web的迅速發(fā)展,常用的瀏覽器均支持Javaapplet。另一方面,Java技術(shù)也不斷更新。Java自面世后就非常流行,發(fā)展迅速,對C++語言形成有力沖擊。在全球云計算和移動互聯(lián)網(wǎng)的產(chǎn)業(yè)環(huán)境下,Java更具備了顯著優(yōu)勢和廣闊前景。2010年Oracle公司收購Sun Microsystems。

名稱欄目:java數(shù)據(jù)導出代碼 java 導出
當前地址:http://chinadenli.net/article0/dojgdoo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站關(guān)鍵詞優(yōu)化網(wǎng)站收錄品牌網(wǎng)站制作企業(yè)網(wǎng)站制作微信公眾號

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)