Excel 超大数据导出

package org.liuqing.excel.util;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import java.util.Random;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.LogFactoryImpl;


/**
 * 
 * @author liuqing
 * @version 1.0
 * @see 导出文件值
 * @datetime 2012-3-12 下午9:56:31
 */
public class ExportFileUtil {
	
	private static Log log = LogFactoryImpl.getLog(ExportFileUtil.class); 
	
	static Properties uploadConf = new Properties();
	
	static {
		try {
			/**
			 * 加载配置文件
			 */
			log.info("loading excel config .......");
			uploadConf.load(ExportFileUtil.class.getResourceAsStream("/org/liuqing/excel/util/conf.properties"));
			log.info("load configuration successfully ...!");
		} 
		catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 自动创建文件夹
	 * @param fileName
	 * @return boolean
	 */
	public static boolean isExitsFile(String fileName) {
		File fileDir = new File(uploadConf.getProperty("path"));
		fileDir.mkdirs();
		File file = new File(fileDir.getPath() + File.separator + fileName);
		return file.exists();
	}
	
	public static void main(String args[]) throws IOException {
		File file = new File(uploadConf.getProperty("path") + File.separator + "fudmafda.xls");
		FileOutputStream fos = new FileOutputStream(file);

        PrintWriter osw=new PrintWriter(fos);

        for (int i = 1 ; i < 600000; i++) { 
        osw.println("aaa\tbb\tccc\tddd\teee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tteee\tfff\tr\tn\r\n");

	        if (i % 100 == 0) {
	        	osw.flush();
	        }
        }
        osw.close();
		/**
		System.out.println(isExitsFile("/201203122258116313653793767960715.xls"));
		
		
		FileOutputStream outputStream = new FileOutputStream(
				new File(String.valueOf(uploadConf.get("path")) + 
				File.separator + randomFileName()));
		HSSFWorkbook hssf = new HSSFWorkbook();
		
		Sheet sheet = hssf.createSheet("excelSheet");
		for (int i = 0 ; i < 5000; i++) {
			Row row = sheet.createRow(i);
			for (int u = 0 ; u < 200 ; u++) {
				Cell cell = row.createCell(u);
				cell.setCellValue(u + "===如果是这种需求如果是这种需求,考虑方案的时候就不应该局限在Java的Tools里面,因为Java里面那些操作excel的工具就只是一个权益之计,考虑方案的时候就不应该局限在Java的Tools里面,因为Java里面那些操作excel的工具就只是一个权益之计===============" + u);
			}
		}
		hssf.write(outputStream);
		outputStream.close();
		System.out.println(ExportFileUtil.randomFileName());
		System.out.println(uploadConf.getProperty("path"));
		**/
		/**
		FileInputStream input = new FileInputStream(
				new File(String.valueOf(uploadConf.get("path")) + 
				File.separator + "201203122258116313653793767960715.xls"));
		POIFSFileSystem poif = new POIFSFileSystem(input);
		HSSFWorkbook wb=new HSSFWorkbook(poif);
		Sheet sheet = wb.getSheetAt(0);
		int last = sheet.getLastRowNum();
		int us =  last + 200;
		for (; last < us;last++) {
			Row row = sheet.createRow(last);
			for (int u = 0 ; u < 254 ; u++) {
				Cell cell = row.createCell(u);
				cell.setCellValue(" uml=2222222222===== " + u);
			}
		}
		OutputStream output = new FileOutputStream(
				new File(String.valueOf(uploadConf.get("path")) + 
				File.separator + "201203122258116313653793767960715.xls"));
		BufferedOutputStream bufOutput = new BufferedOutputStream(output);
		wb.write(bufOutput);
		output.close();
		input.close();
		**/
		
	}
	
	/**
	 * 生文件唯一文件名
	 * @return String
	 */
	public static String randomFileName() {
		
		Random random = new Random();
		long randomValue = random.nextLong();
		randomValue = Math.abs(randomValue);
		SimpleDateFormat simp = new SimpleDateFormat("yyyyMMddHHssmm");
		String dateStr = simp.format(new Date());
		String fileName = dateStr + randomValue + ".xls";
		return fileName;
	}

}
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值